@trackunit/react-core-contexts-test 1.6.57 → 1.6.60

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.
@@ -2,6 +2,7 @@
2
2
 
3
3
  var react = require('@testing-library/react');
4
4
  var index = require('./index.cjs.js');
5
+ require('@trackunit/react-core-contexts-api');
5
6
  require('react/jsx-runtime');
6
7
  require('@trackunit/react-core-hooks');
7
8
  require('lodash/omit');
@@ -9,7 +10,6 @@ require('@apollo/client');
9
10
  require('@apollo/client/dev');
10
11
  require('@apollo/client/link/error');
11
12
  require('@apollo/client/testing');
12
- require('@trackunit/react-core-contexts-api');
13
13
  require('@trackunit/shared-utils');
14
14
  require('react');
15
15
  require('@apollo/client/react');
@@ -1,5 +1,6 @@
1
1
  import { act, renderHook } from '@testing-library/react';
2
2
  import { flushPromises, flushPromisesInAct } from './index.esm.js';
3
+ import '@trackunit/react-core-contexts-api';
3
4
  import 'react/jsx-runtime';
4
5
  import '@trackunit/react-core-hooks';
5
6
  import 'lodash/omit';
@@ -7,7 +8,6 @@ import '@apollo/client';
7
8
  import '@apollo/client/dev';
8
9
  import '@apollo/client/link/error';
9
10
  import '@apollo/client/testing';
10
- import '@trackunit/react-core-contexts-api';
11
11
  import '@trackunit/shared-utils';
12
12
  import 'react';
13
13
  import '@apollo/client/react';
package/index.cjs.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var reactCoreContextsApi = require('@trackunit/react-core-contexts-api');
3
4
  var jsxRuntime = require('react/jsx-runtime');
4
5
  var react$1 = require('@testing-library/react');
5
6
  var reactCoreHooks = require('@trackunit/react-core-hooks');
@@ -8,48 +9,12 @@ var client = require('@apollo/client');
8
9
  var dev = require('@apollo/client/dev');
9
10
  var error = require('@apollo/client/link/error');
10
11
  var testing = require('@apollo/client/testing');
11
- var reactCoreContextsApi = require('@trackunit/react-core-contexts-api');
12
12
  var sharedUtils = require('@trackunit/shared-utils');
13
13
  var React = require('react');
14
14
  var react = require('@apollo/client/react');
15
15
  var reactRouter = require('@tanstack/react-router');
16
16
  var graphql = require('graphql');
17
17
 
18
- const defaultOptions = {
19
- mutate: {
20
- errorPolicy: "all",
21
- },
22
- query: {
23
- errorPolicy: "all",
24
- },
25
- };
26
- /**
27
- * This is a wrapper around the MockedProvider that logs errors to the console.
28
- */
29
- function ApolloMockedProviderWithError(props) {
30
- const isDebugging = !!process.env.VSCODE_INSPECTOR_OPTIONS || !!process.env.DEBUG;
31
- dev.loadDevMessages();
32
- dev.loadErrorMessages();
33
- const { mocks, ...otherProps } = props;
34
- const mockLink = new testing.MockLink(mocks, false, { showWarnings: isDebugging });
35
- const errorLoggingLink = error.onError(({ graphQLErrors, networkError }) => {
36
- if (graphQLErrors) {
37
- graphQLErrors.map(({ message, locations, path }) => {
38
- if (isDebugging) {
39
- // eslint-disable-next-line no-console
40
- console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
41
- }
42
- });
43
- }
44
- if (networkError && isDebugging) {
45
- // eslint-disable-next-line no-console
46
- console.log(`[Network error]: ${networkError}`);
47
- }
48
- });
49
- const link = client.ApolloLink.from([errorLoggingLink, mockLink]);
50
- return (jsxRuntime.jsx(testing.MockedProvider, { ...otherProps, defaultOptions: { ...defaultOptions, watchQuery: { fetchPolicy: "no-cache" } }, link: link }));
51
- }
52
-
53
18
  /**
54
19
  * Do nothing
55
20
  */
