@trackunit/react-core-contexts-test 0.1.75 → 0.1.77
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/HookRenderer.cjs +552 -34
- package/HookRenderer.js +546 -35
- package/index.cjs +4 -7
- package/index.js +5 -8
- package/index2.cjs +44454 -709
- package/index2.js +44430 -711
- package/package.json +5 -5
- package/src/ApolloMockedProviderWithError.d.ts +5 -5
- package/src/HookRenderer.d.ts +11 -11
- package/src/TrackunitProvidersMockBuilder.d.ts +326 -304
- package/src/debugger.d.ts +36 -36
- package/src/index.d.ts +13 -13
- package/src/mocks/mockAnalyticsContext.d.ts +2 -2
- package/src/mocks/mockAssetSortingContext.d.ts +2 -2
- package/src/mocks/mockCurrentUserContext.d.ts +7 -7
- package/src/mocks/mockEnvironmentContext.d.ts +2 -2
- package/src/mocks/mockOemBrandingContext.d.ts +2 -2
- package/src/mocks/mockToastContext.d.ts +2 -2
- package/src/mocks/mockUserSubscriptionContext.d.ts +7 -7
- package/src/utils/doNothing.d.ts +4 -4
- package/src/utils/queryFor.d.ts +18 -18
- package/src/utils/validateIrisApp.d.ts +21 -21
- package/src/utils/wait.d.ts +16 -16
|
@@ -1,304 +1,326 @@
|
|
|
1
|
-
import { MockedResponse } from "@apollo/client/testing";
|
|
2
|
-
import { RenderResult } from "@testing-library/react";
|
|
3
|
-
import { IAnalyticsContext, IAssetSortingContext, ICurrentUserContext, IEnvironmentContext, IGlobalSelectionContext, IOemBrandingContext, IToastContext, ITokenContext, IUserSubscriptionContext } from "@trackunit/react-core-contexts-api";
|
|
4
|
-
import * as React from "react";
|
|
5
|
-
import { MemoryRouterProps } from "react-router-dom";
|
|
6
|
-
/**
|
|
7
|
-
* This builder allows you to enable trackunit providers using the builder pattern, and then call 1 of either:
|
|
8
|
-
* For React Components:
|
|
9
|
-
* - render
|
|
10
|
-
* For React Hooks:
|
|
11
|
-
* - renderHook
|
|
12
|
-
* For Storybook:
|
|
13
|
-
* - storybook
|
|
14
|
-
*/
|
|
15
|
-
export declare class TrackunitProvidersMockBuilder {
|
|
16
|
-
protected selectedEnvironmentContext: IEnvironmentContext;
|
|
17
|
-
protected selectedTokenContext: ITokenContext;
|
|
18
|
-
protected selectedApolloMocks: MockedResponse[];
|
|
19
|
-
protected selectedRouterProps: MemoryRouterProps;
|
|
20
|
-
protected selectedToastContext: IToastContext;
|
|
21
|
-
protected selectedGlobalSelection: IGlobalSelectionContext;
|
|
22
|
-
protected selectedAssetSortingContext: IAssetSortingContext;
|
|
23
|
-
protected selectedCurrentUserContext: ICurrentUserContext;
|
|
24
|
-
protected selectedAnalyticsContext: IAnalyticsContext<{}>;
|
|
25
|
-
protected selectedOemBrandingContext: IOemBrandingContext;
|
|
26
|
-
protected selectedUserSubscriptionContext: IUserSubscriptionContext;
|
|
27
|
-
/**
|
|
28
|
-
* Use this Analytics Context.
|
|
29
|
-
* Defaults to mockAnalyticsContext.
|
|
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
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* ...
|
|
161
|
-
*
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* @
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* @example
|
|
191
|
-
* ...
|
|
192
|
-
* it("should allow
|
|
193
|
-
* await trackunitProviders().
|
|
194
|
-
* expect(
|
|
195
|
-
* });
|
|
196
|
-
* ...
|
|
197
|
-
* @
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
* ...
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
* });
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
* ...
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
* }
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
* ...
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
* @
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
*
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
*
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
*
|
|
298
|
-
*/
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
1
|
+
import { MockedResponse } from "@apollo/client/testing";
|
|
2
|
+
import { RenderResult } from "@testing-library/react";
|
|
3
|
+
import { IAnalyticsContext, IAssetSortingContext, ICurrentUserContext, IEnvironmentContext, IGlobalSelectionContext, IOemBrandingContext, IToastContext, ITokenContext, IUserSubscriptionContext } from "@trackunit/react-core-contexts-api";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { MemoryRouterProps } from "react-router-dom";
|
|
6
|
+
/**
|
|
7
|
+
* This builder allows you to enable trackunit providers using the builder pattern, and then call 1 of either:
|
|
8
|
+
* For React Components:
|
|
9
|
+
* - render
|
|
10
|
+
* For React Hooks:
|
|
11
|
+
* - renderHook
|
|
12
|
+
* For Storybook:
|
|
13
|
+
* - storybook
|
|
14
|
+
*/
|
|
15
|
+
export declare class TrackunitProvidersMockBuilder {
|
|
16
|
+
protected selectedEnvironmentContext: IEnvironmentContext;
|
|
17
|
+
protected selectedTokenContext: ITokenContext;
|
|
18
|
+
protected selectedApolloMocks: MockedResponse[];
|
|
19
|
+
protected selectedRouterProps: MemoryRouterProps;
|
|
20
|
+
protected selectedToastContext: IToastContext;
|
|
21
|
+
protected selectedGlobalSelection: IGlobalSelectionContext;
|
|
22
|
+
protected selectedAssetSortingContext: IAssetSortingContext;
|
|
23
|
+
protected selectedCurrentUserContext: ICurrentUserContext;
|
|
24
|
+
protected selectedAnalyticsContext: IAnalyticsContext<{}>;
|
|
25
|
+
protected selectedOemBrandingContext: IOemBrandingContext;
|
|
26
|
+
protected selectedUserSubscriptionContext: IUserSubscriptionContext;
|
|
27
|
+
/**
|
|
28
|
+
* Use this Analytics Context.
|
|
29
|
+
* Defaults to mockAnalyticsContext.
|
|
30
|
+
*
|
|
31
|
+
* This context is used by the useAnalytics hook from lib "@trackunit/react-core-hooks"
|
|
32
|
+
*
|
|
33
|
+
* @see mockAnalyticsContext
|
|
34
|
+
* @example
|
|
35
|
+
* ...
|
|
36
|
+
* it("should allow render", async () => {
|
|
37
|
+
* await trackunitProviders().analytics(yourPartialAnalyticsMock).render(<YourTestComponent data-testid="yourTestId" />);
|
|
38
|
+
* expect(screen.getByTestId("yourTestId")).toBeInTheDocument();
|
|
39
|
+
* });
|
|
40
|
+
* ...
|
|
41
|
+
* @example
|
|
42
|
+
* ...
|
|
43
|
+
* it("should allow renderHook", async () => {
|
|
44
|
+
* const { result } = await trackunitProviders().analytics(yourPartialAnalyticsMock).renderHook(() => useYourTestHook());
|
|
45
|
+
* expect(result.current).toEqual(anything());
|
|
46
|
+
* });
|
|
47
|
+
* ...
|
|
48
|
+
* @param analyticsContext - The analytics context to use.
|
|
49
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
50
|
+
*/
|
|
51
|
+
analytics(analyticsContext: Partial<IAnalyticsContext<any>>): this;
|
|
52
|
+
/**
|
|
53
|
+
* Use this Environment Context.
|
|
54
|
+
* Defaults to mockEnvironmentContext.
|
|
55
|
+
*
|
|
56
|
+
* This context is used by the useEnvironment hook from lib "@trackunit/react-core-hooks"
|
|
57
|
+
*
|
|
58
|
+
* @see mockEnvironmentContext
|
|
59
|
+
* @example
|
|
60
|
+
* ...
|
|
61
|
+
* it("should allow render", async () => {
|
|
62
|
+
* await trackunitProviders().environment(yourPartialEnvironmentsMock).render(<YourTestComponent data-testid="yourTestId" />);
|
|
63
|
+
* expect(screen.getByTestId("yourTestId")).toBeInTheDocument();
|
|
64
|
+
* });
|
|
65
|
+
* ...
|
|
66
|
+
* @example
|
|
67
|
+
* ...
|
|
68
|
+
* it("should allow renderHook", async () => {
|
|
69
|
+
* const { result } = await trackunitProviders().environment(yourPartialEnvironmentMock).renderHook(() => useYourTestHook());
|
|
70
|
+
* expect(result.current).toEqual(anything());
|
|
71
|
+
* });
|
|
72
|
+
* ...
|
|
73
|
+
* @param environmentContext - The environment context to use.
|
|
74
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
75
|
+
*/
|
|
76
|
+
environment(environmentContext: Partial<IEnvironmentContext>): this;
|
|
77
|
+
/**
|
|
78
|
+
* Use this to pass in a differerent current user.
|
|
79
|
+
* Defaults to mockCurrentUserContext.
|
|
80
|
+
*
|
|
81
|
+
* This context is used by the useCurrentUser hook from lib "@trackunit/react-core-hooks"
|
|
82
|
+
*
|
|
83
|
+
* @see mockCurrentUserContext
|
|
84
|
+
* @example
|
|
85
|
+
* ...
|
|
86
|
+
* it("should allow render", async () => {
|
|
87
|
+
* await trackunitProviders().currentUser(yourPartialCurrentUserMock).render(<YourTestComponent data-testid="yourTestId" />);
|
|
88
|
+
* expect(screen.getByTestId("yourTestId")).toBeInTheDocument();
|
|
89
|
+
* });
|
|
90
|
+
* ...
|
|
91
|
+
* @example
|
|
92
|
+
* ...
|
|
93
|
+
* it("should allow renderHook", async () => {
|
|
94
|
+
* const { result } = await trackunitProviders().currentUser(yourPartialCurrentUserMock).renderHook(() => useYourTestHook());
|
|
95
|
+
* expect(result.current).toEqual(anything());
|
|
96
|
+
* });
|
|
97
|
+
* ...
|
|
98
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
99
|
+
*/
|
|
100
|
+
currentUser(currentUserContext: Partial<ICurrentUserContext>): this;
|
|
101
|
+
/**
|
|
102
|
+
* Use this to pass in a differerent current user subscription.
|
|
103
|
+
* Defaults to mockUserSubscriptionContext.
|
|
104
|
+
*
|
|
105
|
+
* This context is used by the useUserSubscription hook from lib "@trackunit/react-core-hooks"
|
|
106
|
+
*
|
|
107
|
+
* @see mockUserSubscriptionContext
|
|
108
|
+
* @example
|
|
109
|
+
* ...
|
|
110
|
+
* it("should allow render", async () => {
|
|
111
|
+
* await trackunitProviders().userSubscription(yourPartialUserSubscriptionMock).render(<YourTestComponent data-testid="yourTestId" />);
|
|
112
|
+
* expect(screen.getByTestId("yourTestId")).toBeInTheDocument();
|
|
113
|
+
* });
|
|
114
|
+
* ...
|
|
115
|
+
* @example
|
|
116
|
+
* ...
|
|
117
|
+
* it("should allow renderHook", async () => {
|
|
118
|
+
* const { result } = await trackunitProviders().userSubscription(yourPartialUserSubscriptionMock).renderHook(() => useYourTestHook());
|
|
119
|
+
* expect(result.current).toEqual(anything());
|
|
120
|
+
* });
|
|
121
|
+
* ...
|
|
122
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
123
|
+
*/
|
|
124
|
+
userSubscription(userSubscription: Partial<IUserSubscriptionContext> | {
|
|
125
|
+
features: string[];
|
|
126
|
+
}): this;
|
|
127
|
+
/**
|
|
128
|
+
* Set global asset sorting context.
|
|
129
|
+
* Defaults to mockAssetSortingContext.
|
|
130
|
+
*
|
|
131
|
+
* This context is used by the useAssetSorting hook from lib "@trackunit/react-core-hooks"
|
|
132
|
+
*
|
|
133
|
+
* @see mockAssetSortingContext
|
|
134
|
+
* @example
|
|
135
|
+
* ...
|
|
136
|
+
* it("should allow render", async () => {
|
|
137
|
+
* await trackunitProviders().assetSorting(yourPartialAssetSortingMock).render(<YourTestComponent data-testid="yourTestId" />);
|
|
138
|
+
* expect(screen.getByTestId("yourTestId")).toBeInTheDocument();
|
|
139
|
+
* });
|
|
140
|
+
* ...
|
|
141
|
+
* @example
|
|
142
|
+
* ...
|
|
143
|
+
* it("should allow renderHook", async () => {
|
|
144
|
+
* const { result } = await trackunitProviders().assetSorting(yourPartialAssetSortingMock).renderHook(() => useYourTestHook());
|
|
145
|
+
* expect(result.current).toEqual(anything());
|
|
146
|
+
* });
|
|
147
|
+
* ...
|
|
148
|
+
* @param assetSortingContext - Override the default context.
|
|
149
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
150
|
+
*/
|
|
151
|
+
assetSorting(assetSortingContext: Partial<IAssetSortingContext>): this;
|
|
152
|
+
/**
|
|
153
|
+
* Set OEM Branding context.
|
|
154
|
+
* Defaults to mockOemBrandingContext.
|
|
155
|
+
*
|
|
156
|
+
* This context is used by the useAssetSorting hook from lib "@trackunit/react-core-hooks"
|
|
157
|
+
*
|
|
158
|
+
* @see mockOemBrandingContext
|
|
159
|
+
* @example
|
|
160
|
+
* ...
|
|
161
|
+
* it("should allow render", async () => {
|
|
162
|
+
* await trackunitProviders().oemBrandingContext(yourPartialOemBrandingMock).render(<YourTestComponent data-testid="yourTestId" />);
|
|
163
|
+
* expect(screen.getByTestId("yourTestId")).toBeInTheDocument();
|
|
164
|
+
* });
|
|
165
|
+
* ...
|
|
166
|
+
* @example
|
|
167
|
+
* ...
|
|
168
|
+
* it("should allow renderHook", async () => {
|
|
169
|
+
* const { result } = await trackunitProviders().oemBrandingContext(yourPartialOemBrandingMock).renderHook(() => useYourTestHook());
|
|
170
|
+
* expect(result.current).toEqual(anything());
|
|
171
|
+
* });
|
|
172
|
+
* ...
|
|
173
|
+
* @param oemBrandingContext - Override the default context.
|
|
174
|
+
*/
|
|
175
|
+
oemBrandingContext(oemBrandingContext: Partial<IOemBrandingContext>): this;
|
|
176
|
+
/**
|
|
177
|
+
* Use this ToastContext with the given mocks.
|
|
178
|
+
* Defaults to mockToastContext.
|
|
179
|
+
*
|
|
180
|
+
* This context is used by the useToast hook from lib "@trackunit/react-core-hooks"
|
|
181
|
+
*
|
|
182
|
+
* @see mockToastContext
|
|
183
|
+
* @example
|
|
184
|
+
* ...
|
|
185
|
+
* it("should allow render", async () => {
|
|
186
|
+
* await trackunitProviders().toast(yourPartialToastMock).render(<YourTestComponent data-testid="yourTestId" />);
|
|
187
|
+
* expect(screen.getByTestId("yourTestId")).toBeInTheDocument();
|
|
188
|
+
* });
|
|
189
|
+
* ...
|
|
190
|
+
* @example
|
|
191
|
+
* ...
|
|
192
|
+
* it("should allow renderHook", async () => {
|
|
193
|
+
* const { result } = await trackunitProviders().toast(yourPartialToastMock).renderHook(() => useYourTestHook());
|
|
194
|
+
* expect(result.current).toEqual(anything());
|
|
195
|
+
* });
|
|
196
|
+
* ...
|
|
197
|
+
* @param toastContext - Override the default toast context.
|
|
198
|
+
*/
|
|
199
|
+
toast(toastContext: Partial<IToastContext>): this;
|
|
200
|
+
/**
|
|
201
|
+
* Use this global selection.
|
|
202
|
+
* Defaults to null.
|
|
203
|
+
*
|
|
204
|
+
* This context is used by the useGlobalSelection hook from lib "@trackunit/react-core-hooks"
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ...
|
|
208
|
+
* it("should allow render", async () => {
|
|
209
|
+
* await trackunitProviders().globalSelection(yourGlobalSelectionMock).render(<YourTestComponent data-testid="yourTestId" />);
|
|
210
|
+
* expect(screen.getByTestId("yourTestId")).toBeInTheDocument();
|
|
211
|
+
* });
|
|
212
|
+
* ...
|
|
213
|
+
* @example
|
|
214
|
+
* ...
|
|
215
|
+
* it("should allow renderHook", async () => {
|
|
216
|
+
* const { result } = await trackunitProviders().globalSelection(yourGlobalSelectionMock).renderHook(() => useYourTestHook());
|
|
217
|
+
* expect(result.current).toEqual(anything());
|
|
218
|
+
* });
|
|
219
|
+
* ...
|
|
220
|
+
* @param globalSelection - The global selection to use.
|
|
221
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
222
|
+
*/
|
|
223
|
+
globalSelection(globalSelection: IGlobalSelectionContext["selection"]): this;
|
|
224
|
+
/**
|
|
225
|
+
* Use this token.
|
|
226
|
+
*
|
|
227
|
+
* This context is used by the useToken hook from lib "@trackunit/react-core-hooks"
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ...
|
|
231
|
+
* it("should allow render", async () => {
|
|
232
|
+
* await trackunitProviders().token(yourMockedToken).render(<YourTestComponent data-testid="yourTestId" />);
|
|
233
|
+
* expect(screen.getByTestId("yourTestId")).toBeInTheDocument();
|
|
234
|
+
* });
|
|
235
|
+
* ...
|
|
236
|
+
* @example
|
|
237
|
+
* ...
|
|
238
|
+
* it("should allow renderHook", async () => {
|
|
239
|
+
* const { result } = await trackunitProviders().token(yourMockedToken).renderHook(() => useYourTestHook());
|
|
240
|
+
* expect(result.current).toEqual(anything());
|
|
241
|
+
* });
|
|
242
|
+
* ...
|
|
243
|
+
* @param token - The token to use.
|
|
244
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
245
|
+
*/
|
|
246
|
+
token(token: string): this;
|
|
247
|
+
/**
|
|
248
|
+
* Use this Router Props with the given mocks.
|
|
249
|
+
*
|
|
250
|
+
* This is used to provide a MemoryRouter from lib "react-router-dom"
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ...
|
|
254
|
+
* it("should allow render", async () => {
|
|
255
|
+
* await trackunitProviders().routerProps(yourRouterPropsMock).render(<YourTestComponent data-testid="yourTestId" />);
|
|
256
|
+
* expect(screen.getByTestId("yourTestId")).toBeInTheDocument();
|
|
257
|
+
* });
|
|
258
|
+
* ...
|
|
259
|
+
* @example
|
|
260
|
+
* ...
|
|
261
|
+
* it("should allow renderHook", async () => {
|
|
262
|
+
* const { result } = await trackunitProviders().routerProps(yourRouterPropsMock).renderHook(() => useYourTestHook());
|
|
263
|
+
* expect(result.current).toEqual(anything());
|
|
264
|
+
* });
|
|
265
|
+
* ...
|
|
266
|
+
* @param routerProps - The router props to use.
|
|
267
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
268
|
+
*/
|
|
269
|
+
routerProps(routerProps: MemoryRouterProps): this;
|
|
270
|
+
/**
|
|
271
|
+
* Use this Manager Apollo Context Provider with the given mocks.
|
|
272
|
+
*
|
|
273
|
+
* This context is used by the useQuery and useLazyQuery hook from lib "@apollo/client"
|
|
274
|
+
*
|
|
275
|
+
* @see https://www.apollographql.com/docs/react/development-testing/testing
|
|
276
|
+
* @example
|
|
277
|
+
* ...
|
|
278
|
+
* it("should allow render", async () => {
|
|
279
|
+
* await trackunitProviders().apollo([yourApolloMocks]).render(<YourTestComponent data-testid="yourTestId" />);
|
|
280
|
+
* expect(screen.getByTestId("yourTestId")).toBeInTheDocument();
|
|
281
|
+
* });
|
|
282
|
+
* ...
|
|
283
|
+
* @example
|
|
284
|
+
* ...
|
|
285
|
+
* it("should allow renderHook", async () => {
|
|
286
|
+
* const { result } = await trackunitProviders().apollo([yourApolloMocks]).renderHook(() => useYourTestHook());
|
|
287
|
+
* expect(result.current).toEqual(anything());
|
|
288
|
+
* });
|
|
289
|
+
* ...
|
|
290
|
+
* @param apolloMocks - The mocks to use for the ApolloProvider.
|
|
291
|
+
*/
|
|
292
|
+
apollo(apolloMocks?: MockedResponse[]): this;
|
|
293
|
+
/**
|
|
294
|
+
* Validate the mocks that has been supplied to make sure they make sense.
|
|
295
|
+
* Note: This function is overriden in builders extending this one.
|
|
296
|
+
*
|
|
297
|
+
* @returns {boolean} true or throws error if any invalid mocks
|
|
298
|
+
*/
|
|
299
|
+
protected validateSuppliedMocks(): true | never;
|
|
300
|
+
/**
|
|
301
|
+
* Make sure this represent the same structure as the main index.tsx does.
|
|
302
|
+
*
|
|
303
|
+
* @param testChildren - the child element being tested.
|
|
304
|
+
* @param addTestRootContainer - if you want to add a root container to the test.
|
|
305
|
+
*/
|
|
306
|
+
protected getMockedCompositionRoot(testChildren: React.ReactNode, addTestRootContainer?: boolean): JSX.Element;
|
|
307
|
+
/**
|
|
308
|
+
* This will return the mocked composition root.
|
|
309
|
+
*/
|
|
310
|
+
renderHook<TProps, TResult>(callback: (props: TProps) => TResult, parentElement?: (children: React.ReactElement) => React.ReactElement): Promise<import("@testing-library/react").RenderHookResult<TResult, TProps>>;
|
|
311
|
+
/**
|
|
312
|
+
* This will use react-testing-library.render the child in the correct mocked hierarchy of context providers.
|
|
313
|
+
*
|
|
314
|
+
* @see https://testing-library.com/docs/react-testing-library/api#render
|
|
315
|
+
* @param child - the child element being tested.
|
|
316
|
+
*/
|
|
317
|
+
render(child: React.ReactElement): Promise<RenderResult>;
|
|
318
|
+
/**
|
|
319
|
+
* This will return the children in the correct mocked hierarchy of context providers.
|
|
320
|
+
*/
|
|
321
|
+
storybook(child: React.ReactNode): JSX.Element;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* This is the default mock builder for the TrackunitProviders.
|
|
325
|
+
*/
|
|
326
|
+
export declare const trackunitProviders: () => TrackunitProvidersMockBuilder;
|