Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build_test_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ jobs:
- name: Build workspace packages
run: |
npm run build -w packages/sdc-populate
npm run build -w packages/testing-toolkit

- name: Install Playwright browsers
run: npx playwright install --with-deps
Expand Down
5 changes: 0 additions & 5 deletions apps/smart-forms-app/jest.config.js

This file was deleted.

73 changes: 0 additions & 73 deletions apps/smart-forms-app/jest.config.ts

This file was deleted.

3 changes: 2 additions & 1 deletion apps/smart-forms-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dev": "vite",
"start": "vite",
"build": "tsc && CI=false vite build",
"test": "TZ=Australia/Sydney jest --config ./jest.config.ts --coverage",
"test": "vitest run",
Copy link
Copy Markdown
Member

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 run for backward compatibility

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check

"preview": "vite preview --port 4173",
"playwright": "npx playwright test",
"playwright-ui": "npx playwright test --ui"
Expand Down Expand Up @@ -102,6 +102,7 @@
"typescript": "^5.8.3",
"vite": "^5.4.19",
"vite-plugin-svgr": "^4.3.0",
"vitest": "^3.2.4",
"yui-lint": "^0.2.0"
},
"eslintConfig": {
Expand Down
98 changes: 98 additions & 0 deletions apps/smart-forms-app/src/test/questionnaireRenderer.test.tsx
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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAnswerRecursiveByLabel

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const qr = questionnaireResponseStore.getState().updatableResponse;
console.log(qr);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove console log

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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');
Comment thread
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>
);
}
16 changes: 16 additions & 0 deletions apps/smart-forms-app/vitest.config.ts
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/**'],
},
},
});
Loading
Loading