forked from aehrc/smart-forms
-
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
Open
Vlpros
wants to merge
15
commits into
alpha
Choose a base branch
from
2-questionnare-behavior-test
base: alpha
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0556614
Migrate smart-forms-app to vitest
ruscoder 91c8dc9
Merge remote-tracking branch 'origin/1-test-toolkit' into 1-test-tool…
ruscoder 5629100
Update lock
ruscoder 6f98983
Update behaviour test
Vlpros 6b43947
Merge branch 'alpha' of https://github.com/beda-software/smart-forms …
Vlpros 6a6ff60
Update behaviout test
Vlpros 296a5be
Update folder for behaviour test
Vlpros 76b5941
Add ne attribute data-label
Vlpros 346d829
Update findByLinkId
Vlpros 05c4307
Merge branch 'alpha' of https://github.com/beda-software/smart-forms …
Vlpros 8b12bc7
Update imports in item types
Vlpros 977f7f4
Update behaviour test and vitest.config
Vlpros 63c8f15
Update imports tests in app
Vlpros 1e89ba3
Add expect type dep, add vitest types in tsconfig and update behaviou…
Vlpros ded24aa
Delete type vitest from tsconfig and add vitest to dep
Vlpros File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
apps/smart-forms-app/src/test/questionnaireRenderer.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| 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 { vi } from 'vitest'; | ||
|
|
||
| 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 getAnswerRecursiveByLabel(text: string) { | ||
| const qr = questionnaireResponseStore.getState().updatableResponse; | ||
| console.log(1); | ||
| const result = await evaluate( | ||
| qr, | ||
| `QuestionnaireResponse.repeat(item).where((text = '${text}')).answer` | ||
| ); | ||
| return result; | ||
| } | ||
|
|
||
| test('behaviour-test-example', 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'); | ||
|
|
||
| await inputText(container, 'Name', 'David'); | ||
| await inputDate(container, 'Date of birth', '11/11/2021'); | ||
| await inputInteger(container, 'Age', 24); | ||
| await checkRadioOption(container, 'Registered for NDIS', 'Yes'); | ||
| await inputText(container, 'NDIS Number', 'Some text'); | ||
| }); | ||
|
|
||
| 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> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/**'], | ||
| }, | ||
| }, | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.