@trackunit/react-core-contexts-test 0.0.52 → 0.0.54

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.
@@ -1,6 +1,6 @@
1
1
  import { MockedResponse } from "@apollo/client/testing";
2
2
  import { RenderResult } from "@testing-library/react";
3
- import { ICurrentUserContext, IEnvironmentContext, IFeature, ITokenContext, UserSubscriptionPackageType } from "@trackunit/react-core-contexts-api";
3
+ import { ICurrentUserContext, IEnvironmentContext, IFeature, IGlobalSelectionContext, ITokenContext, UserSubscriptionPackageType } from "@trackunit/react-core-contexts-api";
4
4
  import * as React from "react";
5
5
  import { MemoryRouterProps } from "react-router-dom";
6
6
  /**
@@ -16,6 +16,7 @@ export declare class MockContextProviderBuilder {
16
16
  protected selectedApolloMocks: MockedResponse[];
17
17
  protected selectedRouterProps: MemoryRouterProps;
18
18
  protected selectedAssumedUser: ICurrentUserContext["assumedUser"];
19
+ protected selectedGlobalSelection: IGlobalSelectionContext;
19
20
  /**
20
21
  * Use this Environment Context.
21
22
  *
@@ -52,6 +53,12 @@ export declare class MockContextProviderBuilder {
52
53
  * @param routerProps
53
54
  */
54
55
  routerProps(routerProps?: MemoryRouterProps): this;
56
+ /**
57
+ * Use this global selection.
58
+ *
59
+ * @param globalSelection
60
+ */
61
+ globalSelection(globalSelection: IGlobalSelectionContext["selection"]): this;
55
62
  renderHook<TProps, TResult>(callback: (props: TProps) => TResult, parentElement?: (children: React.ReactElement) => React.ReactElement): Promise<import("@testing-library/react-hooks/pure").RenderHookResult<TProps, TResult, import("@testing-library/react-hooks/pure").Renderer<TProps>>>;
56
63
  /**
57
64
  * Use this Manager Apollo Context Provider with the given mocks.
@@ -65,6 +72,13 @@ export declare class MockContextProviderBuilder {
65
72
  * @param child - the child element being tested.
66
73
  */
67
74
  render(child: React.ReactElement): Promise<RenderResult<typeof import("@testing-library/dom/types/queries"), HTMLElement, HTMLElement>>;
75
+ /**
76
+ * Validate the mocks that has been supplied to make sure they make sense.
77
+ * Note: This function is overriden in builders extending this one.
78
+ *
79
+ * @returns true or throws error if any invalid mocks
80
+ */
81
+ protected validateSuppliedMocks(): true | never;
68
82
  /**
69
83
  * Make sure this represent the same structure as the main index.tsx does.
70
84
  *
package/index2.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
2
  import { act, render } from '@testing-library/react';
3
3
  import { UserSubscriptionPackageType } from '@trackunit/react-core-contexts-api';
4
- import { EnvironmentContextProvider, CurrentUserProvider, UserSubscriptionProvider, TokenProvider, ToastProvider } from '@trackunit/react-core-hooks';
4
+ import { EnvironmentContextProvider, CurrentUserProvider, UserSubscriptionProvider, TokenProvider, ToastProvider, GlobalSelectionProvider } from '@trackunit/react-core-hooks';
5
5
  import { tw } from '@trackunit/tailwind-styled-components';
6
6
  import { MemoryRouter } from 'react-router-dom';
7
7
  import { ApolloLink } from '@apollo/client';
@@ -2453,6 +2453,9 @@ class MockContextProviderBuilder {
2453
2453
  this.selectedApolloMocks = [];
2454
2454
  this.selectedRouterProps = {};
2455
2455
  this.selectedAssumedUser = mockCurrentUserContext().assumedUser;
2456
+ this.selectedGlobalSelection = {
2457
+ selection: null
2458
+ };
2456
2459
  }
2457
2460
  /**
2458
2461
  * Use this Environment Context.
@@ -2533,11 +2536,24 @@ class MockContextProviderBuilder {
2533
2536
  this.selectedRouterProps = routerProps || {};
2534
2537
  return this;
2535
2538
  }
2539
+ /**
2540
+ * Use this global selection.
2541
+ *
2542
+ * @param globalSelection
2543
+ */
2544
+
2545
+
2546
+ globalSelection(globalSelection) {
2547
+ this.selectedGlobalSelection = {
2548
+ selection: globalSelection
2549
+ };
2550
+ return this;
2551
+ }
2536
2552
 
