-
Notifications
You must be signed in to change notification settings - Fork 214
/
Copy pathmock.tsx
146 lines (106 loc) · 4.44 KB
/
mock.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import React from 'react';
import { openmrsFetch } from '@openmrs/esm-api/mock';
import { configSchema } from '@openmrs/esm-config/mock';
import { getExtensionInternalStore } from '@openmrs/esm-extensions/mock';
import { createGlobalStore } from '@openmrs/esm-state/mock';
import {
isDesktop as realIsDesktop,
usePagination as realUsePagination,
useOpenmrsPagination as realUseOpenmrsrPagination,
useOpenmrsInfinite as realUseOpenmrsInfinite,
useOpenmrsFetchAll as realUseOpenmrsFetchAll,
useFhirPagination as realUseFhirPagination,
useFhirInfinite as realUseFhirInfinite,
useFhirFetchAll as realUseFhirFetchAll,
} from './src/index';
export { ConfigurableLink, useStore, useStoreWithActions, createUseStore } from './src/index';
import * as utils from '@openmrs/esm-utils';
export const ComponentContext = React.createContext(null);
export const openmrsComponentDecorator = jest.fn().mockImplementation(() => (component) => component);
export const useAttachments = jest.fn(() => ({
isLoading: true,
data: [],
error: null,
mutate: jest.fn(),
isValidating: true,
}));
export const useConfig = jest.fn().mockImplementation((options?: { externalModuleName?: string }) => {
if (options?.externalModuleName) {
console.warn(`Mock useConfig called with externalModuleName: ${options.externalModuleName}`);
}
return utils.getDefaultsFromConfigSchema(configSchema);
});
export const useCurrentPatient = jest.fn(() => []);
export const usePatient = jest.fn(() => ({
isLoading: true,
patient: null,
patientUuid: null,
error: null,
}));
export const useSession = jest.fn(() => ({
authenticated: false,
sessionId: '',
}));
export const useLayoutType = jest.fn(() => 'desktop');
export const useRenderableExtensions = jest.fn(() => []);
export const useAssignedExtensions = jest.fn(() => []);
export const useExtensionSlotMeta = jest.fn(() => ({}));
export const useConnectedExtensions = jest.fn(() => []);
export const UserHasAccess = jest.fn().mockImplementation((props: any) => {
return props.children;
});
export const useExtensionInternalStore = createGlobalStore('extensionInternal', getExtensionInternalStore());
export const useExtensionStore = jest.fn();
export const ExtensionSlot = jest.fn().mockImplementation(({ children }) => <>{children}</>);
export const Extension = jest.fn().mockImplementation((props: any) => <slot />);
export const useFeatureFlag = jest.fn().mockReturnValue(true);
export const usePagination = jest.fn(realUsePagination);
export const useOpenmrsPagination = jest.fn(realUseOpenmrsrPagination);
export const useOpenmrsInfinite = jest.fn(realUseOpenmrsInfinite);
export const useOpenmrsFetchAll = jest.fn(realUseOpenmrsFetchAll);
export const useFhirPagination = jest.fn(realUseFhirPagination);
export const useFhirInfinite = jest.fn(realUseFhirInfinite);
export const useFhirFetchAll = jest.fn(realUseFhirFetchAll);
export const useVisit = jest.fn().mockReturnValue({
error: null,
mutate: jest.fn(),
isValidating: true,
currentVisit: null,
activeVisit: null,
currentVisitIsRetrospective: false,
});
export const useVisitTypes = jest.fn(() => []);
export const useAbortController = jest.fn().mockReturnValue(() => {
let aborted = false;
return jest.fn(
() =>
({
abort: () => {
aborted = true;
},
signal: {
aborted,
},
}) as AbortController,
);
});
export const useOpenmrsSWR = jest.fn((key: string | Array<any>) => {
return { data: openmrsFetch(key.toString()) };
});
export const useDebounce = jest.fn().mockImplementation((value) => value);
export const useOnClickOutside = jest.fn();
export const useBodyScrollLock = jest.fn();
export const isDesktop = jest.fn().mockImplementation(realIsDesktop);
export const useLocations = jest.fn().mockReturnValue([]);
export const toOmrsIsoString = jest.fn().mockImplementation((date: Date) => date.toISOString());
export const toDateObjectStrict = jest.fn().mockImplementation((date: string) => new Date(date));
export const getLocale = jest.fn().mockReturnValue('en');
export const useAppContext = jest.fn();
export const useAssignedExtensionIds = jest.fn();
export const useConnectivity = jest.fn();
export const useDefineAppContext = jest.fn();
export const useExtensionSlot = jest.fn();
export const useForceUpdate = jest.fn();
// TODO: Remove this in favour of usePrimaryIdentifierCode below
export const usePrimaryIdentifierResource = jest.fn();
export const usePrimaryIdentifierCode = jest.fn();