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