import React from 'react'
import '@testing-library/jest-dom/extend-expect'
import { render, getByTestId } from '@testing-library/react'
import { IntlProvider, FormattedDate } from 'react-intl'
import IntlPolyfill from 'intl'
import 'intl/locale-data/jsonp/pt'
const setupTests = () => {
if (global.Intl) {
Intl.NumberFormat = IntlPolyfill.NumberFormat
Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat
} else {
global.Intl = IntlPolyfill
}
}
const FormatDateView = () => {
return (
<div data-testid="date-display">
<FormattedDate
value="2019-03-11"
timeZone="utc"
day="2-digit"
month="2-digit"
year="numeric"
/>
</div>
)
}
const renderWithReactIntl = component => {
return render(<IntlProvider locale="pt">{component}</IntlProvider>)
}
setupTests()
test('it should render FormattedDate and have a formated pt date', () => {
const { container } = renderWithReactIntl(<FormatDateView />)
expect(getByTestId(container, 'date-display')).toHaveTextContent('11/03/2019')
})