Skip to content
Snippets Groups Projects
Commit aa96974b authored by Tore.Brede's avatar Tore.Brede
Browse files

Fixing test where checks did not work

parent dbe6db61
No related branches found
No related tags found
1 merge request!169Fixing test where checks did not work
Pipeline #101070 passed
import React from 'react' import React from 'react'
import fetchMock, { enableFetchMocks } from 'jest-fetch-mock' import fetchMock, { enableFetchMocks } from 'jest-fetch-mock'
import { render, waitFor, screen } from 'test-utils' import { render, screen } from 'test-utils'
import AdapterDateFns from '@mui/lab/AdapterDateFns' import AdapterDateFns from '@mui/lab/AdapterDateFns'
import { LocalizationProvider } from '@mui/lab' import { LocalizationProvider } from '@mui/lab'
import GuestRegister from './index' import GuestRegister from './index'
...@@ -9,12 +9,13 @@ enableFetchMocks() ...@@ -9,12 +9,13 @@ enableFetchMocks()
const testData = { const testData = {
person: { person: {
first_name: 'Test', first_name: 'Test20',
last_name: 'Tester', last_name: 'Tester',
mobile_phone: '+4797543910', mobile_phone: '+4797543910',
email: 'test@example.org', email: 'test@example.org',
fnr: '04062141242', fnr: '04062141242',
passport: 'NO-123456', passport: 'DK-123456',
date_of_birth: '1995-02-25',
}, },
role: { role: {
ou_name_en: 'English organizational unit name', ou_name_en: 'English organizational unit name',
...@@ -23,7 +24,8 @@ const testData = { ...@@ -23,7 +24,8 @@ const testData = {
name_nb: 'Gjesterolle', name_nb: 'Gjesterolle',
start: '2021-08-10', start: '2021-08-10',
end: '2021-08-16', end: '2021-08-16',
comment: '', contact_person_unit: 'Test contact person',
comments: 'Test comment',
}, },
meta: { meta: {
session_type: 'invite', session_type: 'invite',
...@@ -31,26 +33,38 @@ const testData = { ...@@ -31,26 +33,38 @@ const testData = {
} }
beforeEach(() => { beforeEach(() => {
fetchMock.mockIf('/api/ui/v1/invited', () => fetchMock.mockIf('/api/ui/v1/invited/', () =>
Promise.resolve<any>(JSON.stringify(testData)) Promise.resolve<any>(JSON.stringify(testData))
) )
}) })
test('Mobile phone number parsed and split correctly', async () => { test('Field showing values correctly', async () => {
render( render(
<LocalizationProvider dateAdapter={AdapterDateFns}> <LocalizationProvider dateAdapter={AdapterDateFns}>
<GuestRegister /> <GuestRegister />
</LocalizationProvider> </LocalizationProvider>
) )
await waitFor(() => screen.queryByText(testData.person.first_name)) await screen.findByDisplayValue(testData.person.first_name)
await waitFor(() => screen.queryByText(testData.person.last_name)) await screen.findByDisplayValue(testData.person.last_name)
await waitFor(() => screen.queryByText(testData.person.email)) await screen.findByDisplayValue(testData.person.email)
await waitFor(() => screen.queryByText(testData.person.fnr)) await screen.findByDisplayValue(testData.person.fnr)
await waitFor(() => screen.queryByText('NO'))
await waitFor(() => screen.queryByText('123456'))
// There is no proper i18n loaded so the country name will be undefined, the country code should still show though // Passport nationality. The i18n-mock sets up en as the i18n.language property, so look for the English name
await waitFor(() => screen.queryByText('undefined (47)')) await screen.findByText('Denmark')
await waitFor(() => screen.queryByText('97543910')) await screen.findByDisplayValue('123456')
await screen.findByDisplayValue(testData.person.date_of_birth)
// Mobile phone country code
await screen.findByDisplayValue('NO')
await screen.findByDisplayValue('97543910')
// Role information
await screen.findByDisplayValue(testData.role.ou_name_en)
// TODO Haven't been able to mock getting role types properly yet, so not checking role name
// await screen.findByDisplayValue(testData.role.name_en)
await screen.findByDisplayValue(
`${testData.role.start} - ${testData.role.end}`
)
await screen.findByDisplayValue(testData.role.comments)
}) })
...@@ -24,6 +24,7 @@ jest.mock('react-i18next', () => ({ ...@@ -24,6 +24,7 @@ jest.mock('react-i18next', () => ({
useTranslation: () => ({ useTranslation: () => ({
t: (value: string) => value, t: (value: string) => value,
i18n: { i18n: {
language: 'en',
changeLanguage: () => new Promise(() => {}), changeLanguage: () => new Promise(() => {}),
}, },
}), }),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment