@trackunit/react-core-contexts-test 1.0.7 → 1.0.9

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.
@@ -25,14 +25,11 @@ require('graphql');
25
25
  * @returns { Promise<RenderHookResult> } The rendered hook.
26
26
  */
27
27
  const reactHooksRenderHook = async (callback, getMockedCompositionRoot) => {
28
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
28
  const wrapper = ({ children }) => {
30
- // eslint-disable-next-line react/jsx-no-useless-fragment
31
29
  return getMockedCompositionRoot(children);
32
30
  };
33
31
  let renderedHook;
34
32
  // This is added here to make storybook work and to ensure the right act is loaded for hooks.
35
- // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
36
33
  await react.act(async () => {
37
34
  renderedHook = await react.renderHook(callback, { wrapper });
38
35
  });
@@ -23,14 +23,11 @@ import 'graphql';
23
23
  * @returns { Promise<RenderHookResult> } The rendered hook.
24
24
  */
25
25
  const reactHooksRenderHook = async (callback, getMockedCompositionRoot) => {
26
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
26
  const wrapper = ({ children }) => {
28
- // eslint-disable-next-line react/jsx-no-useless-fragment
29
27
  return getMockedCompositionRoot(children);
30
28
  };
31
29
  let renderedHook;
32
30
  // This is added here to make storybook work and to ensure the right act is loaded for hooks.
33
- // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
34
31
  await act(async () => {
35
32
  renderedHook = await renderHook(callback, { wrapper });
36
33
  });
package/index.cjs.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
- var react$1 = require('@testing-library/react');
4
+ var react$2 = require('@testing-library/react');
5
5
  var reactCoreHooks = require('@trackunit/react-core-hooks');
6
6
  var omit = require('lodash/omit');
7
7
  var client = require('@apollo/client');
@@ -10,8 +10,8 @@ var error = require('@apollo/client/link/error');
10
10
  var testing = require('@apollo/client/testing');
11
11
  var reactCoreContextsApi = require('@trackunit/react-core-contexts-api');
12
12
  var sharedUtils = require('@trackunit/shared-utils');
13
- var React = require('react');
14
- var react = require('@apollo/client/react');
13
+ var react = require('react');
14
+ var react$1 = require('@apollo/client/react');
15
15
  var reactRouter = require('@tanstack/react-router');
16
16
  var graphql = require('graphql');
17
17
 
@@ -34,7 +34,6 @@ function ApolloMockedProviderWithError(props) {
34
34
  const mockLink = new testing.MockLink(mocks, false, { showWarnings: isDebugging });
35
35
  const errorLoggingLink = error.onError(({ graphQLErrors, networkError }) => {
36
36
  if (graphQLErrors) {
37
- // eslint-disable-next-line array-callback-return
38
37
  graphQLErrors.map(({ message, locations, path }) => {
39
38
  if (isDebugging) {
40
39
  // eslint-disable-next-line no-console
@@ -223,13 +222,13 @@ const mockUserSubscriptionContext = {
223
222
  packageType: "EXPAND_FLEET_OWNER",
224
223
  };
225
224
 
226
- const RerenderContext = React.createContext({ rerenderCounter: 0, setRerenderCounter: (value) => { } });
225
+ const RerenderContext = react.createContext({ rerenderCounter: 0, setRerenderCounter: (value) => { } });
227
226
  /**
228
227
  * This provider is used to force re-renders in the test environment, since tanstack router does not support re-render.
229
228
  */
230
229
  const RerenderProvider = ({ children, counter }) => {
231
- const [rerenderCounter, setRerenderCounter] = React.useState(0);
232
- React.useEffect(() => {
230
+ const [rerenderCounter, setRerenderCounter] = react.useState(0);
231
+ react.useEffect(() => {
233
232
  if (counter && rerenderCounter !== counter && rerenderCounter !== 0) {
234
233
  setRerenderCounter(counter);
235
234
  }
@@ -240,7 +239,7 @@ const RerenderProvider = ({ children, counter }) => {
240
239
  * This hook is used to get the rerender counter.
241
240
  */
242
241
  const useRerenderCounter = () => {
243
- return React.useContext(RerenderContext);
242
+ return react.useContext(RerenderContext);
244
243
  };
245
244
 
246
245
  /**
@@ -248,8 +247,8 @@ const useRerenderCounter = () => {
248
247
  */
249
248
  const RerenderComponent = ({ children }) => {
250
249
  const { rerenderCounter } = useRerenderCounter();
251
- return (jsxRuntime.jsx("div", { "data-rerender-counter": `rerender-${rerenderCounter}`, children: React.Children.map(children, child => React.isValidElement(child)
252
- ? React.createElement(child.type, {
250
+ return (jsxRuntime.jsx("div", { "data-rerender-counter": `rerender-${rerenderCounter}`, children: react.Children.map(children, child => react.isValidElement(child)
251
+ ? react.createElement(child.type, {
253
252
  ...child.props,
254
253
  key: child.key,
255
254
  "data-rerender-counter": rerenderCounter,
@@ -298,17 +297,17 @@ const TestRenderChildren = ({ addTestRootContainer, children }) => {
298
297
  * @param selectedRouterProps selected router props
299
298
  * @param rootRoute root route
300
299
  * @param children children to be wrapped
301
- * @returns {React.ReactElement} children component wrapped in a test root container
300
+ * @returns {ReactElement} children component wrapped in a test root container
302
301
  */
303
302
  const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute, children, }) => {
304
- const client = react.useApolloClient();
303
+ const client = react$1.useApolloClient();
305
304
  // 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
306
- const memoryHistory = React.useRef(reactRouter.createMemoryHistory({
305
+ const memoryHistory = react.useRef(reactRouter.createMemoryHistory({
307
306
  initialEntries: selectedRouterProps?.initialEntries?.map(entry => entry.path + "#") ?? ["/#"],
308
307
  initialIndex: 0,
309
308
  }));
310
- const getChildren = React.useCallback(() => children, [children]);
311
- const router = React.useMemo(() => {
309
+ const getChildren = react.useCallback(() => children, [children]);
310
+ const router = react.useMemo(() => {
312
311
  let localRootRoute = rootRoute;
313
312
  if (!localRootRoute) {
314
313
  const route = reactRouter.createRootRoute({ component: RootRouteDebugger });
@@ -391,7 +390,7 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
391
390
  // This causes unexpected state updates in Tanstack router which make the test fail
392
391
  // eslint-disable-next-line react-hooks/exhaustive-deps
393
392
  }, [rootRoute]);
394
- const context = React.useMemo(() => ({
393
+ const context = react.useMemo(() => ({
395
394
  hasAccessTo: async () => true,
396
395
  isAuthenticated: true,
397
396
  client,
@@ -431,7 +430,7 @@ const flushPromises = (waitTimeInMS = 0) => {
431
430
  * @returns {Promise<void>} - Returns a promise that resolves after the wait time.
432
431
  */
433
432
  const flushPromisesInAct = (waitTimeInMS = 0) => {
434
- return react$1.act(() => {
433
+ return react$2.act(() => {
435
434
  return new Promise(resolve => {
436
435
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
437
436
  if (global.ORG_setTimeout) {
@@ -899,16 +898,16 @@ class TrackunitProvidersMockBuilder {
899
898
  async render(child) {
900
899
  this.validateSuppliedMocks();
901
900
  let mountedcomponent;
902
- await react$1.act(async () => {
903
- mountedcomponent = react$1.render(child, {
901
+ await react$2.act(async () => {
902
+ mountedcomponent = react$2.render(child, {
904
903
  wrapper: ({ children }) => this.getMockedCompositionRootWithRouter(children),
905
904
  });
906
905
  await flushPromises();
907
906
  });
908
- await react$1.act(async () => {
907
+ await react$2.act(async () => {
909
908
  await flushPromises();
910
909
  });
911
- await react$1.act(async () => {
910
+ await react$2.act(async () => {
912
911
  await flushPromises();
913
912
  });
914
913
  // eslint-disable-next-line local-rules/no-typescript-assertion
@@ -932,7 +931,7 @@ const trackunitProviders = () => new TrackunitProvidersMockBuilder();
932
931
  * @returns {boolean} Returns true if it is the first render, false otherwise.
933
932
  */
934
933
  const useIsFirstRender = () => {
935
- const renderRef = React.useRef(true);
934
+ const renderRef = react.useRef(true);
936
935
  if (renderRef.current === true) {
937
936
  renderRef.current = false;
938
937
  return true;
@@ -952,8 +951,8 @@ const useIsFirstRender = () => {
952
951
  * useDebugger(propsToWatch);
953
952
  */
954
953
  const useDebugger = (propsToWatch, id) => {
955
- const prevPropsRef = React.useRef(propsToWatch);
956
- const uniqueId = React.useMemo(() => {
954
+ const prevPropsRef = react.useRef(propsToWatch);
955
+ const uniqueId = react.useMemo(() => {
957
956
  // eslint-disable-next-line local-rules/no-typescript-assertion
958
957
  let stackId = id || (propsToWatch && propsToWatch.id);
959
958
  const stack = new Error().stack;
@@ -972,8 +971,7 @@ const useDebugger = (propsToWatch, id) => {
972
971
  const isFirstRender = useIsFirstRender();
973
972
  // eslint-disable-next-line no-console
974
973
  console.log(isFirstRender ? "First-render" : "Re-render", uniqueId, window.location.pathname);
975
- React.useEffect(() => {
976
- // eslint-disable-next-line local-rules/prefer-custom-object-entries
974
+ react.useEffect(() => {
977
975
  const changedProps = Object.entries(propsToWatch || {}).reduce((result, [key, value]) => {
978
976
  if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
979
977
  result[key + ""] = [prevPropsRef.current[key], value];
@@ -981,7 +979,6 @@ const useDebugger = (propsToWatch, id) => {
981
979
  return result;
982
980
  }, {});
983
981
  if (sharedUtils.objectKeys(changedProps).length > 0) {
984
- // eslint-disable-next-line no-console
985
982
  sharedUtils.objectKeys(changedProps).forEach(changedProp => {
986
983
  // eslint-disable-next-line no-console
987
984
  console.log(`${uniqueId} changed property: ${changedProp}`);
@@ -1026,7 +1023,7 @@ const Debugger = ({ id, logPropsChanges, stop, children, }) => {
1026
1023
  new Error().stack?.split("\n")[2]?.trim() ||
1027
1024
  "unknown-id";
1028
1025
  useDebugger(logPropsChanges || {}, id);
1029
- React.useEffect(() => {
1026
+ react.useEffect(() => {
1030
1027
  // eslint-disable-next-line no-console
1031
1028
  console.log(`${uniqueId} Debugger is mounting`);
1032
1029
  return () => {
package/index.esm.js CHANGED
@@ -8,7 +8,7 @@ import { onError } from '@apollo/client/link/error';
8
8
  import { MockLink, MockedProvider } from '@apollo/client/testing';
9
9
  import { AssetSortByProperty, SortOrder } from '@trackunit/react-core-contexts-api';
10
10
  import { doNothing as doNothing$1, objectValues, objectKeys } from '@trackunit/shared-utils';
11
- import React, { createContext, useState, useEffect, useContext, useRef, useCallback, useMemo } from 'react';
11
+ import { createContext, useState, useEffect, useContext, Children, isValidElement, createElement, useRef, useCallback, useMemo } from 'react';
12
12
  import { useApolloClient } from '@apollo/client/react';
13
13
  import { createMemoryHistory, createRootRoute, createRoute, createRouter, RouterProvider, Outlet } from '@tanstack/react-router';
14
14
  import { GraphQLError } from 'graphql';
@@ -32,7 +32,6 @@ function ApolloMockedProviderWithError(props) {
32
32
  const mockLink = new MockLink(mocks, false, { showWarnings: isDebugging });
33
33
  const errorLoggingLink = onError(({ graphQLErrors, networkError }) => {
34
34
  if (graphQLErrors) {
35
- // eslint-disable-next-line array-callback-return
36
35
  graphQLErrors.map(({ message, locations, path }) => {
37
36
  if (isDebugging) {
38
37
  // eslint-disable-next-line no-console
@@ -246,8 +245,8 @@ const useRerenderCounter = () => {
246
245
  */
247
246
  const RerenderComponent = ({ children }) => {
248
247
  const { rerenderCounter } = useRerenderCounter();
249
- return (jsx("div", { "data-rerender-counter": `rerender-${rerenderCounter}`, children: React.Children.map(children, child => React.isValidElement(child)
250
- ? React.createElement(child.type, {
248
+ return (jsx("div", { "data-rerender-counter": `rerender-${rerenderCounter}`, children: Children.map(children, child => isValidElement(child)
249
+ ? createElement(child.type, {
251
250
  ...child.props,
252
251
  key: child.key,
253
252
  "data-rerender-counter": rerenderCounter,
@@ -296,7 +295,7 @@ const TestRenderChildren = ({ addTestRootContainer, children }) => {
296
295
  * @param selectedRouterProps selected router props
297
296
  * @param rootRoute root route
298
297
  * @param children children to be wrapped
299
- * @returns {React.ReactElement} children component wrapped in a test root container
298
+ * @returns {ReactElement} children component wrapped in a test root container
300
299
  */
301
300
  const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute, children, }) => {
302
301
  const client = useApolloClient();
@@ -971,7 +970,6 @@ const useDebugger = (propsToWatch, id) => {
971
970
  // eslint-disable-next-line no-console
972
971
  console.log(isFirstRender ? "First-render" : "Re-render", uniqueId, window.location.pathname);
973
972
  useEffect(() => {
974
- // eslint-disable-next-line local-rules/prefer-custom-object-entries
975
973
  const changedProps = Object.entries(propsToWatch || {}).reduce((result, [key, value]) => {
976
974
  if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
977
975
  result[key + ""] = [prevPropsRef.current[key], value];
@@ -979,7 +977,6 @@ const useDebugger = (propsToWatch, id) => {
979
977
  return result;
980
978
  }, {});
981
979
  if (objectKeys(changedProps).length > 0) {
982
- // eslint-disable-next-line no-console
983
980
  objectKeys(changedProps).forEach(changedProp => {
984
981
  // eslint-disable-next-line no-console
985
982
  console.log(`${uniqueId} changed property: ${changedProp}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-contexts-test",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -13,9 +13,9 @@
13
13
  "lodash": "4.17.21",
14
14
  "graphql": "^16.9.0",
15
15
  "@tanstack/react-router": "1.47.1",
16
- "@trackunit/react-core-contexts-api": "^1.0.7",
17
- "@trackunit/react-core-hooks": "^1.0.7",
18
- "@trackunit/shared-utils": "^1.1.1"
16
+ "@trackunit/react-core-contexts-api": "1.0.9",
17
+ "@trackunit/react-core-hooks": "1.0.9",
18
+ "@trackunit/shared-utils": "1.2.1"
19
19
  },
20
20
  "module": "./index.esm.js",
21
21
  "main": "./index.cjs.js",
@@ -1,5 +1,5 @@
1
1
  import { RenderHookResult } from "@testing-library/react";
2
- import * as React from "react";
2
+ import { ReactElement, ReactNode } from "react";
3
3
  /**
4
4
  * This is a wrapper around the react testing library renderHook function.
5
5
  * It will make sure that the act function is called and that the promises are flushed.
@@ -8,4 +8,4 @@ import * as React from "react";
8
8
  * @param getMockedCompositionRoot A function that will return the mocked composition root.
9
9
  * @returns { Promise<RenderHookResult> } The rendered hook.
10
10
  */
11
- export declare const reactHooksRenderHook: <TProps, TResult>(callback: (props: TProps) => TResult, getMockedCompositionRoot: (children: React.ReactNode) => React.ReactElement) => Promise<RenderHookResult<TResult, TProps>>;
11
+ export declare const reactHooksRenderHook: <TProps, TResult>(callback: (props: TProps) => TResult, getMockedCompositionRoot: (children: ReactNode) => ReactElement) => Promise<RenderHookResult<TResult, TProps>>;
@@ -2,7 +2,7 @@ import { MockedResponse } from "@apollo/client/testing";
2
2
  import { AnyRoute } from "@tanstack/react-router";
3
3
  import { RenderResult } from "@testing-library/react";
4
4
  import { AssetSortingContextValue, ConfirmationDialogContextValue, ErrorHandlingContextValue, FilterBarValues, IAnalyticsContext, ICurrentUserContext, IEnvironmentContext, INavigationContext, OemBrandingContext, IToastContext, ITokenContext, IUserPreferencesContext, IUserSubscriptionContext, ModalDialogContextValue } from "@trackunit/react-core-contexts-api";
5
- import * as React from "react";
5
+ import { ReactElement, ReactNode } from "react";
6
6
  import { MemoryRouterProps } from "./utils/routingUtils";
7
7
  /**
8
8
  * This builder allows you to enable trackunit providers using the builder pattern, and then call 1 of either:
@@ -357,12 +357,12 @@ export declare class TrackunitProvidersMockBuilder<T extends AnyRoute> {
357
357
  *
358
358
  * @param testChildren - the child element being tested.
359
359
  */
360
- protected getMockedCompositionRoot(testChildren: React.ReactNode): import("react/jsx-runtime").JSX.Element;
361
- protected getMockedCompositionRootWithRouter(testChildren: React.ReactNode): import("react/jsx-runtime").JSX.Element;
360
+ protected getMockedCompositionRoot(testChildren: ReactNode): import("react/jsx-runtime").JSX.Element;
361
+ protected getMockedCompositionRootWithRouter(testChildren: ReactNode): import("react/jsx-runtime").JSX.Element;
362
362
  /**
363
363
  * This will return the mocked composition root.
364
364
  */
365
- renderHook<TProps, TResult>(callback: (props: TProps) => TResult, parentElement?: (children: React.ReactNode) => React.ReactElement): Promise<{
365
+ renderHook<TProps, TResult>(callback: (props: TProps) => TResult, parentElement?: (children: ReactNode) => ReactElement): Promise<{
366
366
  rerender: (props?: TProps) => Promise<void>;
367
367
  result: {
368
368
  current: TResult;
@@ -375,11 +375,11 @@ export declare class TrackunitProvidersMockBuilder<T extends AnyRoute> {
375
375
  * @see https://testing-library.com/docs/react-testing-library/api#render
376
376
  * @param child - the child element being tested.
377
377
  */
378
- render(child: React.ReactElement): Promise<RenderResult>;
378
+ render(child: ReactElement): Promise<RenderResult>;
379
379
  /**
380
380
  * This will return the children in the correct mocked hierarchy of context providers.
381
381
  */
382
- storybook(child: React.ReactNode): import("react/jsx-runtime").JSX.Element;
382
+ storybook(child: ReactNode): import("react/jsx-runtime").JSX.Element;
383
383
  }
384
384
  /**
385
385
  * This is the default mock builder for the TrackunitProviders.
package/src/debugger.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import { ReactNode } from "react";
2
2
  type PropsToWatch<P> = P extends object ? P : never;
3
3
  /**
4
4
  * Differentiate between the first and subsequent renders.
@@ -31,7 +31,7 @@ export declare const useDebugger: <P extends object>(propsToWatch: PropsToWatch<
31
31
  * @param children the children to render
32
32
  */
33
33
  export declare const Debugger: ({ id, logPropsChanges, stop, children, }: {
34
- children?: React.ReactNode;
34
+ children?: ReactNode;
35
35
  id?: string;
36
36
  stop?: boolean;
37
37
  logPropsChanges?: Record<string, unknown>;
@@ -1,7 +1,7 @@
1
- import React from "react";
1
+ import { ReactNode } from "react";
2
2
  /**
3
3
  * This component is used to force re-renders in the test environment, since tanstack router does not support re-render.
4
4
  */
5
5
  export declare const RerenderComponent: ({ children }: {
6
- children: React.ReactNode;
6
+ children: ReactNode;
7
7
  }) => import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,5 @@
1
1
  import { AnyRoute, RegisteredRouter, RouteIds } from "@tanstack/react-router";
2
- import React from "react";
2
+ import { ReactElement, ReactNode } from "react";
3
3
  export type MemoryRouterProps<T extends AnyRoute> = {
4
4
  routeTree?: T;
5
5
  initialEntries?: {
@@ -18,7 +18,7 @@ export declare const RootRouteDebugger: () => import("react/jsx-runtime").JSX.El
18
18
  */
19
19
  export interface TestRenderChildrenProps {
20
20
  addTestRootContainer: boolean;
21
- children: React.ReactNode;
21
+ children: ReactNode;
22
22
  }
23
23
  /**
24
24
  * This component is used to wrap the children of the RouterContainer to add a test root container.
@@ -32,7 +32,7 @@ export interface RouterContainerProps<T extends AnyRoute = AnyRoute> {
32
32
  addTestRootContainer: boolean;
33
33
  rootRoute?: T | null;
34
34
  selectedRouterProps: MemoryRouterProps<T> | null;
35
- children: React.ReactNode;
35
+ children: ReactNode;
36
36
  }
37
37
  /**
38
38
  * This component is used to wrap the children of the RouterContainer to add a test root container.
@@ -41,6 +41,6 @@ export interface RouterContainerProps<T extends AnyRoute = AnyRoute> {
41
41
  * @param selectedRouterProps selected router props
42
42
  * @param rootRoute root route
43
43
  * @param children children to be wrapped
44
- * @returns {React.ReactElement} children component wrapped in a test root container
44
+ * @returns {ReactElement} children component wrapped in a test root container
45
45
  */
46
- export declare const RouterContainer: ({ addTestRootContainer, selectedRouterProps, rootRoute, children, }: RouterContainerProps) => React.ReactElement;
46
+ export declare const RouterContainer: ({ addTestRootContainer, selectedRouterProps, rootRoute, children, }: RouterContainerProps) => ReactElement;