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