-
Notifications
You must be signed in to change notification settings - Fork 0
Questionnare behavior test #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: alpha
Are you sure you want to change the base?
Changes from 13 commits
0556614
91c8dc9
5629100
6f98983
6b43947
6a6ff60
296a5be
76b5941
346d829
05c4307
8b12bc7
977f7f4
63c8f15
1e89ba3
ded24aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import { test, vi } from 'vitest'; | ||
| import { render } from '@testing-library/react'; | ||
| import { evaluate } from 'fhirpath'; | ||
| import type { Questionnaire, QuestionnaireResponse } from 'fhir/r4'; | ||
| import aboriginalForm from '../data/resources/Questionnaire/Questionnaire-AboriginalTorresStraitIslanderHealthCheckAssembled-0.1.0.json'; | ||
| import { QueryClientProvider } from '@tanstack/react-query'; | ||
| import { testUtils } from '@aehrc/smart-forms-renderer'; | ||
|
|
||
| import { | ||
| BaseRenderer, | ||
| questionnaireResponseStore, | ||
| RendererThemeProvider, | ||
| useBuildForm, | ||
| useRendererQueryClient | ||
| } from '@aehrc/smart-forms-renderer'; | ||
|
|
||
| const { inputText, inputDate, inputInteger, checkRadioOption } = testUtils; | ||
| vi.mock('fhirclient', () => ({ | ||
| client: () => ({ | ||
| request: vi.fn(() => Promise.resolve({})) | ||
| }) | ||
| })); | ||
|
|
||
| export async function getAnswerRecurciseByLabel(text: string) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getAnswerRecursiveByLabel
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| const qr = questionnaireResponseStore.getState().updatableResponse; | ||
| console.log(qr); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove console log
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| const result = await evaluate( | ||
| qr, | ||
| `QuestionnaireResponse.repeat(item).where((text = '${text}')).answer` | ||
| ); | ||
| return result; | ||
| } | ||
|
|
||
| test('Behavior test', async () => { | ||
| const form = aboriginalForm as Questionnaire; | ||
|
|
||
| const { container } = render(<BuildFormWrapperForStorybook questionnaire={form} />); | ||
| await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
| expect(container.innerHTML).toContain('Patient Details'); | ||
|
ruscoder marked this conversation as resolved.
|
||
| const nameTex = 'David'; | ||
| await inputText(container, 'Name', nameTex); | ||
| let result = await getAnswerRecurciseByLabel('Name'); | ||
| expect(result).toHaveLength(1); | ||
| expect(result[0]).toEqual(expect.objectContaining({ valueString: nameTex })); | ||
|
|
||
| const date = '11/11/2021'; | ||
| const dateText = '2021-11-11'; | ||
| await inputDate(container, 'Date of birth', date); | ||
| result = await getAnswerRecurciseByLabel('Date of birth'); | ||
| expect(result).toHaveLength(1); | ||
| expect(result[0]).toEqual(expect.objectContaining({ valueDate: dateText })); | ||
|
|
||
| const ageText = 24; | ||
| await inputInteger(container, 'Age', ageText); | ||
| result = await getAnswerRecurciseByLabel('Age'); | ||
| expect(result).toHaveLength(1); | ||
| expect(result[0]).toEqual(expect.objectContaining({ valueInteger: ageText })); | ||
|
|
||
| const answerCoding = { | ||
| code: 'Y', | ||
| display: 'Yes', | ||
| system: 'http://terminology.hl7.org/CodeSystem/v2-0532' | ||
| }; | ||
| const inputTargetText = 'Some text'; | ||
| await checkRadioOption(container, 'Registered for NDIS', answerCoding.display); | ||
| await inputText(container, 'NDIS Number', inputTargetText); | ||
| result = await getAnswerRecurciseByLabel('NDIS Number'); | ||
| expect(result).toHaveLength(1); | ||
| expect(result[0]).toEqual(expect.objectContaining({ valueString: inputTargetText })); | ||
| }); | ||
|
|
||
| interface BuildFormWrapperForStorybookProps { | ||
| questionnaire: Questionnaire; | ||
| questionnaireResponse?: QuestionnaireResponse; | ||
| } | ||
|
|
||
| function BuildFormWrapperForStorybook(props: BuildFormWrapperForStorybookProps) { | ||
| const { questionnaire, questionnaireResponse } = props; | ||
| const queryClient = useRendererQueryClient(); | ||
| const isBuilding = useBuildForm( | ||
| questionnaire, | ||
| questionnaireResponse, | ||
| undefined, | ||
| 'https://r4.ontoserver.csiro.au/fhir' | ||
| ); | ||
|
|
||
| if (isBuilding) { | ||
| return <div>Loading...</div>; | ||
| } | ||
|
|
||
| return ( | ||
| <RendererThemeProvider> | ||
| <QueryClientProvider client={queryClient}> | ||
| <BaseRenderer /> | ||
| </QueryClientProvider> | ||
| </RendererThemeProvider> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { defineConfig } from 'vitest/config'; | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| globals: true, | ||
| testTimeout:40000, | ||
| environment: 'jsdom', | ||
| include: ['**/__tests__/**/*.{test,spec}.{js,ts,jsx,tsx}', '**/*.{test,spec}.{js,ts,jsx,tsx}'], | ||
| exclude: ['**/e2e/**', '**/node_modules/**'], | ||
| coverage: { | ||
| provider: 'v8', | ||
| reporter: ['text', 'json', 'html'], | ||
| exclude: ['**/e2e/**', '**/node_modules/**'], | ||
| }, | ||
| }, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be
TZ=Australia/Sydney vitest runfor backward compatibilityThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check