@trackunit/react-core-contexts-test 0.1.68 → 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 +8 -3
- package/index.js +3 -2
- package/index2.cjs +249 -195
- package/index2.js +232 -186
- package/package.json +2 -1
- package/src/{MockContextProviderBuilder.d.ts → TrackunitProvidersMockBuilder.d.ts} +73 -56
- package/src/debugger.d.ts +19 -7
- 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.cjs
CHANGED
|
@@ -1,31 +1,42 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
-
var
|
|
5
|
-
var react$1 = require('@testing-library/react');
|
|
4
|
+
var React = require('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');
|
|
12
13
|
var testing = require('@apollo/client/testing');
|
|
13
14
|
var graphql = require('graphql');
|
|
14
15
|
|
|
16
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
17
|
+
|
|
18
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
19
|
+
|
|
15
20
|
/**
|
|
16
21
|
* Logs props that have changed.
|
|
17
22
|
* Use this for debugging which props force a component to re-render.
|
|
18
23
|
* This is a hook version of the class component lifecycle method `componentDidUpdate`.
|
|
19
24
|
* ALWAYS wrap in your own object.
|
|
20
25
|
*
|
|
26
|
+
* @param id optional id to use for logging or it will guess the id from the stack trace
|
|
21
27
|
* @param propsToWatch all the props to watch for changes
|
|
28
|
+
* @example
|
|
29
|
+
* const propsToWatch = { foo: props.foo, bar: props.bar };
|
|
30
|
+
* useDebugger({ id: "MyComponent", propsToWatch });
|
|
22
31
|
*/
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
const useDebugger = ({ id, propsToWatch, }) => {
|
|
33
|
+
const prevPropsRef = React.useRef(propsToWatch);
|
|
34
|
+
const uniqueId = React.useMemo(() => {
|
|
35
|
+
var _a;
|
|
36
|
+
return id || ((_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n")[2].trim()) || "unknown-id";
|
|
37
|
+
}, [id]);
|
|
38
|
+
React.useEffect(() => {
|
|
39
|
+
const changedProps = Object.entries(propsToWatch || {}).reduce((result, [key, value]) => {
|
|
29
40
|
if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
|
|
30
41
|
result[key + ""] = [prevPropsRef.current[key], value];
|
|
31
42
|
}
|
|
@@ -35,7 +46,7 @@ const useLogPropsChanged = (propsToWatch) => {
|
|
|
35
46
|
// eslint-disable-next-line no-console
|
|
36
47
|
Object.keys(changedProps).forEach(changedProp => {
|
|
37
48
|
// eslint-disable-next-line no-console
|
|
38
|
-
console.log(
|
|
49
|
+
console.log(`${uniqueId} changed property: ${changedProp}`);
|
|
39
50
|
// JSON stringify is used to avoid console.table from logging the object reference
|
|
40
51
|
const result = JSON.parse(JSON.stringify(changedProps[changedProp]));
|
|
41
52
|
const result0 = result[0];
|
|
@@ -55,104 +66,44 @@ const useLogPropsChanged = (propsToWatch) => {
|
|
|
55
66
|
console.dir(changedProps);
|
|
56
67
|
}
|
|
57
68
|
prevPropsRef.current = propsToWatch;
|
|
58
|
-
}, [
|
|
69
|
+
}, [propsToWatch, uniqueId]);
|
|
59
70
|
};
|
|
60
71
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
72
|
+
* Debugger component for debugging state changes and re-renders.
|
|
73
|
+
*
|
|
74
|
+
* This component will log when it is mounted, re-renders or unmounted.
|
|
63
75
|
* It will also log when any of its props change.
|
|
64
76
|
*
|
|
65
|
-
* @param
|
|
77
|
+
* @param id optional id to use for logging
|
|
78
|
+
* @param stop if true, will stop execution and open debugger
|
|
79
|
+
* @param logPropsChanges optional object with props to watch for changes
|
|
66
80
|
* @param children the children to render
|
|
67
81
|
*/
|
|
68
|
-
const Debugger = ({ logPropsChanges, children }) => {
|
|
69
|
-
|
|
82
|
+
const Debugger = ({ id, logPropsChanges, stop, children, }) => {
|
|
83
|
+
var _a, _b, _c, _d, _e, _f;
|
|
84
|
+
const uniqueId = id ||
|
|
85
|
+
((_e = (_d = (_c = (_b = (_a = React__default["default"]["__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED"]) === null || _a === void 0 ? void 0 : _a.ReactCurrentOwner) === null || _b === void 0 ? void 0 : _b.current) === null || _c === void 0 ? void 0 : _c._debugOwner) === null || _d === void 0 ? void 0 : _d.type) === null || _e === void 0 ? void 0 : _e.name) ||
|
|
86
|
+
((_f = new Error().stack) === null || _f === void 0 ? void 0 : _f.split("\n")[2].trim()) ||
|
|
87
|
+
"unknown-id";
|
|
88
|
+
useDebugger({ id: uniqueId, propsToWatch: logPropsChanges || {} });
|
|
70
89
|
// eslint-disable-next-line no-console
|
|
71
|
-
console.log(
|
|
72
|
-
|
|
90
|
+
console.log(`${uniqueId} Debugger is rendering`);
|
|
91
|
+
React.useEffect(() => {
|
|
73
92
|
// eslint-disable-next-line no-console
|
|
74
|
-
console.log(
|
|
93
|
+
console.log(`${uniqueId} Debugger is mounting`);
|
|
75
94
|
return () => {
|
|
76
95
|
// eslint-disable-next-line no-console
|
|
77
|
-
console.log(
|
|
96
|
+
console.log(`${uniqueId} Debugger is unmounting`);
|
|
78
97
|
};
|
|
98
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
79
99
|
}, []);
|
|
100
|
+
if (stop === true) {
|
|
101
|
+
// eslint-disable-next-line no-debugger
|
|
102
|
+
debugger;
|
|
103
|
+
}
|
|
80
104
|
return jsxRuntime.jsx("div", Object.assign({ className: "Debugger" }, { children: children }));
|
|
81
105
|
};
|
|
82
106
|
|
|
83
|
-
/******************************************************************************
|
|
84
|
-
Copyright (c) Microsoft Corporation.
|
|
85
|
-
|
|
86
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
87
|
-
purpose with or without fee is hereby granted.
|
|
88
|
-
|
|
89
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
90
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
91
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
92
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
93
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
94
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
95
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
96
|
-
***************************************************************************** */
|
|
97
|
-
|
|
98
|
-
function __rest(s, e) {
|
|
99
|
-
var t = {};
|
|
100
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
101
|
-
t[p] = s[p];
|
|
102
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
103
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
104
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
105
|
-
t[p[i]] = s[p[i]];
|
|
106
|
-
}
|
|
107
|
-
return t;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
111
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
112
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
113
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
114
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
115
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
116
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const defaultOptions = {
|
|
121
|
-
mutate: {
|
|
122
|
-
errorPolicy: "all",
|
|
123
|
-
},
|
|
124
|
-
query: {
|
|
125
|
-
errorPolicy: "all",
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
/**
|
|
129
|
-
* This is a wrapper around the MockedProvider that logs errors to the console.
|
|
130
|
-
*/
|
|
131
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
132
|
-
function ApolloMockedProviderWithError(props) {
|
|
133
|
-
const { mocks } = props, otherProps = __rest(props, ["mocks"]);
|
|
134
|
-
const mockLink = new testing.MockLink(mocks);
|
|
135
|
-
const errorLoggingLink = error.onError(({ graphQLErrors, networkError }) => {
|
|
136
|
-
if (graphQLErrors) {
|
|
137
|
-
// eslint-disable-next-line array-callback-return
|
|
138
|
-
graphQLErrors.map(({ message, locations, path }) => {
|
|
139
|
-
if (process.env.VSCODE_INSPECTOR_OPTIONS || process.env.DEBUG) {
|
|
140
|
-
// eslint-disable-next-line no-console
|
|
141
|
-
console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
if (networkError) {
|
|
146
|
-
if (process.env.VSCODE_INSPECTOR_OPTIONS || process.env.DEBUG) {
|
|
147
|
-
// eslint-disable-next-line no-console
|
|
148
|
-
console.log(`[Network error]: ${networkError}`);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
const link = client.ApolloLink.from([errorLoggingLink, mockLink]);
|
|
153
|
-
return (jsxRuntime.jsx(testing.MockedProvider, Object.assign({}, otherProps, { link: link, defaultOptions: Object.assign(Object.assign({}, defaultOptions), { watchQuery: { fetchPolicy: "no-cache" } }) })));
|
|
154
|
-
}
|
|
155
|
-
|
|
156
107
|
/**
|
|
157
108
|
* Do nothing
|
|
158
109
|
*/
|
|
@@ -179,10 +130,26 @@ const mockAssetSortingContext = {
|
|
|
179
130
|
/**
|
|
180
131
|
* Mocks the current user context
|
|
181
132
|
*
|
|
182
|
-
* @param overrides - The overrides to apply to the mock
|
|
183
133
|
* @returns {ICurrentUserContext} - Returns the mocked current user context
|
|
184
134
|
*/
|
|
185
|
-
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
|
+
};
|
|
186
153
|
|
|
187
154
|
const mockEnvironmentContext = {
|
|
188
155
|
auth: {
|
|
@@ -227,19 +194,88 @@ const mockToastContext = {
|
|
|
227
194
|
/**
|
|
228
195
|
* This is a mock for the UserSubscriptionContext.
|
|
229
196
|
*
|
|
230
|
-
* @param features - array of features
|
|
231
|
-
* @param packageType - package type
|
|
232
197
|
* @returns { IUserSubscriptionContext }- mock for the UserSubscriptionContext
|
|
233
198
|
*/
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
packageType,
|
|
240
|
-
};
|
|
199
|
+
const mockUserSubscriptionContext = {
|
|
200
|
+
numberOfDaysWithAccessToHistoricalData: 30,
|
|
201
|
+
numberOfDaysWithAccessToHistoricalInsights: 30,
|
|
202
|
+
features: [],
|
|
203
|
+
packageType: "EXPAND_FLEET_OWNER",
|
|
241
204
|
};
|
|
242
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
|
+
|
|
243
279
|
/**
|
|
244
280
|
* Flushes all promises in the queue.
|
|
245
281
|
* This is useful when testing async code.
|
|
@@ -267,7 +303,7 @@ const flushPromises = (waitTimeInMS = 0) => {
|
|
|
267
303
|
* @returns {Promise<void>} - Returns a promise that resolves after the wait time.
|
|
268
304
|
*/
|
|
269
305
|
const flushPromisesInAct = (waitTimeInMS = 0) => {
|
|
270
|
-
return react
|
|
306
|
+
return react.act(() => {
|
|
271
307
|
return new Promise(resolve => {
|
|
272
308
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
273
309
|
if (global.ORG_setTimeout) {
|
|
@@ -282,133 +318,147 @@ const flushPromisesInAct = (waitTimeInMS = 0) => {
|
|
|
282
318
|
};
|
|
283
319
|
|
|
284
320
|
/**
|
|
285
|
-
* 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:
|
|
286
323
|
* - render
|
|
287
|
-
*
|
|
324
|
+
* For React Hooks:
|
|
325
|
+
* - renderHook
|
|
326
|
+
* For Storybook:
|
|
327
|
+
* - storybook
|
|
288
328
|
*/
|
|
289
|
-
class
|
|
329
|
+
class TrackunitProvidersMockBuilder {
|
|
290
330
|
constructor() {
|
|
291
331
|
this.selectedEnvironmentContext = mockEnvironmentContext;
|
|
292
332
|
this.selectedTokenContext = { token: "fakeToken" };
|
|
293
|
-
this.userSubscriptionPackageType = reactCoreContextsApi.UserSubscriptionPackage.INSIGHT;
|
|
294
|
-
this.features = [];
|
|
295
333
|
this.selectedApolloMocks = [];
|
|
296
334
|
this.selectedRouterProps = {};
|
|
297
335
|
this.selectedToastContext = mockToastContext;
|
|
298
336
|
this.selectedGlobalSelection = { selection: null };
|
|
299
337
|
this.selectedAssetSortingContext = mockAssetSortingContext;
|
|
300
|
-
this.selectedCurrentUserContext = mockCurrentUserContext
|
|
338
|
+
this.selectedCurrentUserContext = mockCurrentUserContext;
|
|
301
339
|
this.selectedAnalyticsContext = mockAnalyticsContext;
|
|
302
340
|
this.selectedOemBrandingContext = mockOemBrandingContext;
|
|
341
|
+
this.selectedUserSubscriptionContext = mockUserSubscriptionContext;
|
|
303
342
|
}
|
|
304
343
|
/**
|
|
305
344
|
* Use this Analytics Context.
|
|
345
|
+
* Defaults to mockAnalyticsContext.
|
|
306
346
|
*
|
|
347
|
+
* @see mockAnalyticsContext
|
|
307
348
|
* @param analyticsContext - The analytics context to use.
|
|
308
|
-
* @returns {
|
|
349
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
309
350
|
*/
|
|
351
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
310
352
|
analytics(analyticsContext) {
|
|
311
|
-
this.selectedAnalyticsContext = analyticsContext;
|
|
353
|
+
this.selectedAnalyticsContext = Object.assign(Object.assign({}, mockAnalyticsContext), analyticsContext);
|
|
312
354
|
return this;
|
|
313
355
|
}
|
|
314
356
|
/**
|
|
315
357
|
* Use this Environment Context.
|
|
358
|
+
* Defaults to mockEnvironmentContext.
|
|
316
359
|
*
|
|
360
|
+
* @see mockEnvironmentContext
|
|
317
361
|
* @param environmentContext - The environment context to use.
|
|
318
|
-
* @returns {
|
|
362
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
319
363
|
*/
|
|
320
364
|
environment(environmentContext) {
|
|
321
|
-
this.selectedEnvironmentContext =
|
|
365
|
+
this.selectedEnvironmentContext = Object.assign(Object.assign({}, mockEnvironmentContext), environmentContext);
|
|
322
366
|
return this;
|
|
323
367
|
}
|
|
324
368
|
/**
|
|
325
|
-
* Use this
|
|
369
|
+
* Use this to pass in a differerent current user.
|
|
370
|
+
* Defaults to mockCurrentUserContext.
|
|
326
371
|
*
|
|
327
|
-
* @
|
|
328
|
-
* @returns {
|
|
372
|
+
* @see mockCurrentUserContext
|
|
373
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
329
374
|
*/
|
|
330
|
-
|
|
331
|
-
this.
|
|
375
|
+
currentUser(currentUserContext) {
|
|
376
|
+
this.selectedCurrentUserContext = Object.assign(Object.assign({}, mockCurrentUserContext), currentUserContext);
|
|
332
377
|
return this;
|
|
333
378
|
}
|
|
334
379
|
/**
|
|
335
|
-
*
|
|
380
|
+
* Use this to pass in a differerent current user subscription.
|
|
381
|
+
* Defaults to mockUserSubscriptionContext.
|
|
336
382
|
*
|
|
337
|
-
* @
|
|
383
|
+
* @see mockUserSubscriptionContext
|
|
384
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
338
385
|
*/
|
|
339
|
-
|
|
340
|
-
|
|
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] });
|
|
341
396
|
return this;
|
|
342
397
|
}
|
|
343
398
|
/**
|
|
344
|
-
*
|
|
399
|
+
* Set global asset sorting context.
|
|
400
|
+
* Defaults to mockAssetSortingContext.
|
|
345
401
|
*
|
|
346
|
-
* @
|
|
347
|
-
* @
|
|
402
|
+
* @see mockAssetSortingContext
|
|
403
|
+
* @param assetSortingContext - Override the default context.
|
|
404
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
348
405
|
*/
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
this.userSubscriptionPackageType = userSubscriptionPackage;
|
|
352
|
-
}
|
|
406
|
+
assetSorting(assetSortingContext) {
|
|
407
|
+
this.selectedAssetSortingContext = Object.assign(Object.assign({}, mockAssetSortingContext), assetSortingContext);
|
|
353
408
|
return this;
|
|
354
409
|
}
|
|
355
410
|
/**
|
|
356
|
-
*
|
|
411
|
+
* Set OEM Branding context.
|
|
412
|
+
* Defaults to mockOemBrandingContext.
|
|
357
413
|
*
|
|
358
|
-
* @
|
|
359
|
-
* @
|
|
414
|
+
* @see mockOemBrandingContext
|
|
415
|
+
* @param oemBrandingContext - Override the default context.
|
|
360
416
|
*/
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
this.features = features.map(feature => {
|
|
364
|
-
return {
|
|
365
|
-
id: feature,
|
|
366
|
-
name: feature,
|
|
367
|
-
};
|
|
368
|
-
});
|
|
369
|
-
}
|
|
417
|
+
oemBrandingContext(oemBrandingContext) {
|
|
418
|
+
this.selectedOemBrandingContext = Object.assign(Object.assign({}, mockOemBrandingContext), oemBrandingContext);
|
|
370
419
|
return this;
|
|
371
420
|
}
|
|
372
421
|
/**
|
|
373
|
-
* Use this
|
|
422
|
+
* Use this ToastContext with the given mocks.
|
|
423
|
+
* Defaults to mockToastContext.
|
|
374
424
|
*
|
|
375
|
-
* @
|
|
376
|
-
* @
|
|
425
|
+
* @see mockToastContext
|
|
426
|
+
* @param toastContext - Override the default toast context.
|
|
377
427
|
*/
|
|
378
|
-
|
|
379
|
-
this.
|
|
428
|
+
toast(toastContext) {
|
|
429
|
+
this.selectedToastContext = Object.assign(Object.assign({}, mockToastContext), toastContext);
|
|
380
430
|
return this;
|
|
381
431
|
}
|
|
382
432
|
/**
|
|
383
433
|
* Use this global selection.
|
|
434
|
+
* Defaults to null.
|
|
384
435
|
*
|
|
385
436
|
* @param globalSelection - The global selection to use.
|
|
386
|
-
* @returns {
|
|
437
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
387
438
|
*/
|
|
388
439
|
globalSelection(globalSelection) {
|
|
389
440
|
this.selectedGlobalSelection = { selection: globalSelection };
|
|
390
441
|
return this;
|
|
391
442
|
}
|
|
392
443
|
/**
|
|
393
|
-
*
|
|
444
|
+
* Use this token.
|
|
394
445
|
*
|
|
395
|
-
* @param
|
|
396
|
-
* @returns {
|
|
446
|
+
* @param token - The token to use.
|
|
447
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
397
448
|
*/
|
|
398
|
-
|
|
399
|
-
this.
|
|
449
|
+
token(token) {
|
|
450
|
+
this.selectedTokenContext = { token };
|
|
400
451
|
return this;
|
|
401
452
|
}
|
|
402
453
|
/**
|
|
403
|
-
*
|
|
454
|
+
* Use this Router Props with the given mocks.
|
|
455
|
+
*
|
|
456
|
+
* @param routerProps - The router props to use.
|
|
457
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
404
458
|
*/
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
// This ensures correct act loading when using hooks
|
|
409
|
-
const hookRenderer = yield Promise.resolve().then(function () { return require('./HookRenderer.cjs'); });
|
|
410
|
-
return hookRenderer.reactHooksRenderHook(callback, children => this.getMockedCompositionRoot(parentElement ? parentElement(children) : children));
|
|
411
|
-
});
|
|
459
|
+
routerProps(routerProps) {
|
|
460
|
+
this.selectedRouterProps = routerProps;
|
|
461
|
+
return this;
|
|
412
462
|
}
|
|
413
463
|
/**
|
|
414
464
|
* Use this Manager Apollo Context Provider with the given mocks.
|
|
@@ -420,70 +470,70 @@ class MockContextProviderBuilder {
|
|
|
420
470
|
return this;
|
|
421
471
|
}
|
|
422
472
|
/**
|
|
423
|
-
*
|
|
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.
|
|
424
475
|
*
|
|
425
|
-
* @
|
|
476
|
+
* @returns {boolean} true or throws error if any invalid mocks
|
|
426
477
|
*/
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
return this;
|
|
478
|
+
validateSuppliedMocks() {
|
|
479
|
+
return true;
|
|
430
480
|
}
|
|
431
481
|
/**
|
|
432
|
-
*
|
|
482
|
+
* Make sure this represent the same structure as the main index.tsx does.
|
|
433
483
|
*
|
|
434
|
-
* @param
|
|
484
|
+
* @param testChildren - the child element being tested.
|
|
485
|
+
* @param addTestRootContainer - if you want to add a root container to the test.
|
|
435
486
|
*/
|
|
436
|
-
|
|
437
|
-
this.selectedOemBrandingContext
|
|
438
|
-
|
|
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
|
+
});
|
|
439
500
|
}
|
|
440
501
|
/**
|
|
441
|
-
* This will use
|
|
502
|
+
* This will use react-testing-library.render the child in the correct mocked hierarchy of context providers.
|
|
442
503
|
*
|
|
504
|
+
* @see https://testing-library.com/docs/react-testing-library/api#render
|
|
443
505
|
* @param child - the child element being tested.
|
|
444
506
|
*/
|
|
445
507
|
render(child) {
|
|
446
508
|
return __awaiter(this, void 0, void 0, function* () {
|
|
447
509
|
this.validateSuppliedMocks();
|
|
448
510
|
let mountedcomponent;
|
|
449
|
-
yield react
|
|
450
|
-
mountedcomponent = react
|
|
511
|
+
yield react.act(() => __awaiter(this, void 0, void 0, function* () {
|
|
512
|
+
mountedcomponent = react.render(child, {
|
|
451
513
|
wrapper: ({ children }) => this.getMockedCompositionRoot(children),
|
|
452
514
|
});
|
|
453
515
|
yield flushPromises();
|
|
454
516
|
}));
|
|
455
|
-
yield react
|
|
517
|
+
yield react.act(() => __awaiter(this, void 0, void 0, function* () {
|
|
456
518
|
yield flushPromises();
|
|
457
519
|
}));
|
|
458
|
-
yield react
|
|
520
|
+
yield react.act(() => __awaiter(this, void 0, void 0, function* () {
|
|
459
521
|
yield flushPromises();
|
|
460
522
|
}));
|
|
461
523
|
return mountedcomponent;
|
|
462
524
|
});
|
|
463
525
|
}
|
|
464
526
|
/**
|
|
465
|
-
*
|
|
466
|
-
* Note: This function is overriden in builders extending this one.
|
|
467
|
-
*
|
|
468
|
-
* @returns {boolean} true or throws error if any invalid mocks
|
|
469
|
-
*/
|
|
470
|
-
validateSuppliedMocks() {
|
|
471
|
-
return true;
|
|
472
|
-
}
|
|
473
|
-
/**
|
|
474
|
-
* Make sure this represent the same structure as the main index.tsx does.
|
|
475
|
-
*
|
|
476
|
-
* @param testChildren - the child element being tested.
|
|
477
|
-
* @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.
|
|
478
528
|
*/
|
|
479
|
-
|
|
480
|
-
return
|
|
529
|
+
storybook(child) {
|
|
530
|
+
return this.getMockedCompositionRoot(child, false);
|
|
481
531
|
}
|
|
482
532
|
}
|
|
483
533
|
/**
|
|
484
|
-
*
|
|
534
|
+
* This is the default mock builder for the TrackunitProviders.
|
|
485
535
|
*/
|
|
486
|
-
const trackunitProviders = () => new
|
|
536
|
+
const trackunitProviders = () => new TrackunitProvidersMockBuilder();
|
|
487
537
|
const TestRoot = tailwindStyledComponents.tw.div `
|
|
488
538
|
--tw-scale-x: 0.99;
|
|
489
539
|
--tw-scale-y: 0.99;
|
|
@@ -572,15 +622,19 @@ const validateIrisApp = (irisApp) => __awaiter(void 0, void 0, void 0, function*
|
|
|
572
622
|
});
|
|
573
623
|
|
|
574
624
|
exports.Debugger = Debugger;
|
|
575
|
-
exports.
|
|
625
|
+
exports.TrackunitProvidersMockBuilder = TrackunitProvidersMockBuilder;
|
|
576
626
|
exports.__awaiter = __awaiter;
|
|
577
627
|
exports.doNothing = doNothing;
|
|
578
628
|
exports.flushPromises = flushPromises;
|
|
579
629
|
exports.flushPromisesInAct = flushPromisesInAct;
|
|
580
630
|
exports.mockAnalyticsContext = mockAnalyticsContext;
|
|
631
|
+
exports.mockAssetSortingContext = mockAssetSortingContext;
|
|
581
632
|
exports.mockCurrentUserContext = mockCurrentUserContext;
|
|
582
633
|
exports.mockEnvironmentContext = mockEnvironmentContext;
|
|
634
|
+
exports.mockOemBrandingContext = mockOemBrandingContext;
|
|
635
|
+
exports.mockToastContext = mockToastContext;
|
|
636
|
+
exports.mockUserSubscriptionContext = mockUserSubscriptionContext;
|
|
583
637
|
exports.queryFor = queryFor;
|
|
584
638
|
exports.trackunitProviders = trackunitProviders;
|
|
585
|
-
exports.
|
|
639
|
+
exports.useDebugger = useDebugger;
|
|
586
640
|
exports.validateIrisApp = validateIrisApp;
|