@openmrs/esm-fast-data-entry-app 1.4.2-pre.725 → 1.4.2-pre.734
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/9108.js +1 -1
- package/dist/9108.js.LICENSE.txt +9 -0
- package/dist/9108.js.map +1 -1
- package/dist/main.js +1 -1
- package/dist/openmrs-esm-fast-data-entry-app.js +1 -1
- package/dist/openmrs-esm-fast-data-entry-app.js.buildmanifest.json +5 -5
- package/dist/routes.json +1 -1
- package/package.json +12 -13
- package/src/FormBootstrap.test.tsx +12 -11
- package/src/add-group-modal/AddGroupModal.test.tsx +13 -12
- package/src/context/FormWorkflowReducer.test.ts +3 -2
- package/src/context/GroupFormWorkflowReducer.test.ts +6 -5
- package/src/form-entry-workflow/patient-banner/PatientBanner.test.tsx +1 -0
- package/src/form-entry-workflow/patient-search-header/PatientSearchHeader.test.tsx +17 -17
- package/src/group-form-entry-workflow/GroupSessionWorkspace.test.tsx +24 -23
- package/src/group-form-entry-workflow/SessionMetaWorkspace.test.tsx +6 -5
- package/src/group-form-entry-workflow/group-display-header/GroupDisplayHeader.test.tsx +1 -0
- package/src/group-form-entry-workflow/group-search-header/GroupSearchHeader.test.tsx +11 -10
- package/src/hooks/useGetPatient.test.tsx +5 -4
- package/src/setup-tests.ts +5 -1
- package/vitest.config.ts +40 -0
- package/jest.config.json +0 -31
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
|
+
import { vi, describe, it, expect } from 'vitest';
|
|
2
3
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
3
4
|
import userEvent from '@testing-library/user-event';
|
|
4
5
|
import { useFormContext } from 'react-hook-form';
|
|
5
6
|
import GroupFormWorkflowContext from '../context/GroupFormWorkflowContext';
|
|
6
7
|
import SessionMetaWorkspace from './SessionMetaWorkspace';
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
vi.mock('../CancelModal', () => ({
|
|
9
10
|
__esModule: true,
|
|
10
11
|
default: () => null,
|
|
11
12
|
}));
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
vi.mock('./SessionDetailsForm', () => ({
|
|
14
15
|
__esModule: true,
|
|
15
16
|
default: function MockSessionDetailsForm() {
|
|
16
17
|
const { register, setValue } = useFormContext();
|
|
@@ -40,7 +41,7 @@ const renderSessionMetaWorkspace = (contextOverrides = {}) =>
|
|
|
40
41
|
workflowState: 'NEW_GROUP_SESSION',
|
|
41
42
|
patientUuids: ['patient-a'],
|
|
42
43
|
activeGroupUuid: 'group-1',
|
|
43
|
-
setSessionMeta:
|
|
44
|
+
setSessionMeta: vi.fn(),
|
|
44
45
|
...contextOverrides,
|
|
45
46
|
} as never
|
|
46
47
|
}
|
|
@@ -52,7 +53,7 @@ const renderSessionMetaWorkspace = (contextOverrides = {}) =>
|
|
|
52
53
|
describe('SessionMetaWorkspace', () => {
|
|
53
54
|
it('submits the session metadata with the normalized session date', async () => {
|
|
54
55
|
const user = userEvent.setup();
|
|
55
|
-
const setSessionMeta =
|
|
56
|
+
const setSessionMeta = vi.fn();
|
|
56
57
|
renderSessionMetaWorkspace({ setSessionMeta });
|
|
57
58
|
|
|
58
59
|
await user.click(screen.getByRole('button', { name: 'Create New Session' }));
|
|
@@ -72,7 +73,7 @@ describe('SessionMetaWorkspace', () => {
|
|
|
72
73
|
|
|
73
74
|
it('shows the group selection error when submitted without a chosen group', async () => {
|
|
74
75
|
const user = userEvent.setup();
|
|
75
|
-
const setSessionMeta =
|
|
76
|
+
const setSessionMeta = vi.fn();
|
|
76
77
|
renderSessionMetaWorkspace({
|
|
77
78
|
activeGroupUuid: null,
|
|
78
79
|
setSessionMeta,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
|
2
3
|
import { render, screen } from '@testing-library/react';
|
|
3
4
|
import userEvent from '@testing-library/user-event';
|
|
4
5
|
import { showSnackbar, useConfig, useSession } from '@openmrs/esm-framework';
|
|
@@ -7,7 +8,7 @@ import GroupSearchHeader from './GroupSearchHeader';
|
|
|
7
8
|
|
|
8
9
|
let selectedGroup;
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
vi.mock('../group-search/CompactGroupSearch', () => ({
|
|
11
12
|
__esModule: true,
|
|
12
13
|
default: ({ selectGroupAction }) => (
|
|
13
14
|
<button data-testid="compact-group-search" onClick={() => selectGroupAction(selectedGroup)}>
|
|
@@ -16,14 +17,14 @@ jest.mock('../group-search/CompactGroupSearch', () => ({
|
|
|
16
17
|
),
|
|
17
18
|
}));
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
vi.mock('../../add-group-modal/AddGroupModal', () => ({
|
|
20
21
|
__esModule: true,
|
|
21
22
|
default: ({ isOpen }) => (isOpen ? <div data-testid="add-group-modal" /> : null),
|
|
22
23
|
}));
|
|
23
24
|
|
|
24
|
-
const mockShowSnackbar =
|
|
25
|
-
const mockUseConfig =
|
|
26
|
-
const mockUseSession =
|
|
25
|
+
const mockShowSnackbar = vi.mocked(showSnackbar);
|
|
26
|
+
const mockUseConfig = vi.mocked(useConfig);
|
|
27
|
+
const mockUseSession = vi.mocked(useSession);
|
|
27
28
|
|
|
28
29
|
const renderGroupSearchHeader = (contextOverrides = {}) =>
|
|
29
30
|
render(
|
|
@@ -31,8 +32,8 @@ const renderGroupSearchHeader = (contextOverrides = {}) =>
|
|
|
31
32
|
value={
|
|
32
33
|
{
|
|
33
34
|
activeGroupUuid: null,
|
|
34
|
-
setGroup:
|
|
35
|
-
destroySession:
|
|
35
|
+
setGroup: vi.fn(),
|
|
36
|
+
destroySession: vi.fn(),
|
|
36
37
|
...contextOverrides,
|
|
37
38
|
} as never
|
|
38
39
|
}
|
|
@@ -56,7 +57,7 @@ describe('GroupSearchHeader', () => {
|
|
|
56
57
|
|
|
57
58
|
it('blocks group selection when location enforcement is enabled and locations mismatch', async () => {
|
|
58
59
|
const user = userEvent.setup();
|
|
59
|
-
const setGroup =
|
|
60
|
+
const setGroup = vi.fn();
|
|
60
61
|
selectedGroup = {
|
|
61
62
|
uuid: 'group-1',
|
|
62
63
|
location: {
|
|
@@ -81,7 +82,7 @@ describe('GroupSearchHeader', () => {
|
|
|
81
82
|
|
|
82
83
|
it('sorts cohort members by display name before storing the selected group', async () => {
|
|
83
84
|
const user = userEvent.setup();
|
|
84
|
-
const setGroup =
|
|
85
|
+
const setGroup = vi.fn();
|
|
85
86
|
selectedGroup = {
|
|
86
87
|
uuid: 'group-1',
|
|
87
88
|
location: {
|
|
@@ -109,7 +110,7 @@ describe('GroupSearchHeader', () => {
|
|
|
109
110
|
|
|
110
111
|
it('opens the add-group modal and lets the user cancel the session', async () => {
|
|
111
112
|
const user = userEvent.setup();
|
|
112
|
-
const destroySession =
|
|
113
|
+
const destroySession = vi.fn();
|
|
113
114
|
renderGroupSearchHeader({ destroySession });
|
|
114
115
|
|
|
115
116
|
await user.click(screen.getByRole('button', { name: 'Create New Group' }));
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { vi, describe, it, expect, beforeEach, type MockedFunction } from 'vitest';
|
|
2
3
|
import { act, render, screen } from '@testing-library/react';
|
|
3
4
|
import { fetchCurrentPatient } from '@openmrs/esm-framework';
|
|
4
5
|
import useGetPatient from './useGetPatient';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
fetchCurrentPatient:
|
|
7
|
+
vi.mock('@openmrs/esm-framework', () => ({
|
|
8
|
+
fetchCurrentPatient: vi.fn(),
|
|
8
9
|
}));
|
|
9
10
|
|
|
10
11
|
type Deferred<T> = {
|
|
@@ -24,7 +25,7 @@ const createDeferred = <T,>(): Deferred<T> => {
|
|
|
24
25
|
};
|
|
25
26
|
};
|
|
26
27
|
|
|
27
|
-
const mockFetchCurrentPatient = fetchCurrentPatient as
|
|
28
|
+
const mockFetchCurrentPatient = fetchCurrentPatient as MockedFunction<typeof fetchCurrentPatient>;
|
|
28
29
|
|
|
29
30
|
const TestHarness = ({ patientUuid }: { patientUuid?: string }) => {
|
|
30
31
|
const patient = useGetPatient(patientUuid);
|
|
@@ -35,7 +36,7 @@ const TestHarness = ({ patientUuid }: { patientUuid?: string }) => {
|
|
|
35
36
|
|
|
36
37
|
describe('useGetPatient', () => {
|
|
37
38
|
beforeEach(() => {
|
|
38
|
-
|
|
39
|
+
vi.clearAllMocks();
|
|
39
40
|
});
|
|
40
41
|
|
|
41
42
|
it('ignores stale responses after patientUuid changes', async () => {
|
package/src/setup-tests.ts
CHANGED
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { defineConfig } from 'vitest/config';
|
|
3
|
+
|
|
4
|
+
const r = (relativePath: string) => fileURLToPath(new URL(relativePath, import.meta.url));
|
|
5
|
+
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
resolve: {
|
|
8
|
+
alias: [{ find: /^.*\.s?css$/, replacement: 'identity-obj-proxy' }],
|
|
9
|
+
},
|
|
10
|
+
test: {
|
|
11
|
+
environment: 'jsdom',
|
|
12
|
+
globals: true,
|
|
13
|
+
clearMocks: true,
|
|
14
|
+
setupFiles: ['./src/setup-tests.ts'],
|
|
15
|
+
exclude: ['**/node_modules/**', '**/e2e/**', '**/dist/**'],
|
|
16
|
+
server: {
|
|
17
|
+
deps: {
|
|
18
|
+
inline: [/@openmrs/],
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
fakeTimers: {
|
|
22
|
+
toFake: [
|
|
23
|
+
'setTimeout',
|
|
24
|
+
'clearTimeout',
|
|
25
|
+
'setInterval',
|
|
26
|
+
'clearInterval',
|
|
27
|
+
'setImmediate',
|
|
28
|
+
'clearImmediate',
|
|
29
|
+
'requestAnimationFrame',
|
|
30
|
+
'cancelAnimationFrame',
|
|
31
|
+
'Date',
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
alias: {
|
|
35
|
+
'@openmrs/esm-framework/src/internal': '@openmrs/esm-framework/mock',
|
|
36
|
+
'@openmrs/esm-framework': '@openmrs/esm-framework/mock',
|
|
37
|
+
'react-i18next': r('./__mocks__/react-i18next.js'),
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
package/jest.config.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
{
|
|
3
|
-
"clearMocks": true,
|
|
4
|
-
"collectCoverageFrom": [
|
|
5
|
-
"**/src/**/*.component.tsx",
|
|
6
|
-
"!**/node_modules/**",
|
|
7
|
-
"!**/src/declarations.d.ts",
|
|
8
|
-
"!**/e2e/**"
|
|
9
|
-
],
|
|
10
|
-
"transform": {
|
|
11
|
-
"^.+\\.m?[jt]sx?$": ["@swc/jest"]
|
|
12
|
-
},
|
|
13
|
-
"transformIgnorePatterns": ["/node_modules/(?!@openmrs)"],
|
|
14
|
-
"moduleNameMapper": {
|
|
15
|
-
"@openmrs/esm-framework": "@openmrs/esm-framework/mock",
|
|
16
|
-
"\\.(s?css)$": "identity-obj-proxy",
|
|
17
|
-
"^lodash-es/(.*)$": "lodash/$1",
|
|
18
|
-
"^lodash-es$": "lodash",
|
|
19
|
-
"^dexie$": "<rootDir>/node_modules/dexie",
|
|
20
|
-
"^react-i18next$": "<rootDir>/__mocks__/react-i18next.js"
|
|
21
|
-
},
|
|
22
|
-
"setupFilesAfterEnv": ["<rootDir>/src/setup-tests.ts"],
|
|
23
|
-
"testEnvironment": "jsdom",
|
|
24
|
-
"testEnvironmentOptions": {
|
|
25
|
-
"url": "http://localhost/"
|
|
26
|
-
},
|
|
27
|
-
"testPathIgnorePatterns": [
|
|
28
|
-
"/node_modules/",
|
|
29
|
-
"/e2e/"
|
|
30
|
-
]
|
|
31
|
-
}
|