@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.
@@ -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
- jest.mock('../CancelModal', () => ({
9
+ vi.mock('../CancelModal', () => ({
9
10
  __esModule: true,
10
11
  default: () => null,
11
12
  }));
12
13
 
13
- jest.mock('./SessionDetailsForm', () => ({
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: jest.fn(),
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 = jest.fn();
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 = jest.fn();
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 } from 'vitest';
2
3
  import { render } from '@testing-library/react';
3
4
  import GroupDisplayHeader from './GroupDisplayHeader';
4
5
 
@@ -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
- jest.mock('../group-search/CompactGroupSearch', () => ({
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
- jest.mock('../../add-group-modal/AddGroupModal', () => ({
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 = jest.mocked(showSnackbar);
25
- const mockUseConfig = jest.mocked(useConfig);
26
- const mockUseSession = jest.mocked(useSession);
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: jest.fn(),
35
- destroySession: jest.fn(),
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 = jest.fn();
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 = jest.fn();
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 = jest.fn();
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
- jest.mock('@openmrs/esm-framework', () => ({
7
- fetchCurrentPatient: jest.fn(),
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 jest.MockedFunction<typeof fetchCurrentPatient>;
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
- jest.clearAllMocks();
39
+ vi.clearAllMocks();
39
40
  });
40
41
 
41
42
  it('ignores stale responses after patientUuid changes', async () => {
@@ -1 +1,5 @@
1
- import '@testing-library/jest-dom/extend-expect';
1
+ import '@testing-library/jest-dom/vitest';
2
+ import { afterEach } from 'vitest';
3
+ import { cleanup } from '@testing-library/react';
4
+
5
+ afterEach(cleanup);
@@ -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
- }