@trackunit/react-core-contexts-test 1.7.25 → 1.7.27

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/index.cjs.js CHANGED
@@ -95,6 +95,18 @@ const mockEnvironmentContext = {
95
95
  reportAccessClientId: "",
96
96
  };
97
97
 
98
+ /**
99
+ * This is a mock for the FilterBarContext.
100
+ *
101
+ * @returns { FilterBarContext }- mock for the FilterBarContext
102
+ */
103
+ const mockFilterBarContext = {
104
+ assetsFilterBarValues: {},
105
+ customersFilterBarValues: {},
106
+ sitesFilterBarValues: {},
107
+ isLoading: false,
108
+ };
109
+
98
110
  const mockOemBrandingContext = {
99
111
  getAllBrandingDetails: doNothing,
100
112
  getOemBranding: async () => null,
@@ -508,12 +520,7 @@ class TrackunitProvidersMockBuilder {
508
520
  this.selectedAnalyticsContext = mockAnalyticsContext;
509
521
  this.selectedOemBrandingContext = mockOemBrandingContext;
510
522
  this.selectedUserSubscriptionContext = mockUserSubscriptionContext;
511
- this.selectedFilterBarValues = {
512
- assetsFilterBarValues: {},
513
- customersFilterBarValues: {},
514
- sitesFilterBarValues: {},
515
- isLoading: false,
516
- };
523
+ this.selectedFilterBarValues = mockFilterBarContext;
517
524
  }
518
525
  /**
519
526
  * Use this Analytics Context.
@@ -974,6 +981,41 @@ class TrackunitProvidersMockBuilder {
974
981
  });
975
982
  return mountedcomponent;
976
983
  }
984
+ /**
985
+ * Test that a hook can handle rerenders with the same props and returns a stable result.
986
+ * This is useful for testing that hooks properly memoize their results.
987
+ * Returns true if the hook result is referentially stable after rerender.
988
+ * Uses Object.is() for comparison to match Jest's toBe() behavior exactly.
989
+ *
990
+ * **Requirements:**
991
+ * - The hook must return a non-null, non-undefined value
992
+ * - If the hook returns null or undefined, the test will throw an error
993
+ * - This ensures the test is actually verifying stability of a meaningful result
994
+ *
995
+ * @example
996
+ * ```ts
997
+ * expect(await trackunitProviders().verifyHookStability(() =>
998
+ * useAssetMetadataChartData({
999
+ * filters: {},
1000
+ * selectedChartOption: "metadataCompleteness",
1001
+ * })
1002
+ * )).toBe(true);
1003
+ * ```
1004
+ * @param callback - The hook to test
1005
+ * @param parentElement - Optional parent element wrapper
1006
+ * @throws Error if the hook result is undefined or null (to ensure meaningful stability testing)
1007
+ * @returns true if the result is referentially stable after rerender (using Object.is()), false otherwise
1008
+ */
1009
+ async verifyHookStability(callback, parentElement) {
1010
+ const { result, rerender } = await this.renderHook(callback, parentElement);
1011
+ const initial = result.current;
1012
+ await rerender();
1013
+ const updated = result.current;
1014
+ if (updated === undefined || updated === null) {
1015
+ throw new Error("Updated result is undefined or null, so the test is not testing anything");
1016
+ }
1017
+ return Object.is(updated, initial);
1018
+ }
977
1019
  /**
978
1020
  * This will return the children in the correct mocked hierarchy of context providers.
979
1021
  */
@@ -1266,6 +1308,7 @@ exports.mockAnalyticsContext = mockAnalyticsContext;
1266
1308
  exports.mockAssetSortingContext = mockAssetSortingContext;
1267
1309
  exports.mockCurrentUserContext = mockCurrentUserContext;
1268
1310
  exports.mockEnvironmentContext = mockEnvironmentContext;
1311
+ exports.mockFilterBarContext = mockFilterBarContext;
1269
1312
  exports.mockOemBrandingContext = mockOemBrandingContext;
1270
1313
  exports.mockToastContext = mockToastContext;
1271
1314
  exports.mockUserSubscriptionContext = mockUserSubscriptionContext;
package/index.esm.js CHANGED
@@ -93,6 +93,18 @@ const mockEnvironmentContext = {
93
93
  reportAccessClientId: "",
94
94
  };
95
95
 
96
+ /**
97
+ * This is a mock for the FilterBarContext.
98
+ *
99
+ * @returns { FilterBarContext }- mock for the FilterBarContext
100
+ */
101
+ const mockFilterBarContext = {
102
+ assetsFilterBarValues: {},
103
+ customersFilterBarValues: {},
104
+ sitesFilterBarValues: {},
105
+ isLoading: false,
106
+ };
107
+
96
108
  const mockOemBrandingContext = {
97
109
  getAllBrandingDetails: doNothing,
98
110
  getOemBranding: async () => null,
@@ -506,12 +518,7 @@ class TrackunitProvidersMockBuilder {
506
518
  this.selectedAnalyticsContext = mockAnalyticsContext;
507
519
  this.selectedOemBrandingContext = mockOemBrandingContext;
508
520
  this.selectedUserSubscriptionContext = mockUserSubscriptionContext;
509
- this.selectedFilterBarValues = {
510
- assetsFilterBarValues: {},
511
- customersFilterBarValues: {},
512
- sitesFilterBarValues: {},
513
- isLoading: false,
514
- };
521
+ this.selectedFilterBarValues = mockFilterBarContext;
515
522
  }
516
523
  /**
517
524
  * Use this Analytics Context.
@@ -972,6 +979,41 @@ class TrackunitProvidersMockBuilder {
972
979
  });
973
980
  return mountedcomponent;
974
981
  }
982
+ /**
983
+ * Test that a hook can handle rerenders with the same props and returns a stable result.
984
+ * This is useful for testing that hooks properly memoize their results.
985
+ * Returns true if the hook result is referentially stable after rerender.
986
+ * Uses Object.is() for comparison to match Jest's toBe() behavior exactly.
987
+ *
988
+ * **Requirements:**
989
+ * - The hook must return a non-null, non-undefined value
990
+ * - If the hook returns null or undefined, the test will throw an error
991
+ * - This ensures the test is actually verifying stability of a meaningful result
992
+ *
993
+ * @example
994
+ * ```ts
995
+ * expect(await trackunitProviders().verifyHookStability(() =>
996
+ * useAssetMetadataChartData({
997
+ * filters: {},
998
+ * selectedChartOption: "metadataCompleteness",
999
+ * })
1000
+ * )).toBe(true);
1001
+ * ```
1002
+ * @param callback - The hook to test
1003
+ * @param parentElement - Optional parent element wrapper
1004
+ * @throws Error if the hook result is undefined or null (to ensure meaningful stability testing)
1005
+ * @returns true if the result is referentially stable after rerender (using Object.is()), false otherwise
1006
+ */
1007
+ async verifyHookStability(callback, parentElement) {
1008
+ const { result, rerender } = await this.renderHook(callback, parentElement);
1009
+ const initial = result.current;
1010
+ await rerender();
1011
+ const updated = result.current;
1012
+ if (updated === undefined || updated === null) {
1013
+ throw new Error("Updated result is undefined or null, so the test is not testing anything");
1014
+ }
1015
+ return Object.is(updated, initial);
1016
+ }
975
1017
  /**
976
1018
  * This will return the children in the correct mocked hierarchy of context providers.
977
1019
  */
@@ -1255,4 +1297,4 @@ const validateIrisApp = async (irisApp) => {
1255
1297
  return null;
1256
1298
  };
1257
1299
 
1258
- export { Debugger, TrackunitProvidersMockBuilder, doNothing, flushPromises, flushPromisesInAct, mockAnalyticsContext, mockAssetSortingContext, mockCurrentUserContext, mockEnvironmentContext, mockOemBrandingContext, mockToastContext, mockUserSubscriptionContext, queryFor, queryForHook, trackunitProviders, useDebugger, validateIrisApp };
1300
+ export { Debugger, TrackunitProvidersMockBuilder, doNothing, flushPromises, flushPromisesInAct, mockAnalyticsContext, mockAssetSortingContext, mockCurrentUserContext, mockEnvironmentContext, mockFilterBarContext, 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.7.25",
3
+ "version": "1.7.27",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -11,10 +11,10 @@
11
11
  "@testing-library/react": "16.2.0",
12
12
  "react": "19.0.0",
13
13
  "graphql": "^16.10.0",
14
- "@trackunit/react-core-contexts-api": "1.8.24",
15
- "@trackunit/react-core-hooks": "1.7.25",
16
- "@trackunit/shared-utils": "1.9.22",
17
- "@trackunit/react-test-setup": "1.4.22",
14
+ "@trackunit/react-core-contexts-api": "1.8.25",
15
+ "@trackunit/react-core-hooks": "1.7.27",
16
+ "@trackunit/shared-utils": "1.9.23",
17
+ "@trackunit/react-test-setup": "1.4.23",
18
18
  "@tanstack/react-router": "1.114.29",
19
19
  "@tanstack/router-core": "1.114.29",
20
20
  "es-toolkit": "^1.39.10"
@@ -392,6 +392,32 @@ export declare class TrackunitProvidersMockBuilder<T extends AnyRoute> {
392
392
  * @param child - the child element being tested.
393
393
  */
394
394
  render(child: ReactElement): Promise<RenderResult>;
395
+ /**
396
+ * Test that a hook can handle rerenders with the same props and returns a stable result.
397
+ * This is useful for testing that hooks properly memoize their results.
398
+ * Returns true if the hook result is referentially stable after rerender.
399
+ * Uses Object.is() for comparison to match Jest's toBe() behavior exactly.
400
+ *
401
+ * **Requirements:**
402
+ * - The hook must return a non-null, non-undefined value
403
+ * - If the hook returns null or undefined, the test will throw an error
404
+ * - This ensures the test is actually verifying stability of a meaningful result
405
+ *
406
+ * @example
407
+ * ```ts
408
+ * expect(await trackunitProviders().verifyHookStability(() =>
409
+ * useAssetMetadataChartData({
410
+ * filters: {},
411
+ * selectedChartOption: "metadataCompleteness",
412
+ * })
413
+ * )).toBe(true);
414
+ * ```
415
+ * @param callback - The hook to test
416
+ * @param parentElement - Optional parent element wrapper
417
+ * @throws Error if the hook result is undefined or null (to ensure meaningful stability testing)
418
+ * @returns true if the result is referentially stable after rerender (using Object.is()), false otherwise
419
+ */
420
+ verifyHookStability<TProps, TResult>(callback: (props: TProps) => TResult, parentElement?: (children: ReactNode) => ReactElement): Promise<boolean>;
395
421
  /**
396
422
  * This will return the children in the correct mocked hierarchy of context providers.
397
423
  */
package/src/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from "./mocks/mockAnalyticsContext";
2
2
  export * from "./mocks/mockAssetSortingContext";
3
3
  export * from "./mocks/mockCurrentUserContext";
4
4
  export * from "./mocks/mockEnvironmentContext";
5
+ export * from "./mocks/mockFilterBarContext";
5
6
  export * from "./mocks/mockOemBrandingContext";
6
7
  export * from "./mocks/mockToastContext";
7
8
  export * from "./mocks/mockUserSubscriptionContext";
@@ -0,0 +1,7 @@
1
+ import { FilterBarContext } from "@trackunit/react-core-contexts-api";
2
+ /**
3
+ * This is a mock for the FilterBarContext.
4
+ *
5
+ * @returns { FilterBarContext }- mock for the FilterBarContext
6
+ */
7
+ export declare const mockFilterBarContext: FilterBarContext;