2537
2553
  renderHook(callback, parentElement) {
2538
2554
  return __awaiter(this, void 0, void 0, function* () {
2539
- // This ensures correct act loading when using hooks
2540
- // eslint-disable-next-line @typescript-eslint/no-var-requires
2555
+ this.validateSuppliedMocks(); // This ensures correct act loading when using hooks
2556
+
2541
2557
  const hookRenderer = yield import('./HookRenderer.js');
2542
2558
  return hookRenderer.reactHooksRenderHook(callback, children => this.getMockedCompositionRoot(parentElement ? parentElement(children) : children));
2543
2559
  });
@@ -2562,6 +2578,7 @@ class MockContextProviderBuilder {
2562
2578
 
2563
2579
  render(child) {
2564
2580
  return __awaiter(this, void 0, void 0, function* () {
2581
+ this.validateSuppliedMocks();
2565
2582
  let mountedcomponent;
2566
2583
  yield act(() => __awaiter(this, void 0, void 0, function* () {
2567
2584
  mountedcomponent = render(child, {
@@ -2575,6 +2592,17 @@ class MockContextProviderBuilder {
2575
2592
  return mountedcomponent;
2576
2593
  });
2577
2594
  }
2595
+ /**
2596
+ * Validate the mocks that has been supplied to make sure they make sense.
2597
+ * Note: This function is overriden in builders extending this one.
2598
+ *
2599
+ * @returns true or throws error if any invalid mocks
2600
+ */
2601
+
2602
+
2603
+ validateSuppliedMocks() {
2604
+ return true;
2605
+ }
2578
2606
  /**
2579
2607
  * Make sure this represent the same structure as the main index.tsx does.
2580
2608
  *
@@ -2604,17 +2632,21 @@ class MockContextProviderBuilder {
2604
2632
  addToast: () => {}
2605
2633
  }
2606
2634
  }, {
2607
- children: jsx(ApolloMockedProviderWithError, Object.assign({
2608
- mocks: this.selectedApolloMocks,
2609
- addTypename: false
2635
+ children: jsx(GlobalSelectionProvider, Object.assign({
2636
+ value: this.selectedGlobalSelection
2610
2637
  }, {
2611
- children: addTestRootContainer ? jsx(TestRoot, Object.assign({
2612
- "data-testid": "testRoot"
2638
+ children: jsx(ApolloMockedProviderWithError, Object.assign({
2639
+ mocks: this.selectedApolloMocks,
2640
+ addTypename: false
2613
2641
  }, {
2614
- children: testChildren
2615
- })) : jsx("div", {
2616
- children: testChildren
2617
- })
2642
+ children: addTestRootContainer ? jsx(TestRoot, Object.assign({
2643
+ "data-testid": "testRoot"
2644
+ }, {
2645
+ children: testChildren
2646
+ })) : jsx("div", {
2647
+ children: testChildren
2648
+ })
2649
+ }))
2618
2650
  }))
2619
2651
  }))
2620
2652
  }))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-contexts-test",
3
- "version": "0.0.52",
3
+ "version": "0.0.54",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "module": "./index.js",
@@ -10,8 +10,8 @@
10
10
  "dependencies": {
11
11
  "@apollo/client": "3.6.9",
12
12
  "react": "17.0.2",
13
- "@trackunit/react-core-contexts-api": "0.0.70",
14
- "@trackunit/react-core-hooks": "0.0.80",
13
+ "@trackunit/react-core-contexts-api": "0.1.0",
14
+ "@trackunit/react-core-hooks": "0.1.1",
15
15
  "@trackunit/tailwind-styled-components": "0.0.48",
16
16
  "react-router-dom": "6.4.1",
17
17
  "graphql": "^15.8.0"