@@ -73,10 +38,6 @@ const mockAssetSortingContext = {
73
38
  },
74
39
  };
75
40
 
76
- const mockConfirmationDialogContext = {
77
- confirm: doNothing,
78
- };
79
-
80
41
  /**
81
42
  * Mocks the current user context
82
43
  *
@@ -101,20 +62,6 @@ const mockCurrentUserContext = {
101
62
  isAccountOwner: true,
102
63
  };
103
64
 
104
- /**
105
- * Mocks the current user context
106
- *
107
- * @returns {IUserPreferencesContext} - Returns the mocked current user context
108
- */
109
- const mockCurrentUserPreferenceContext = {
110
- language: "en",
111
- setLanguage: doNothing,
112
- timeZonePreference: "LOCAL_TIME_ZONE",
113
- setTimeZonePreference: doNothing,
114
- systemOfMeasurement: "SI",
115
- setSystemOfMeasurement: doNothing,
116
- };
117
-
118
65
  const mockEnvironmentContext = {
119
66
  auth: {
120
67
  url: "",
@@ -148,6 +95,83 @@ const mockEnvironmentContext = {
148
95
  reportAccessClientId: "",
149
96
  };
150
97
 
98
+ const mockOemBrandingContext = {
99
+ getAllBrandingDetails: doNothing,
100
+ getOemBranding: async () => null,
101
+ getOemImage: doNothing,
102
+ };
103
+
104
+ const mockToastContext = {
105
+ addToast: doNothing,
106
+ setIsManifestError: doNothing,
107
+ };
108
+
109
+ /**
110
+ * This is a mock for the UserSubscriptionContext.
111
+ *
112
+ * @returns { IUserSubscriptionContext }- mock for the UserSubscriptionContext
113
+ */
114
+ const mockUserSubscriptionContext = {
115
+ numberOfDaysWithAccessToHistoricalData: 30,
116
+ numberOfDaysWithAccessToHistoricalInsights: 30,
117
+ features: [],
118
+ loading: false,
119
+ packageType: "EXPAND_FLEET_OWNER",
120
+ };
121
+
122
+ const defaultOptions = {
123
+ mutate: {
124
+ errorPolicy: "all",
125
+ },
126
+ query: {
127
+ errorPolicy: "all",
128
+ },
129
+ };
130
+ /**
131
+ * This is a wrapper around the MockedProvider that logs errors to the console.
132
+ */
133
+ function ApolloMockedProviderWithError(props) {
134
+ const isDebugging = !!process.env.VSCODE_INSPECTOR_OPTIONS || !!process.env.DEBUG;
135
+ dev.loadDevMessages();
136
+ dev.loadErrorMessages();
137
+ const { mocks, ...otherProps } = props;
138
+ const mockLink = new testing.MockLink(mocks, false, { showWarnings: isDebugging });
139
+ const errorLoggingLink = error.onError(({ graphQLErrors, networkError }) => {
140
+ if (graphQLErrors) {
141
+ graphQLErrors.map(({ message, locations, path }) => {
142
+ if (isDebugging) {
143
+ // eslint-disable-next-line no-console
144
+ console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
145
+ }
146
+ });
147
+ }
148
+ if (networkError && isDebugging) {
149
+ // eslint-disable-next-line no-console
150
+ console.log(`[Network error]: ${networkError}`);
151
+ }
152
+ });
153
+ const link = client.ApolloLink.from([errorLoggingLink, mockLink]);
154
+ return (jsxRuntime.jsx(testing.MockedProvider, { ...otherProps, defaultOptions: { ...defaultOptions, watchQuery: { fetchPolicy: "no-cache" } }, link: link }));
155
+ }
156
+
157
+ const mockConfirmationDialogContext = {
158
+ confirm: doNothing,
159
+ };
160
+
161
+ /**
162
+ * Mocks the current user context
163
+ *
164
+ * @returns {IUserPreferencesContext} - Returns the mocked current user context
165
+ */
166
+ const mockCurrentUserPreferenceContext = {
167
+ language: "en",
168
+ setLanguage: doNothing,
169
+ timeZonePreference: "LOCAL_TIME_ZONE",
170
+ setTimeZonePreference: doNothing,
171
+ systemOfMeasurement: "SI",
172
+ setSystemOfMeasurement: doNothing,
173
+ };
174
+
151
175
  /**
152
176
  * Mocks the ErrorHandlingContextValue
153
177
  *
@@ -197,12 +221,6 @@ const mockNavigationContext = {
197
221
  },
198
222
  };
199
223
 
200
- const mockOemBrandingContext = {
201
- getAllBrandingDetails: doNothing,
202
- getOemBranding: async () => null,
203
- getOemImage: doNothing,
204
- };
205
-
206
224
  const mockTimeRangeContext = {
207
225
  timeRange: {
208
226
  startMsInEpoch: 1,
@@ -215,24 +233,6 @@ const mockTimeRangeContext = {
215
233
  },
216
234
  };
217
235
 
218
- const mockToastContext = {
219
- addToast: doNothing,
220
- setIsManifestError: doNothing,
221
- };
222
-
223
- /**
224
- * This is a mock for the UserSubscriptionContext.
225
- *
226
- * @returns { IUserSubscriptionContext }- mock for the UserSubscriptionContext
227
- */
228
- const mockUserSubscriptionContext = {
229
- numberOfDaysWithAccessToHistoricalData: 30,
230
- numberOfDaysWithAccessToHistoricalInsights: 30,
231
- features: [],
232
- loading: false,
233
- packageType: "EXPAND_FLEET_OWNER",
234
- };
235
-
236
236
  const RerenderContext = React.createContext({ rerenderCounter: 0, setRerenderCounter: (value) => { } });
237
237
  /**
238
238
  * This provider is used to force re-renders in the test environment, since tanstack router does not support re-render.
@@ -963,11 +963,6 @@ class TrackunitProvidersMockBuilder {
963
963
  */
964
964
  const trackunitProviders = () => new TrackunitProvidersMockBuilder();
965
965
 
966
- /**
967
- * Differentiate between the first and subsequent renders.
968
- *
969
- * @returns {boolean} Returns true if it is the first render, false otherwise.
970
- */
971
966
  /**
972
967
  * Differentiate between the first and subsequent renders.
973
968
  *
@@ -980,6 +975,7 @@ const useIsFirstRender = () => {
980
975
  }, []);
981
976
  return isFirstRender;
982
977
  };
978
+
983
979
  /**
984
980
  * Logs props that have changed.
985
981
  * Use this for debugging which props force a component to re-render.
@@ -1245,5 +1241,4 @@ exports.queryFor = queryFor;
1245
1241
  exports.queryForHook = queryForHook;
1246
1242
  exports.trackunitProviders = trackunitProviders;
1247
1243
  exports.useDebugger = useDebugger;
1248
- exports.useIsFirstRender = useIsFirstRender;
1249
1244
  exports.validateIrisApp = validateIrisApp;
package/index.esm.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { AssetSortByProperty, SortOrder } from '@trackunit/react-core-contexts-api';
1
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
3
  import { act, render } from '@testing-library/react';
3
4
  import { ErrorHandlingContextProvider, CurrentUserProvider, AnalyticsContext, UserSubscriptionProvider, OemBrandingContextProvider, TokenProvider, ToastProvider, ConfirmationDialogProvider, FilterBarProvider, AssetSortingProvider, NavigationContextProvider, CurrentUserPreferenceProvider, EnvironmentContextProvider, ModalDialogContextProvider, TimeRangeProvider } from '@trackunit/react-core-hooks';
@@ -6,48 +7,12 @@ import { ApolloLink } from '@apollo/client';
6
7
  import { loadDevMessages, loadErrorMessages } from '@apollo/client/dev';
7
8
  import { onError } from '@apollo/client/link/error';
8
9
  import { MockLink, MockedProvider } from '@apollo/client/testing';
9
- import { AssetSortByProperty, SortOrder } from '@trackunit/react-core-contexts-api';
10
10
  import { doNothing as doNothing$1, objectValues, objectKeys } from '@trackunit/shared-utils';
11
11
  import React, { 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';
15
15
 
16
- const defaultOptions = {
17
- mutate: {
18
- errorPolicy: "all",
19
- },
20
- query: {
21
- errorPolicy: "all",
22
- },
23
- };
24
- /**
25
- * This is a wrapper around the MockedProvider that logs errors to the console.
26
- */
27
- function ApolloMockedProviderWithError(props) {
28
- const isDebugging = !!process.env.VSCODE_INSPECTOR_OPTIONS || !!process.env.DEBUG;
29
- loadDevMessages();
30
- loadErrorMessages();
31
- const { mocks, ...otherProps } = props;
32
- const mockLink = new MockLink(mocks, false, { showWarnings: isDebugging });
33
- const errorLoggingLink = onError(({ graphQLErrors, networkError }) => {
34
- if (graphQLErrors) {
35
- graphQLErrors.map(({ message, locations, path }) => {
36
- if (isDebugging) {
37
- // eslint-disable-next-line no-console
38
- console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
39
- }
40
- });
41
- }
42
- if (networkError && isDebugging) {
43
- // eslint-disable-next-line no-console
44
- console.log(`[Network error]: ${networkError}`);
45
- }
46
- });
47
- const link = ApolloLink.from([errorLoggingLink, mockLink]);
48
- return (jsx(MockedProvider, { ...otherProps, defaultOptions: { ...defaultOptions, watchQuery: { fetchPolicy: "no-cache" } }, link: link }));
49
- }
50
-
51
16
  /**
52
17
  * Do nothing
53
18
  */
@@ -71,10 +36,6 @@ const mockAssetSortingContext = {
71
36
  },
72
37
  };
73
38
 
74
- const mockConfirmationDialogContext = {
75
- confirm: doNothing,
76
- };
77
-
78
39
  /**
79
40
  * Mocks the current user context
80
41
  *
@@ -99,20 +60,6 @@ const mockCurrentUserContext = {
99
60
  isAccountOwner: true,
100
61
  };
101
62
 
102
- /**
103
- * Mocks the current user context
104
- *
105
- * @returns {IUserPreferencesContext} - Returns the mocked current user context
106
- */
107
- const mockCurrentUserPreferenceContext = {
108
- language: "en",
109
- setLanguage: doNothing,
110
- timeZonePreference: "LOCAL_TIME_ZONE",
111
- setTimeZonePreference: doNothing,
112
- systemOfMeasurement: "SI",
113
- setSystemOfMeasurement: doNothing,
114
- };
115
-
116
63
  const mockEnvironmentContext = {
117
64
  auth: {
118
65
  url: "",
@@ -146,6 +93,83 @@ const mockEnvironmentContext = {
146
93
  reportAccessClientId: "",
147
94
  };
148
95
 
96
+ const mockOemBrandingContext = {
97
+ getAllBrandingDetails: doNothing,
98
+ getOemBranding: async () => null,
99
+ getOemImage: doNothing,
100
+ };
101
+
102
+ const mockToastContext = {
103
+ addToast: doNothing,
104
+ setIsManifestError: doNothing,
105
+ };
106
+
107
+ /**
108
+ * This is a mock for the UserSubscriptionContext.
109
+ *
110
+ * @returns { IUserSubscriptionContext }- mock for the UserSubscriptionContext
111
+ */
112
+ const mockUserSubscriptionContext = {
113
+ numberOfDaysWithAccessToHistoricalData: 30,
114
+ numberOfDaysWithAccessToHistoricalInsights: 30,
115
+ features: [],
116
+ loading: false,
117
+ packageType: "EXPAND_FLEET_OWNER",
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
+ function ApolloMockedProviderWithError(props) {
132
+ const isDebugging = !!process.env.VSCODE_INSPECTOR_OPTIONS || !!process.env.DEBUG;
133
+ loadDevMessages();
134
+ loadErrorMessages();
135
+ const { mocks, ...otherProps } = props;
136
+ const mockLink = new MockLink(mocks, false, { showWarnings: isDebugging });
137
+ const errorLoggingLink = onError(({ graphQLErrors, networkError }) => {
138
+ if (graphQLErrors) {
139
+ graphQLErrors.map(({ message, locations, path }) => {
140
+ if (isDebugging) {
141
+ // eslint-disable-next-line no-console
142
+ console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
143
+ }
144
+ });
145
+ }
146
+ if (networkError && isDebugging) {
147
+ // eslint-disable-next-line no-console
148
+ console.log(`[Network error]: ${networkError}`);
149
+ }
150
+ });
151
+ const link = ApolloLink.from([errorLoggingLink, mockLink]);
152
+ return (jsx(MockedProvider, { ...otherProps, defaultOptions: { ...defaultOptions, watchQuery: { fetchPolicy: "no-cache" } }, link: link }));
153
+ }
154
+
155
+ const mockConfirmationDialogContext = {
156
+ confirm: doNothing,
157
+ };
158
+
159
+ /**
160
+ * Mocks the current user context
161
+ *
162
+ * @returns {IUserPreferencesContext} - Returns the mocked current user context
163
+ */
164
+ const mockCurrentUserPreferenceContext = {
165
+ language: "en",
166
+ setLanguage: doNothing,
167
+ timeZonePreference: "LOCAL_TIME_ZONE",
168
+ setTimeZonePreference: doNothing,
169
+ systemOfMeasurement: "SI",
170
+ setSystemOfMeasurement: doNothing,
171
+ };
172
+
149
173
  /**
150
174
  * Mocks the ErrorHandlingContextValue
151
175
  *
@@ -195,12 +219,6 @@ const mockNavigationContext = {
195
219
  },
196
220
  };
197
221
 
198
- const mockOemBrandingContext = {
199
- getAllBrandingDetails: doNothing,
200
- getOemBranding: async () => null,
201
- getOemImage: doNothing,
202
- };
203
-
204
222
  const mockTimeRangeContext = {
205
223
  timeRange: {
206
224
  startMsInEpoch: 1,
@@ -213,24 +231,6 @@ const mockTimeRangeContext = {
213
231
  },
214
232
  };
215
233
 
216
- const mockToastContext = {
217
- addToast: doNothing,
218
- setIsManifestError: doNothing,
219
- };
220
-
221
- /**
222
- * This is a mock for the UserSubscriptionContext.
223
- *
224
- * @returns { IUserSubscriptionContext }- mock for the UserSubscriptionContext
225
- */
226
- const mockUserSubscriptionContext = {
227
- numberOfDaysWithAccessToHistoricalData: 30,
228
- numberOfDaysWithAccessToHistoricalInsights: 30,
229
- features: [],
230
- loading: false,
231
- packageType: "EXPAND_FLEET_OWNER",
232
- };
233
-
234
234
  const RerenderContext = createContext({ rerenderCounter: 0, setRerenderCounter: (value) => { } });
235
235
  /**
236
236
  * This provider is used to force re-renders in the test environment, since tanstack router does not support re-render.
@@ -961,11 +961,6 @@ class TrackunitProvidersMockBuilder {
961
961
  */
962
962
  const trackunitProviders = () => new TrackunitProvidersMockBuilder();
963
963
 
964
- /**
965
- * Differentiate between the first and subsequent renders.
966
- *
967
- * @returns {boolean} Returns true if it is the first render, false otherwise.
968
- */
969
964
  /**
970
965
  * Differentiate between the first and subsequent renders.
971
966
  *
@@ -978,6 +973,7 @@ const useIsFirstRender = () => {
978
973
  }, []);
979
974
  return isFirstRender;
980
975
  };
976
+
981
977
  /**
982
978
  * Logs props that have changed.
983
979
  * Use this for debugging which props force a component to re-render.
@@ -1227,4 +1223,4 @@ const validateIrisApp = async (irisApp) => {
1227
1223
  return null;
1228
1224
  };
1229
1225
 
1230
- export { Debugger, TrackunitProvidersMockBuilder, doNothing, flushPromises, flushPromisesInAct, mockAnalyticsContext, mockAssetSortingContext, mockCurrentUserContext, mockEnvironmentContext, mockOemBrandingContext, mockToastContext, mockUserSubscriptionContext, queryFor, queryForHook, trackunitProviders, useDebugger, useIsFirstRender, validateIrisApp };
1226
+ export { Debugger, TrackunitProvidersMockBuilder, doNothing, flushPromises, flushPromisesInAct, mockAnalyticsContext, mockAssetSortingContext, mockCurrentUserContext, mockEnvironmentContext, mockOemBrandingContext, mockToastContext, mockUserSubscriptionContext, queryFor, queryForHook, trackunitProviders, useDebugger, validateIrisApp };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-contexts-test",
3
- "version": "1.6.57",
3
+ "version": "1.6.60",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -12,10 +12,10 @@
12
12
  "react": "19.0.0",
13
13
  "lodash": "4.17.21",
14
14
  "graphql": "^16.10.0",
15
- "@trackunit/react-core-contexts-api": "1.7.55",
16
- "@trackunit/react-core-hooks": "1.6.57",
17
- "@trackunit/shared-utils": "1.8.54",
18
- "@trackunit/react-test-setup": "1.3.53",
15
+ "@trackunit/react-core-contexts-api": "1.7.58",
16
+ "@trackunit/react-core-hooks": "1.6.60",
17
+ "@trackunit/shared-utils": "1.8.57",
18
+ "@trackunit/react-test-setup": "1.3.56",
19
19
  "@tanstack/react-router": "1.114.29",
20
20
  "@tanstack/router-core": "1.114.29"
21
21
  },
package/src/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- export * from "./TrackunitProvidersMockBuilder";
2
- export * from "./debugger";
3
1
  export * from "./mocks/mockAnalyticsContext";
4
2
  export * from "./mocks/mockAssetSortingContext";
5
3
  export * from "./mocks/mockCurrentUserContext";
@@ -7,6 +5,8 @@ export * from "./mocks/mockEnvironmentContext";
7
5
  export * from "./mocks/mockOemBrandingContext";
8
6
  export * from "./mocks/mockToastContext";
9
7
  export * from "./mocks/mockUserSubscriptionContext";
8
+ export * from "./TrackunitProvidersMockBuilder";
9
+ export * from "./useDebugger";
10
10
  export * from "./utils/doNothing";
11
11
  export * from "./utils/queryFor";
12
12
  export * from "./utils/validateIrisApp";
@@ -1,16 +1,5 @@
1
1
  import { ReactNode } from "react";
2
2
  type PropsToWatch<P> = P extends object ? P : never;
3
- /**
4
- * Differentiate between the first and subsequent renders.
5
- *
6
- * @returns {boolean} Returns true if it is the first render, false otherwise.
7
- */
8
- /**
9
- * Differentiate between the first and subsequent renders.
10
- *
11
- * @returns {boolean} Returns true if it is the first render, false otherwise.
12
- */
13
- export declare const useIsFirstRender: () => boolean;
14
3
  /**
15
4
  * Logs props that have changed.
16
5
  * Use this for debugging which props force a component to re-render.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Differentiate between the first and subsequent renders.
3
+ *
4
+ * @returns {boolean} Returns true if it is the first render, false otherwise.
5
+ */
6
+ export declare const useIsFirstRender: () => boolean;