@trackunit/react-core-contexts-test 0.1.210 → 0.1.211
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.js +1 -1
- package/HookRenderer.esm.js +1 -1
- package/index.cjs.js +1 -1
- package/index.cjs2.js +29 -20
- package/index.esm.js +1 -1
- package/index.esm2.js +32 -23
- package/package.json +2 -2
package/HookRenderer.cjs.js
CHANGED
|
@@ -12,8 +12,8 @@ require('@apollo/client/testing');
|
|
|
12
12
|
require('@trackunit/react-core-contexts-api');
|
|
13
13
|
require('@apollo/client/react');
|
|
14
14
|
require('@tanstack/react-router');
|
|
15
|
-
require('react');
|
|
16
15
|
require('@trackunit/shared-utils');
|
|
16
|
+
require('react');
|
|
17
17
|
require('graphql');
|
|
18
18
|
|
|
19
19
|
/**
|
package/HookRenderer.esm.js
CHANGED
package/index.cjs.js
CHANGED
|
@@ -13,8 +13,8 @@ require('@apollo/client/testing');
|
|
|
13
13
|
require('@trackunit/react-core-contexts-api');
|
|
14
14
|
require('@apollo/client/react');
|
|
15
15
|
require('@tanstack/react-router');
|
|
16
|
-
require('react');
|
|
17
16
|
require('@trackunit/shared-utils');
|
|
17
|
+
require('react');
|
|
18
18
|
require('graphql');
|
|
19
19
|
|
|
20
20
|
|
package/index.cjs2.js
CHANGED
|
@@ -10,8 +10,8 @@ var testing = require('@apollo/client/testing');
|
|
|
10
10
|
var reactCoreContextsApi = require('@trackunit/react-core-contexts-api');
|
|
11
11
|
var react = require('@apollo/client/react');
|
|
12
12
|
var reactRouter = require('@tanstack/react-router');
|
|
13
|
-
var React = require('react');
|
|
14
13
|
var sharedUtils = require('@trackunit/shared-utils');
|
|
14
|
+
var React = require('react');
|
|
15
15
|
var graphql = require('graphql');
|
|
16
16
|
|
|
17
17
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -231,7 +231,7 @@ const mockNavigationContext = {
|
|
|
231
231
|
|
|
232
232
|
const mockOemBrandingContext = {
|
|
233
233
|
getAllBrandingDetails: doNothing,
|
|
234
|
-
getOemBranding:
|
|
234
|
+
getOemBranding: () => __awaiter(void 0, void 0, void 0, function* () { return null; }),
|
|
235
235
|
getOemImage: doNothing,
|
|
236
236
|
};
|
|
237
237
|
|
|
@@ -268,7 +268,10 @@ const buildFlatRouteMap = (routes) => {
|
|
|
268
268
|
*/
|
|
269
269
|
const RootRouteDebugger = () => {
|
|
270
270
|
// const matches = useMatches();
|
|
271
|
-
// console.log(
|
|
271
|
+
// console.log(
|
|
272
|
+
// "matches",
|
|
273
|
+
// matches.map(match => match.routeId)
|
|
274
|
+
// );
|
|
272
275
|
return jsxRuntime.jsx(reactRouter.Outlet, {});
|
|
273
276
|
};
|
|
274
277
|
/**
|
|
@@ -294,14 +297,13 @@ const TestRenderChildren = ({ addTestRootContainer, children }) => {
|
|
|
294
297
|
* @returns React.ReactElement
|
|
295
298
|
*/
|
|
296
299
|
const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute, children, }) => {
|
|
300
|
+
var _a, _b;
|
|
297
301
|
const client = react.useApolloClient();
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
});
|
|
304
|
-
}, [selectedRouterProps]);
|
|
302
|
+
// The current version of createMemoryHistory seem to have issues when NOT ending on / so adding a # will not effect what url is rendered but it seems to work
|
|
303
|
+
const memoryHistory = reactRouter.createMemoryHistory({
|
|
304
|
+
initialEntries: (_b = (_a = selectedRouterProps === null || selectedRouterProps === void 0 ? void 0 : selectedRouterProps.initialEntries) === null || _a === void 0 ? void 0 : _a.map(entry => entry.path + "#")) !== null && _b !== void 0 ? _b : ["/#"],
|
|
305
|
+
initialIndex: 0,
|
|
306
|
+
});
|
|
305
307
|
const getChildren = React.useCallback(() => children, [children]);
|
|
306
308
|
const router = React.useMemo(() => {
|
|
307
309
|
var _a, _b;
|
|
@@ -310,20 +312,28 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
|
|
|
310
312
|
const childRoute = reactRouter.createRoute({
|
|
311
313
|
path: "/",
|
|
312
314
|
getParentRoute: () => rootRoute,
|
|
313
|
-
component: () =>
|
|
315
|
+
component: () => {
|
|
316
|
+
return jsxRuntime.jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainer, children: getChildren() });
|
|
317
|
+
},
|
|
314
318
|
});
|
|
315
319
|
rootRoute.addChildren([childRoute]);
|
|
316
320
|
}
|
|
317
321
|
else {
|
|
318
322
|
const pathsToRoute = buildFlatRouteMap([rootRoute]);
|
|
323
|
+
sharedUtils.objectValues(pathsToRoute).forEach(route => {
|
|
324
|
+
route.options.component = RootRouteDebugger;
|
|
325
|
+
route.lazyFn = undefined;
|
|
326
|
+
});
|
|
319
327
|
if (pathsToRoute.__root__) {
|
|
320
|
-
pathsToRoute.__root__.options.component =
|
|
328
|
+
pathsToRoute.__root__.options.component = RootRouteDebugger;
|
|
329
|
+
pathsToRoute.__root__.options.beforeLoad = () => { };
|
|
330
|
+
pathsToRoute.__root__.lazyFn = undefined;
|
|
321
331
|
}
|
|
322
332
|
if (pathsToRoute["/"]) {
|
|
323
333
|
// This ensures / is not redirecting to default home route
|
|
324
334
|
pathsToRoute["/"].options.beforeLoad = () => { };
|
|
325
335
|
}
|
|
326
|
-
if (((_a = selectedRouterProps === null || selectedRouterProps === void 0 ? void 0 : selectedRouterProps.initialEntries) === null || _a === void 0 ? void 0 : _a.length) || 0 > 0) {
|
|
336
|
+
if ((((_a = selectedRouterProps === null || selectedRouterProps === void 0 ? void 0 : selectedRouterProps.initialEntries) === null || _a === void 0 ? void 0 : _a.length) || 0) > 0) {
|
|
327
337
|
(_b = selectedRouterProps === null || selectedRouterProps === void 0 ? void 0 : selectedRouterProps.initialEntries) === null || _b === void 0 ? void 0 : _b.forEach(entry => {
|
|
328
338
|
const route = pathsToRoute[entry.route];
|
|
329
339
|
if (route) {
|
|
@@ -346,11 +356,7 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
|
|
|
346
356
|
path: "/",
|
|
347
357
|
getParentRoute: () => rootRoute,
|
|
348
358
|
component: () => (jsxRuntime.jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainer, children: getChildren() })),
|
|
349
|
-
})
|
|
350
|
-
return reactRouter.createLazyRoute("/")({
|
|
351
|
-
component: () => (jsxRuntime.jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainer, children: getChildren() })),
|
|
352
|
-
});
|
|
353
|
-
}));
|
|
359
|
+
});
|
|
354
360
|
rootRoute.addChildren([childRoute]);
|
|
355
361
|
}
|
|
356
362
|
}
|
|
@@ -371,8 +377,11 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
|
|
|
371
377
|
},
|
|
372
378
|
});
|
|
373
379
|
}, [rootRoute]);
|
|
374
|
-
const context = React.useMemo(() => (Object.assign({ hasAccessTo: () => __awaiter(void 0, void 0, void 0, function* () { return true; }), isAuthenticated: true, client, defaultUserRoute: "/" }, ((selectedRouterProps === null || selectedRouterProps === void 0 ? void 0 : selectedRouterProps.context) || {}))), [client]);
|
|
375
|
-
|
|
380
|
+
const context = React.useMemo(() => (Object.assign({ hasAccessTo: () => __awaiter(void 0, void 0, void 0, function* () { return true; }), isAuthenticated: true, client, defaultUserRoute: "/" }, ((selectedRouterProps === null || selectedRouterProps === void 0 ? void 0 : selectedRouterProps.context) || {}))), [client, selectedRouterProps === null || selectedRouterProps === void 0 ? void 0 : selectedRouterProps.context]);
|
|
381
|
+
const ErrorComponent = ({ error, info }) => {
|
|
382
|
+
return jsxRuntime.jsxs(jsxRuntime.Fragment, { children: ["UNCAUGHT ERROR IN TEST: ", error === null || error === void 0 ? void 0 : error.message] });
|
|
383
|
+
};
|
|
384
|
+
return jsxRuntime.jsx(reactRouter.RouterProvider, { context: context, defaultErrorComponent: ErrorComponent, router: router });
|
|
376
385
|
};
|
|
377
386
|
|
|
378
387
|
/**
|
package/index.esm.js
CHANGED
package/index.esm2.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { act, render } from '@testing-library/react';
|
|
3
3
|
import { CurrentUserProvider, AnalyticsContext, UserSubscriptionProvider, OemBrandingContextProvider, TokenProvider, ToastProvider, ConfirmationDialogProvider, FilterBarProvider, AssetSortingProvider, NavigationContextProvider, CurrentUserPreferenceProvider, EnvironmentContextProvider } from '@trackunit/react-core-hooks';
|
|
4
4
|
import omit from 'lodash/omit';
|
|
@@ -7,9 +7,9 @@ import { onError } from '@apollo/client/link/error';
|
|
|
7
7
|
import { MockLink, MockedProvider } from '@apollo/client/testing';
|
|
8
8
|
import { AssetSortByProperty, SortOrder } from '@trackunit/react-core-contexts-api';
|
|
9
9
|
import { useApolloClient } from '@apollo/client/react';
|
|
10
|
-
import { createMemoryHistory, createRootRoute, createRoute,
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
10
|
+
import { createMemoryHistory, createRootRoute, createRoute, createRouter, RouterProvider, Outlet } from '@tanstack/react-router';
|
|
11
|
+
import { objectValues, objectKeys } from '@trackunit/shared-utils';
|
|
12
|
+
import React, { useCallback, useMemo, useRef, useEffect } from 'react';
|
|
13
13
|
import { GraphQLError } from 'graphql';
|
|
14
14
|
|
|
15
15
|
/******************************************************************************
|
|
@@ -224,7 +224,7 @@ const mockNavigationContext = {
|
|
|
224
224
|
|
|
225
225
|
const mockOemBrandingContext = {
|
|
226
226
|
getAllBrandingDetails: doNothing,
|
|
227
|
-
getOemBranding:
|
|
227
|
+
getOemBranding: () => __awaiter(void 0, void 0, void 0, function* () { return null; }),
|
|
228
228
|
getOemImage: doNothing,
|
|
229
229
|
};
|
|
230
230
|
|
|
@@ -261,7 +261,10 @@ const buildFlatRouteMap = (routes) => {
|
|
|
261
261
|
*/
|
|
262
262
|
const RootRouteDebugger = () => {
|
|
263
263
|
// const matches = useMatches();
|
|
264
|
-
// console.log(
|
|
264
|
+
// console.log(
|
|
265
|
+
// "matches",
|
|
266
|
+
// matches.map(match => match.routeId)
|
|
267
|
+
// );
|
|
265
268
|
return jsx(Outlet, {});
|
|
266
269
|
};
|
|
267
270
|
/**
|
|
@@ -287,14 +290,13 @@ const TestRenderChildren = ({ addTestRootContainer, children }) => {
|
|
|
287
290
|
* @returns React.ReactElement
|
|
288
291
|
*/
|
|
289
292
|
const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute, children, }) => {
|
|
293
|
+
var _a, _b;
|
|
290
294
|
const client = useApolloClient();
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
});
|
|
297
|
-
}, [selectedRouterProps]);
|
|
295
|
+
// The current version of createMemoryHistory seem to have issues when NOT ending on / so adding a # will not effect what url is rendered but it seems to work
|
|
296
|
+
const memoryHistory = createMemoryHistory({
|
|
297
|
+
initialEntries: (_b = (_a = selectedRouterProps === null || selectedRouterProps === void 0 ? void 0 : selectedRouterProps.initialEntries) === null || _a === void 0 ? void 0 : _a.map(entry => entry.path + "#")) !== null && _b !== void 0 ? _b : ["/#"],
|
|
298
|
+
initialIndex: 0,
|
|
299
|
+
});
|
|
298
300
|
const getChildren = useCallback(() => children, [children]);
|
|
299
301
|
const router = useMemo(() => {
|
|
300
302
|
var _a, _b;
|
|
@@ -303,20 +305,28 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
|
|
|
303
305
|
const childRoute = createRoute({
|
|
304
306
|
path: "/",
|
|
305
307
|
getParentRoute: () => rootRoute,
|
|
306
|
-
component: () =>
|
|
308
|
+
component: () => {
|
|
309
|
+
return jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainer, children: getChildren() });
|
|
310
|
+
},
|
|
307
311
|
});
|
|
308
312
|
rootRoute.addChildren([childRoute]);
|
|
309
313
|
}
|
|
310
314
|
else {
|
|
311
315
|
const pathsToRoute = buildFlatRouteMap([rootRoute]);
|
|
316
|
+
objectValues(pathsToRoute).forEach(route => {
|
|
317
|
+
route.options.component = RootRouteDebugger;
|
|
318
|
+
route.lazyFn = undefined;
|
|
319
|
+
});
|
|
312
320
|
if (pathsToRoute.__root__) {
|
|
313
|
-
pathsToRoute.__root__.options.component =
|
|
321
|
+
pathsToRoute.__root__.options.component = RootRouteDebugger;
|
|
322
|
+
pathsToRoute.__root__.options.beforeLoad = () => { };
|
|
323
|
+
pathsToRoute.__root__.lazyFn = undefined;
|
|
314
324
|
}
|
|
315
325
|
if (pathsToRoute["/"]) {
|
|
316
326
|
// This ensures / is not redirecting to default home route
|
|
317
327
|
pathsToRoute["/"].options.beforeLoad = () => { };
|
|
318
328
|
}
|
|
319
|
-
if (((_a = selectedRouterProps === null || selectedRouterProps === void 0 ? void 0 : selectedRouterProps.initialEntries) === null || _a === void 0 ? void 0 : _a.length) || 0 > 0) {
|
|
329
|
+
if ((((_a = selectedRouterProps === null || selectedRouterProps === void 0 ? void 0 : selectedRouterProps.initialEntries) === null || _a === void 0 ? void 0 : _a.length) || 0) > 0) {
|
|
320
330
|
(_b = selectedRouterProps === null || selectedRouterProps === void 0 ? void 0 : selectedRouterProps.initialEntries) === null || _b === void 0 ? void 0 : _b.forEach(entry => {
|
|
321
331
|
const route = pathsToRoute[entry.route];
|
|
322
332
|
if (route) {
|
|
@@ -339,11 +349,7 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
|
|
|
339
349
|
path: "/",
|
|
340
350
|
getParentRoute: () => rootRoute,
|
|
341
351
|
component: () => (jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainer, children: getChildren() })),
|
|
342
|
-
})
|
|
343
|
-
return createLazyRoute("/")({
|
|
344
|
-
component: () => (jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainer, children: getChildren() })),
|
|
345
|
-
});
|
|
346
|
-
}));
|
|
352
|
+
});
|
|
347
353
|
rootRoute.addChildren([childRoute]);
|
|
348
354
|
}
|
|
349
355
|
}
|
|
@@ -364,8 +370,11 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
|
|
|
364
370
|
},
|
|
365
371
|
});
|
|
366
372
|
}, [rootRoute]);
|
|
367
|
-
const context = useMemo(() => (Object.assign({ hasAccessTo: () => __awaiter(void 0, void 0, void 0, function* () { return true; }), isAuthenticated: true, client, defaultUserRoute: "/" }, ((selectedRouterProps === null || selectedRouterProps === void 0 ? void 0 : selectedRouterProps.context) || {}))), [client]);
|
|
368
|
-
|
|
373
|
+
const context = useMemo(() => (Object.assign({ hasAccessTo: () => __awaiter(void 0, void 0, void 0, function* () { return true; }), isAuthenticated: true, client, defaultUserRoute: "/" }, ((selectedRouterProps === null || selectedRouterProps === void 0 ? void 0 : selectedRouterProps.context) || {}))), [client, selectedRouterProps === null || selectedRouterProps === void 0 ? void 0 : selectedRouterProps.context]);
|
|
374
|
+
const ErrorComponent = ({ error, info }) => {
|
|
375
|
+
return jsxs(Fragment, { children: ["UNCAUGHT ERROR IN TEST: ", error === null || error === void 0 ? void 0 : error.message] });
|
|
376
|
+
};
|
|
377
|
+
return jsx(RouterProvider, { context: context, defaultErrorComponent: ErrorComponent, router: router });
|
|
369
378
|
};
|
|
370
379
|
|
|
371
380
|
/**
|
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.211",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@trackunit/react-core-hooks": "*",
|
|
15
15
|
"lodash": "4.17.21",
|
|
16
16
|
"graphql": "^15.8.0",
|
|
17
|
-
"@tanstack/react-router": "1.
|
|
17
|
+
"@tanstack/react-router": "1.31.6",
|
|
18
18
|
"@trackunit/shared-utils": "*"
|
|
19
19
|
},
|
|
20
20
|
"module": "./index.esm.js",
|