@trackunit/react-core-contexts-test 0.1.69 → 0.1.71

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/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 = (overrides = {}) => (Object.assign({ userName: "", userRole: "", customerId: 12345, userId: 154312, tasUserId: "751ea227-f199-4d00-925f-a608312c5e45", email: "", name: "", accountId: "", assumedUser: null, jobTitle: "", isAuthenticated: true, isVerified: true, isTrackunitUser: false, isAssuming: false, isAccountOwner: true, subscriptionPackage: "EXPAND_FLEET_OWNER" }, overrides));
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 mockUserSubscriptionProviderValue = (features, packageType) => {
252
- return {
253
- numberOfDaysWithAccessToHistoricalData: 30,
254
- numberOfDaysWithAccessToHistoricalInsights: 30,
255
- features,
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
- * - mount
318
+ * For React Hooks:
319
+ * - renderHook
320
+ * For Storybook:
321
+ * - storybook
305
322
  */
306
- class MockContextProviderBuilder {
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 { MockContextProviderBuilder } - The builder.
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 { MockContextProviderBuilder } - The builder.
356
+ * @returns { TrackunitProvidersMockBuilder } - The builder.
336
357
  */
337
358
  environment(environmentContext) {
338
- this.selectedEnvironmentContext = environmentContext || mockEnvironmentContext;
359
+ this.selectedEnvironmentContext = Object.assign(Object.assign({}, mockEnvironmentContext), environmentContext);
339
360
  return this;
340
361
  }
341
362
  /**
342
- * Use this token.
363
+ * Use this to pass in a differerent current user.
364
+ * Defaults to mockCurrentUserContext.
343
365
  *
344
- * @param token - The token to use.
345
- * @returns { MockContextProviderBuilder } - The builder.
366
+ * @see mockCurrentUserContext
367
+ * @returns { TrackunitProvidersMockBuilder } - The builder.
346
368
  */
347
- token(token) {
348
- this.selectedTokenContext = { token };
369
+ currentUser(currentUserContext) {
370
+ this.selectedCurrentUserContext = Object.assign(Object.assign({}, mockCurrentUserContext), currentUserContext);
349
371
  return this;
350
372
  }
351
373
  /**
352
- * User this to pass in a differerent current user.
374
+ * Use this to pass in a differerent current user subscription.
375
+ * Defaults to mockUserSubscriptionContext.
353
376
  *
354
- * @returns { MockContextProviderBuilder } - The builder.
377
+ * @see mockUserSubscriptionContext
378
+ * @returns { TrackunitProvidersMockBuilder } - The builder.
355
379
  */
356
- currentUser(currentUserContext) {
357
- this.selectedCurrentUserContext = currentUserContext;
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
- * Use this to pass in userSubscriptionPackage.
393
+ * Set global asset sorting context.
394
+ * Defaults to mockAssetSortingContext.
362
395
  *
363
- * @param userSubscriptionPackage - The developer settings context to use.
364
- * @returns { MockContextProviderBuilder } - The builder.
396
+ * @see mockAssetSortingContext
397
+ * @param assetSortingContext - Override the default context.
398
+ * @returns { TrackunitProvidersMockBuilder } - The builder.
365
399
  */
366
- userSubscriptionPackage(userSubscriptionPackage) {
367
- if (userSubscriptionPackage) {
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
- * Use this to pass in SupportedFeatures.
405
+ * Set OEM Branding context.
406
+ * Defaults to mockOemBrandingContext.
374
407
  *
375
- * @param features - The developer settings context to use.
376
- * @returns { MockContextProviderBuilder } - The builder.
408
+ * @see mockOemBrandingContext
409
+ * @param oemBrandingContext - Override the default context.
377
410
  */
378
- supportedFeatures(features) {
379
- if (features) {
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 Router Props with the given mocks.
416
+ * Use this ToastContext with the given mocks.
417
+ * Defaults to mockToastContext.
391
418
  *
392
- * @param routerProps - The router props to use.
393
- * @returns { MockContextProviderBuilder } - The builder.
419
+ * @see mockToastContext
420
+ * @param toastContext - Override the default toast context.
394
421
  */
395
- routerProps(routerProps) {
396
- this.selectedRouterProps = routerProps || {};
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 { MockContextProviderBuilder } - The builder.
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
- * Set global asset sorting context.
438
+ * Use this token.
411
439
  *
412
- * @param overrides - Override the default context.
413
- * @returns { MockContextProviderBuilder } - The builder.
440
+ * @param token - The token to use.
441
+ * @returns { TrackunitProvidersMockBuilder } - The builder.
414
442
  */
415
- assetSorting(overrides) {
416
- this.selectedAssetSortingContext = Object.assign(Object.assign({}, mockAssetSortingContext), overrides);
443
+ token(token) {
444
+ this.selectedTokenContext = { token };
417
445
  return this;
418
446
  }
419
447
  /**
420
- * This will return the mocked composition root.
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
- renderHook(callback, parentElement) {
423
- return __awaiter(this, void 0, void 0, function* () {
424
- this.validateSuppliedMocks();
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
- * Use this ToastContext with the given mocks.
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
- * @param toastContext - Override the default toast context.
470
+ * @returns {boolean} true or throws error if any invalid mocks
443
471
  */
444
- toast(toastContext) {
445
- this.selectedToastContext = Object.assign(Object.assign({}, mockToastContext), toastContext);
446
- return this;
472
+ validateSuppliedMocks() {
473
+ return true;
447
474
  }
448
475
  /**
449
- * Set irisOemApp SDK context.
476
+ * Make sure this represent the same structure as the main index.tsx does.
450
477
  *
451
- * @param overrides - Override the default context.
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
- oemBrandingContext(overrides) {
454
- this.selectedOemBrandingContext = Object.assign(Object.assign({}, mockOemBrandingContext), overrides);
455
- return this;
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 RTL.render the child in the correct mocked hierarchy of context providers.
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
- * Validate the mocks that has been supplied to make sure they make sense.
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
- getMockedCompositionRoot(testChildren, addTestRootContainer = true) {
497
- 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: mockUserSubscriptionProviderValue(this.features, this.userSubscriptionPackageType) }, { 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 })) })) })) })) })) })) })) })) })) })) })) })));
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 MockContextProviderBuilder();
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, MockContextProviderBuilder as M, __awaiter as _, mockCurrentUserContext as a, mockEnvironmentContext as b, flushPromisesInAct as c, doNothing as d, flushPromises as f, mockAnalyticsContext as m, queryFor as q, trackunitProviders as t, useDebugger as u, validateIrisApp as v };
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.69",
3
+ "version": "0.1.71",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "module": "./index.js",
@@ -10,9 +10,10 @@
10
10
  "dependencies": {
11
11
  "@apollo/client": "3.7.10",
12
12
  "@trackunit/react-core-contexts-api": "0.2.37",
13
- "@trackunit/react-core-hooks": "0.2.60",
13
+ "@trackunit/react-core-hooks": "0.2.61",
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
  },