@trackunit/react-core-contexts-test 0.1.69 → 0.1.70
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 +1 -0
- package/HookRenderer.js +1 -0
- package/index.cjs +7 -2
- package/index.js +3 -2
- package/index2.cjs +202 -171
- package/index2.js +198 -171
- package/package.json +2 -1
- package/src/{MockContextProviderBuilder.d.ts → TrackunitProvidersMockBuilder.d.ts} +73 -56
- package/src/index.d.ts +5 -1
- package/src/mocks/mockCurrentUserContext.d.ts +1 -2
- package/src/mocks/mockUserSubscriptionContext.d.ts +2 -4
- /package/src/mocks/{mockIrisOemAppSDKContext.d.ts → mockOemBrandingContext.d.ts} +0 -0
package/index2.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import React, { useRef, useMemo, useEffect } from 'react';
|
|
3
|
+
import { AssetSortByProperty, SortOrder } from '@trackunit/react-core-contexts-api';
|
|
3
4
|
import { act, render } from '@testing-library/react';
|
|
4
|
-
import { AssetSortByProperty, SortOrder, UserSubscriptionPackage } from '@trackunit/react-core-contexts-api';
|
|
5
5
|
import { EnvironmentContextProvider, CurrentUserProvider, AnalyticsContext, UserSubscriptionProvider, OemBrandingContextProvider, TokenProvider, ToastProvider, GlobalSelectionProvider, AssetSortingProvider } from '@trackunit/react-core-hooks';
|
|
6
6
|
import { tw } from '@trackunit/tailwind-styled-components';
|
|
7
|
+
import { omit } from 'lodash';
|
|
7
8
|
import { MemoryRouter } from 'react-router-dom';
|
|
8
9
|
import { ApolloLink } from '@apollo/client';
|
|
9
10
|
import { onError } from '@apollo/client/link/error';
|
|
@@ -97,79 +98,6 @@ const Debugger = ({ id, logPropsChanges, stop, children, }) => {
|
|
|
97
98
|
return jsx("div", Object.assign({ className: "Debugger" }, { children: children }));
|
|
98
99
|
};
|
|
99
100
|
|
|
100
|
-
/******************************************************************************
|
|
101
|
-
Copyright (c) Microsoft Corporation.
|
|
102
|
-
|
|
103
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
104
|
-
purpose with or without fee is hereby granted.
|
|
105
|
-
|
|
106
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
107
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
108
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
109
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
110
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
111
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
112
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
113
|
-
***************************************************************************** */
|
|
114
|
-
|
|
115
|
-
function __rest(s, e) {
|
|
116
|
-
var t = {};
|
|
117
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
118
|
-
t[p] = s[p];
|
|
119
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
120
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
121
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
122
|
-
t[p[i]] = s[p[i]];
|
|
123
|
-
}
|
|
124
|
-
return t;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
128
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
129
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
130
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
131
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
132
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
133
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const defaultOptions = {
|
|
138
|
-
mutate: {
|
|
139
|
-
errorPolicy: "all",
|
|
140
|
-
},
|
|
141
|
-
query: {
|
|
142
|
-
errorPolicy: "all",
|
|
143
|
-
},
|
|
144
|
-
};
|
|
145
|
-
/**
|
|
146
|
-
* This is a wrapper around the MockedProvider that logs errors to the console.
|
|
147
|
-
*/
|
|
148
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
149
|
-
function ApolloMockedProviderWithError(props) {
|
|
150
|
-
const { mocks } = props, otherProps = __rest(props, ["mocks"]);
|
|
151
|
-
const mockLink = new MockLink(mocks);
|
|
152
|
-
const errorLoggingLink = onError(({ graphQLErrors, networkError }) => {
|
|
153
|
-
if (graphQLErrors) {
|
|
154
|
-
// eslint-disable-next-line array-callback-return
|
|
155
|
-
graphQLErrors.map(({ message, locations, path }) => {
|
|
156
|
-
if (process.env.VSCODE_INSPECTOR_OPTIONS || process.env.DEBUG) {
|
|
157
|
-
// eslint-disable-next-line no-console
|
|
158
|
-
console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
if (networkError) {
|
|
163
|
-
if (process.env.VSCODE_INSPECTOR_OPTIONS || process.env.DEBUG) {
|
|
164
|
-
// eslint-disable-next-line no-console
|
|
165
|
-
console.log(`[Network error]: ${networkError}`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
const link = ApolloLink.from([errorLoggingLink, mockLink]);
|
|
170
|
-
return (jsx(MockedProvider, Object.assign({}, otherProps, { link: link, defaultOptions: Object.assign(Object.assign({}, defaultOptions), { watchQuery: { fetchPolicy: "no-cache" } }) })));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
101
|
/**
|
|
174
102
|
* Do nothing
|
|
175
103
|
*/
|
|
@@ -196,10 +124,26 @@ const mockAssetSortingContext = {
|
|
|
196
124
|
/**
|
|
197
125
|
* Mocks the current user context
|
|
198
126
|
*
|
|
199
|
-
* @param overrides - The overrides to apply to the mock
|
|
200
127
|
* @returns {ICurrentUserContext} - Returns the mocked current user context
|
|
201
128
|
*/
|
|
202
|
-
const mockCurrentUserContext =
|
|
129
|
+
const mockCurrentUserContext = {
|
|
130
|
+
userName: "",
|
|
131
|
+
userRole: "",
|
|
132
|
+
customerId: 12345,
|
|
133
|
+
userId: 154312,
|
|
134
|
+
tasUserId: "751ea227-f199-4d00-925f-a608312c5e45",
|
|
135
|
+
email: "",
|
|
136
|
+
name: "",
|
|
137
|
+
accountId: "",
|
|
138
|
+
assumedUser: null,
|
|
139
|
+
jobTitle: "",
|
|
140
|
+
isAuthenticated: true,
|
|
141
|
+
isVerified: true,
|
|
142
|
+
isTrackunitUser: false,
|
|
143
|
+
isAssuming: false,
|
|
144
|
+
isAccountOwner: true,
|
|
145
|
+
subscriptionPackage: "EXPAND_FLEET_OWNER",
|
|
146
|
+
};
|
|
203
147
|
|
|
204
148
|
const mockEnvironmentContext = {
|
|
205
149
|
auth: {
|
|
@@ -244,19 +188,88 @@ const mockToastContext = {
|
|
|
244
188
|
/**
|
|
245
189
|
* This is a mock for the UserSubscriptionContext.
|
|
246
190
|
*
|
|
247
|
-
* @param features - array of features
|
|
248
|
-
* @param packageType - package type
|
|
249
191
|
* @returns { IUserSubscriptionContext }- mock for the UserSubscriptionContext
|
|
250
192
|
*/
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
packageType,
|
|
257
|
-
};
|
|
193
|
+
const mockUserSubscriptionContext = {
|
|
194
|
+
numberOfDaysWithAccessToHistoricalData: 30,
|
|
195
|
+
numberOfDaysWithAccessToHistoricalInsights: 30,
|
|
196
|
+
features: [],
|
|
197
|
+
packageType: "EXPAND_FLEET_OWNER",
|
|
258
198
|
};
|
|
259
199
|
|
|
200
|
+
/******************************************************************************
|
|
201
|
+
Copyright (c) Microsoft Corporation.
|
|
202
|
+
|
|
203
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
204
|
+
purpose with or without fee is hereby granted.
|
|
205
|
+
|
|
206
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
207
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
208
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
209
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
210
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
211
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
212
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
213
|
+
***************************************************************************** */
|
|
214
|
+
|
|
215
|
+
function __rest(s, e) {
|
|
216
|
+
var t = {};
|
|
217
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
218
|
+
t[p] = s[p];
|
|
219
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
220
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
221
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
222
|
+
t[p[i]] = s[p[i]];
|
|
223
|
+
}
|
|
224
|
+
return t;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
228
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
229
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
230
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
231
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
232
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
233
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const defaultOptions = {
|
|
238
|
+
mutate: {
|
|
239
|
+
errorPolicy: "all",
|
|
240
|
+
},
|
|
241
|
+
query: {
|
|
242
|
+
errorPolicy: "all",
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* This is a wrapper around the MockedProvider that logs errors to the console.
|
|
247
|
+
*/
|
|
248
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
249
|
+
function ApolloMockedProviderWithError(props) {
|
|
250
|
+
const { mocks } = props, otherProps = __rest(props, ["mocks"]);
|
|
251
|
+
const mockLink = new MockLink(mocks);
|
|
252
|
+
const errorLoggingLink = onError(({ graphQLErrors, networkError }) => {
|
|
253
|
+
if (graphQLErrors) {
|
|
254
|
+
// eslint-disable-next-line array-callback-return
|
|
255
|
+
graphQLErrors.map(({ message, locations, path }) => {
|
|
256
|
+
if (process.env.VSCODE_INSPECTOR_OPTIONS || process.env.DEBUG) {
|
|
257
|
+
// eslint-disable-next-line no-console
|
|
258
|
+
console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
if (networkError) {
|
|
263
|
+
if (process.env.VSCODE_INSPECTOR_OPTIONS || process.env.DEBUG) {
|
|
264
|
+
// eslint-disable-next-line no-console
|
|
265
|
+
console.log(`[Network error]: ${networkError}`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
const link = ApolloLink.from([errorLoggingLink, mockLink]);
|
|
270
|
+
return (jsx(MockedProvider, Object.assign({}, otherProps, { link: link, defaultOptions: Object.assign(Object.assign({}, defaultOptions), { watchQuery: { fetchPolicy: "no-cache" } }) })));
|
|
271
|
+
}
|
|
272
|
+
|
|
260
273
|
/**
|
|
261
274
|
* Flushes all promises in the queue.
|
|
262
275
|
* This is useful when testing async code.
|
|
@@ -299,133 +312,147 @@ const flushPromisesInAct = (waitTimeInMS = 0) => {
|
|
|
299
312
|
};
|
|
300
313
|
|
|
301
314
|
/**
|
|
302
|
-
* This builder allows you to enable providers using the builder pattern, and then call 1 of either:
|
|
315
|
+
* This builder allows you to enable trackunit providers using the builder pattern, and then call 1 of either:
|
|
316
|
+
* For React Components:
|
|
303
317
|
* - render
|
|
304
|
-
*
|
|
318
|
+
* For React Hooks:
|
|
319
|
+
* - renderHook
|
|
320
|
+
* For Storybook:
|
|
321
|
+
* - storybook
|
|
305
322
|
*/
|
|
306
|
-
class
|
|
323
|
+
class TrackunitProvidersMockBuilder {
|
|
307
324
|
constructor() {
|
|
308
325
|
this.selectedEnvironmentContext = mockEnvironmentContext;
|
|
309
326
|
this.selectedTokenContext = { token: "fakeToken" };
|
|
310
|
-
this.userSubscriptionPackageType = UserSubscriptionPackage.INSIGHT;
|
|
311
|
-
this.features = [];
|
|
312
327
|
this.selectedApolloMocks = [];
|
|
313
328
|
this.selectedRouterProps = {};
|
|
314
329
|
this.selectedToastContext = mockToastContext;
|
|
315
330
|
this.selectedGlobalSelection = { selection: null };
|
|
316
331
|
this.selectedAssetSortingContext = mockAssetSortingContext;
|
|
317
|
-
this.selectedCurrentUserContext = mockCurrentUserContext
|
|
332
|
+
this.selectedCurrentUserContext = mockCurrentUserContext;
|
|
318
333
|
this.selectedAnalyticsContext = mockAnalyticsContext;
|
|
319
334
|
this.selectedOemBrandingContext = mockOemBrandingContext;
|
|
335
|
+
this.selectedUserSubscriptionContext = mockUserSubscriptionContext;
|
|
320
336
|
}
|
|
321
337
|
/**
|
|
322
338
|
* Use this Analytics Context.
|
|
339
|
+
* Defaults to mockAnalyticsContext.
|
|
323
340
|
*
|
|
341
|
+
* @see mockAnalyticsContext
|
|
324
342
|
* @param analyticsContext - The analytics context to use.
|
|
325
|
-
* @returns {
|
|
343
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
326
344
|
*/
|
|
345
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
327
346
|
analytics(analyticsContext) {
|
|
328
|
-
this.selectedAnalyticsContext = analyticsContext;
|
|
347
|
+
this.selectedAnalyticsContext = Object.assign(Object.assign({}, mockAnalyticsContext), analyticsContext);
|
|
329
348
|
return this;
|
|
330
349
|
}
|
|
331
350
|
/**
|
|
332
351
|
* Use this Environment Context.
|
|
352
|
+
* Defaults to mockEnvironmentContext.
|
|
333
353
|
*
|
|
354
|
+
* @see mockEnvironmentContext
|
|
334
355
|
* @param environmentContext - The environment context to use.
|
|
335
|
-
* @returns {
|
|
356
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
336
357
|
*/
|
|
337
358
|
environment(environmentContext) {
|
|
338
|
-
this.selectedEnvironmentContext =
|
|
359
|
+
this.selectedEnvironmentContext = Object.assign(Object.assign({}, mockEnvironmentContext), environmentContext);
|
|
339
360
|
return this;
|
|
340
361
|
}
|
|
341
362
|
/**
|
|
342
|
-
* Use this
|
|
363
|
+
* Use this to pass in a differerent current user.
|
|
364
|
+
* Defaults to mockCurrentUserContext.
|
|
343
365
|
*
|
|
344
|
-
* @
|
|
345
|
-
* @returns {
|
|
366
|
+
* @see mockCurrentUserContext
|
|
367
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
346
368
|
*/
|
|
347
|
-
|
|
348
|
-
this.
|
|
369
|
+
currentUser(currentUserContext) {
|
|
370
|
+
this.selectedCurrentUserContext = Object.assign(Object.assign({}, mockCurrentUserContext), currentUserContext);
|
|
349
371
|
return this;
|
|
350
372
|
}
|
|
351
373
|
/**
|
|
352
|
-
*
|
|
374
|
+
* Use this to pass in a differerent current user subscription.
|
|
375
|
+
* Defaults to mockUserSubscriptionContext.
|
|
353
376
|
*
|
|
354
|
-
* @
|
|
377
|
+
* @see mockUserSubscriptionContext
|
|
378
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
355
379
|
*/
|
|
356
|
-
|
|
357
|
-
|
|
380
|
+
userSubscription(userSubscription) {
|
|
381
|
+
var _a;
|
|
382
|
+
//TODO DONT SUPPORT THE WIERD WAY OF PASSING FEATURES
|
|
383
|
+
const featuresConverted = ((_a = userSubscription === null || userSubscription === void 0 ? void 0 : userSubscription.features) === null || _a === void 0 ? void 0 : _a.map(f => {
|
|
384
|
+
if (typeof f === "string") {
|
|
385
|
+
return { id: f, name: f };
|
|
386
|
+
}
|
|
387
|
+
return f;
|
|
388
|
+
})) || [];
|
|
389
|
+
this.selectedUserSubscriptionContext = Object.assign(Object.assign(Object.assign({}, mockUserSubscriptionContext), omit(userSubscription, "features")), { features: [...(mockUserSubscriptionContext.features || []), ...featuresConverted] });
|
|
358
390
|
return this;
|
|
359
391
|
}
|
|
360
392
|
/**
|
|
361
|
-
*
|
|
393
|
+
* Set global asset sorting context.
|
|
394
|
+
* Defaults to mockAssetSortingContext.
|
|
362
395
|
*
|
|
363
|
-
* @
|
|
364
|
-
* @
|
|
396
|
+
* @see mockAssetSortingContext
|
|
397
|
+
* @param assetSortingContext - Override the default context.
|
|
398
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
365
399
|
*/
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
this.userSubscriptionPackageType = userSubscriptionPackage;
|
|
369
|
-
}
|
|
400
|
+
assetSorting(assetSortingContext) {
|
|
401
|
+
this.selectedAssetSortingContext = Object.assign(Object.assign({}, mockAssetSortingContext), assetSortingContext);
|
|
370
402
|
return this;
|
|
371
403
|
}
|
|
372
404
|
/**
|
|
373
|
-
*
|
|
405
|
+
* Set OEM Branding context.
|
|
406
|
+
* Defaults to mockOemBrandingContext.
|
|
374
407
|
*
|
|
375
|
-
* @
|
|
376
|
-
* @
|
|
408
|
+
* @see mockOemBrandingContext
|
|
409
|
+
* @param oemBrandingContext - Override the default context.
|
|
377
410
|
*/
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
this.features = features.map(feature => {
|
|
381
|
-
return {
|
|
382
|
-
id: feature,
|
|
383
|
-
name: feature,
|
|
384
|
-
};
|
|
385
|
-
});
|
|
386
|
-
}
|
|
411
|
+
oemBrandingContext(oemBrandingContext) {
|
|
412
|
+
this.selectedOemBrandingContext = Object.assign(Object.assign({}, mockOemBrandingContext), oemBrandingContext);
|
|
387
413
|
return this;
|
|
388
414
|
}
|
|
389
415
|
/**
|
|
390
|
-
* Use this
|
|
416
|
+
* Use this ToastContext with the given mocks.
|
|
417
|
+
* Defaults to mockToastContext.
|
|
391
418
|
*
|
|
392
|
-
* @
|
|
393
|
-
* @
|
|
419
|
+
* @see mockToastContext
|
|
420
|
+
* @param toastContext - Override the default toast context.
|
|
394
421
|
*/
|
|
395
|
-
|
|
396
|
-
this.
|
|
422
|
+
toast(toastContext) {
|
|
423
|
+
this.selectedToastContext = Object.assign(Object.assign({}, mockToastContext), toastContext);
|
|
397
424
|
return this;
|
|
398
425
|
}
|
|
399
426
|
/**
|
|
400
427
|
* Use this global selection.
|
|
428
|
+
* Defaults to null.
|
|
401
429
|
*
|
|
402
430
|
* @param globalSelection - The global selection to use.
|
|
403
|
-
* @returns {
|
|
431
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
404
432
|
*/
|
|
405
433
|
globalSelection(globalSelection) {
|
|
406
434
|
this.selectedGlobalSelection = { selection: globalSelection };
|
|
407
435
|
return this;
|
|
408
436
|
}
|
|
409
437
|
/**
|
|
410
|
-
*
|
|
438
|
+
* Use this token.
|
|
411
439
|
*
|
|
412
|
-
* @param
|
|
413
|
-
* @returns {
|
|
440
|
+
* @param token - The token to use.
|
|
441
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
414
442
|
*/
|
|
415
|
-
|
|
416
|
-
this.
|
|
443
|
+
token(token) {
|
|
444
|
+
this.selectedTokenContext = { token };
|
|
417
445
|
return this;
|
|
418
446
|
}
|
|
419
447
|
/**
|
|
420
|
-
*
|
|
448
|
+
* Use this Router Props with the given mocks.
|
|
449
|
+
*
|
|
450
|
+
* @param routerProps - The router props to use.
|
|
451
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
421
452
|
*/
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
// This ensures correct act loading when using hooks
|
|
426
|
-
const hookRenderer = yield import('./HookRenderer.js');
|
|
427
|
-
return hookRenderer.reactHooksRenderHook(callback, children => this.getMockedCompositionRoot(parentElement ? parentElement(children) : children));
|
|
428
|
-
});
|
|
453
|
+
routerProps(routerProps) {
|
|
454
|
+
this.selectedRouterProps = routerProps;
|
|
455
|
+
return this;
|
|
429
456
|
}
|
|
430
457
|
/**
|
|
431
458
|
* Use this Manager Apollo Context Provider with the given mocks.
|
|
@@ -437,26 +464,38 @@ class MockContextProviderBuilder {
|
|
|
437
464
|
return this;
|
|
438
465
|
}
|
|
439
466
|
/**
|
|
440
|
-
*
|
|
467
|
+
* Validate the mocks that has been supplied to make sure they make sense.
|
|
468
|
+
* Note: This function is overriden in builders extending this one.
|
|
441
469
|
*
|
|
442
|
-
* @
|
|
470
|
+
* @returns {boolean} true or throws error if any invalid mocks
|
|
443
471
|
*/
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
return this;
|
|
472
|
+
validateSuppliedMocks() {
|
|
473
|
+
return true;
|
|
447
474
|
}
|
|
448
475
|
/**
|
|
449
|
-
*
|
|
476
|
+
* Make sure this represent the same structure as the main index.tsx does.
|
|
450
477
|
*
|
|
451
|
-
* @param
|
|
478
|
+
* @param testChildren - the child element being tested.
|
|
479
|
+
* @param addTestRootContainer - if you want to add a root container to the test.
|
|
452
480
|
*/
|
|
453
|
-
|
|
454
|
-
this.selectedOemBrandingContext
|
|
455
|
-
|
|
481
|
+
getMockedCompositionRoot(testChildren, addTestRootContainer = true) {
|
|
482
|
+
return (jsx(EnvironmentContextProvider, Object.assign({ value: this.selectedEnvironmentContext }, { children: jsx(MemoryRouter, Object.assign({}, this.selectedRouterProps, { children: jsx(CurrentUserProvider, Object.assign({ value: this.selectedCurrentUserContext }, { children: jsx(AnalyticsContext.Provider, Object.assign({ value: this.selectedAnalyticsContext }, { children: jsx(UserSubscriptionProvider, Object.assign({ value: this.selectedUserSubscriptionContext }, { children: jsx(OemBrandingContextProvider, Object.assign({ value: this.selectedOemBrandingContext }, { children: jsx(TokenProvider, Object.assign({ value: this.selectedTokenContext }, { children: jsx(ToastProvider, Object.assign({ value: this.selectedToastContext }, { children: jsx(GlobalSelectionProvider, Object.assign({ value: this.selectedGlobalSelection }, { children: jsx(AssetSortingProvider, Object.assign({ value: this.selectedAssetSortingContext }, { children: jsx(ApolloMockedProviderWithError, Object.assign({ mocks: this.selectedApolloMocks, addTypename: false }, { children: addTestRootContainer ? (jsx(TestRoot, Object.assign({ "data-testid": "testRoot" }, { children: testChildren }))) : (jsx("div", { children: testChildren })) })) })) })) })) })) })) })) })) })) })) })));
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* This will return the mocked composition root.
|
|
486
|
+
*/
|
|
487
|
+
renderHook(callback, parentElement) {
|
|
488
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
489
|
+
this.validateSuppliedMocks();
|
|
490
|
+
// This ensures correct act loading when using hooks and not loaded if this build is used for storybook
|
|
491
|
+
const hookRenderer = yield import('./HookRenderer.js');
|
|
492
|
+
return hookRenderer.reactHooksRenderHook(callback, children => this.getMockedCompositionRoot(parentElement ? parentElement(children) : children));
|
|
493
|
+
});
|
|
456
494
|
}
|
|
457
495
|
/**
|
|
458
|
-
* This will use
|
|
496
|
+
* This will use react-testing-library.render the child in the correct mocked hierarchy of context providers.
|
|
459
497
|
*
|
|
498
|
+
* @see https://testing-library.com/docs/react-testing-library/api#render
|
|
460
499
|
* @param child - the child element being tested.
|
|
461
500
|
*/
|
|
462
501
|
render(child) {
|
|
@@ -479,28 +518,16 @@ class MockContextProviderBuilder {
|
|
|
479
518
|
});
|
|
480
519
|
}
|
|
481
520
|
/**
|
|
482
|
-
*
|
|
483
|
-
* Note: This function is overriden in builders extending this one.
|
|
484
|
-
*
|
|
485
|
-
* @returns {boolean} true or throws error if any invalid mocks
|
|
486
|
-
*/
|
|
487
|
-
validateSuppliedMocks() {
|
|
488
|
-
return true;
|
|
489
|
-
}
|
|
490
|
-
/**
|
|
491
|
-
* Make sure this represent the same structure as the main index.tsx does.
|
|
492
|
-
*
|
|
493
|
-
* @param testChildren - the child element being tested.
|
|
494
|
-
* @param addTestRootContainer - if you want to add a root container to the test.
|
|
521
|
+
* This will return the children in the correct mocked hierarchy of context providers.
|
|
495
522
|
*/
|
|
496
|
-
|
|
497
|
-
return
|
|
523
|
+
storybook(child) {
|
|
524
|
+
return this.getMockedCompositionRoot(child, false);
|
|
498
525
|
}
|
|
499
526
|
}
|
|
500
527
|
/**
|
|
501
|
-
*
|
|
528
|
+
* This is the default mock builder for the TrackunitProviders.
|
|
502
529
|
*/
|
|
503
|
-
const trackunitProviders = () => new
|
|
530
|
+
const trackunitProviders = () => new TrackunitProvidersMockBuilder();
|
|
504
531
|
const TestRoot = tw.div `
|
|
505
532
|
--tw-scale-x: 0.99;
|
|
506
533
|
--tw-scale-y: 0.99;
|
|
@@ -588,4 +615,4 @@ const validateIrisApp = (irisApp) => __awaiter(void 0, void 0, void 0, function*
|
|
|
588
615
|
return null;
|
|
589
616
|
});
|
|
590
617
|
|
|
591
|
-
export { Debugger as D,
|
|
618
|
+
export { Debugger as D, TrackunitProvidersMockBuilder as T, __awaiter as _, mockAssetSortingContext as a, mockCurrentUserContext as b, mockEnvironmentContext as c, mockOemBrandingContext as d, mockToastContext as e, flushPromises as f, mockUserSubscriptionContext as g, doNothing as h, flushPromisesInAct as i, mockAnalyticsContext as m, queryFor as q, trackunitProviders as t, useDebugger as u, validateIrisApp as v };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-core-contexts-test",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.70",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"@trackunit/react-core-hooks": "0.2.60",
|
|
14
14
|
"@trackunit/tailwind-styled-components": "0.0.56",
|
|
15
15
|
"graphql": "15.8.0",
|
|
16
|
+
"lodash": "4.17.21",
|
|
16
17
|
"react": "18.2.0",
|
|
17
18
|
"react-router-dom": "6.4.5"
|
|
18
19
|
},
|