Skip to content

Commit 842f0c9

Browse files
committed
Add react tests
1 parent 7b4bdd2 commit 842f0c9

File tree

16 files changed

+898
-15
lines changed

16 files changed

+898
-15
lines changed

.github/workflows/gh-pages.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ jobs:
1717
- name: Setup Node.js
1818
uses: actions/setup-node@v4
1919
with:
20-
node-version: '18'
20+
node-version: '22'
2121

2222
- name: Install Dependencies
2323
run: npm install
2424

2525
- name: Build
26-
run: BUILD_TARGET=app npm run build -- --base=/aidbox-forms-renderer
26+
run: BUILD_TARGET=demo npm run build -- --base=/aidbox-forms-renderer
2727

2828
- name: Add GitHub ribbon to built files
2929
run: |

.github/workflows/npm-publish.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup Node.js
1616
uses: actions/setup-node@v4
1717
with:
18-
node-version: '18'
18+
node-version: '22'
1919
registry-url: 'https://registry.npmjs.org'
2020

2121
- name: Install Dependencies
@@ -27,4 +27,4 @@ jobs:
2727
- name: Publish to npm
2828
run: npm publish
2929
env:
30-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
30+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
</head>
99
<body>
1010
<div id="root" class="contents"></div>
11-
<script type="module" src="/src/index.tsx"></script>
11+
<script type="module" src="/demo/index.tsx"></script>
1212
</body>
1313
</html>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { render, screen } from "@testing-library/react";
2+
import userEvent from "@testing-library/user-event";
3+
import { describe, expect, it, vi } from "vitest";
4+
5+
import Renderer from "../index";
6+
import type { Questionnaire, QuestionnaireResponse } from "fhir/r5";
7+
8+
describe("Renderer", () => {
9+
it("updates QuestionnaireResponse when a user answers a question", async () => {
10+
const questionnaire: Questionnaire = {
11+
resourceType: "Questionnaire",
12+
id: "test",
13+
status: "active",
14+
item: [
15+
{
16+
linkId: "name",
17+
text: "Full name",
18+
type: "string",
19+
required: true,
20+
},
21+
],
22+
};
23+
24+
const handleChange = vi.fn();
25+
26+
render(<Renderer questionnaire={questionnaire} onChange={handleChange} />);
27+
28+
const user = userEvent.setup();
29+
const input = screen.getByRole("textbox", { name: /full name/i });
30+
await user.clear(input);
31+
await user.type(input, "Ada Lovelace");
32+
33+
expect(handleChange).toHaveBeenCalled();
34+
35+
const lastCall = handleChange.mock.calls.at(-1) as [QuestionnaireResponse];
36+
const response = lastCall[0];
37+
const valueString = response.item?.[0]?.answer?.[0]?.valueString;
38+
expect(valueString).toBe("Ada Lovelace");
39+
expect(response.status).toBe("in-progress");
40+
});
41+
});

lib/__tests__/setup-tests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "@testing-library/jest-dom/vitest";

lib/index.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
flex-direction: column;
44
gap: 1.5rem;
55
padding: 1.5rem;
6-
border: 1px solid #e2e8f0;
7-
border-radius: 0.75rem;
8-
background: #ffffff;
96
color: #1a202c;
10-
max-width: 640px;
117
}
128

139
.q-title {

0 commit comments

Comments
 (0)