@trackunit/react-core-contexts-test 0.1.69 → 0.1.70

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,18 +1,20 @@
1
1
  import { MockedResponse } from "@apollo/client/testing";
2
2
  import { RenderResult } from "@testing-library/react";
3
- import { IAnalyticsContext, IAssetSortingContext, ICurrentUserContext, IEnvironmentContext, IFeature, IGlobalSelectionContext, IOemBrandingContext, IToastContext, ITokenContext, UserSubscriptionPackageType } from "@trackunit/react-core-contexts-api";
3
+ import { IAnalyticsContext, IAssetSortingContext, ICurrentUserContext, IEnvironmentContext, IGlobalSelectionContext, IOemBrandingContext, IToastContext, ITokenContext, IUserSubscriptionContext } from "@trackunit/react-core-contexts-api";
4
4
  import * as React from "react";
5
5
  import { MemoryRouterProps } from "react-router-dom";
6
6
  /**
7
- * This builder allows you to enable providers using the builder pattern, and then call 1 of either:
7
+ * This builder allows you to enable trackunit providers using the builder pattern, and then call 1 of either:
8
+ * For React Components:
8
9
  * - render
9
- * - mount
10
+ * For React Hooks:
11
+ * - renderHook
12
+ * For Storybook:
13
+ * - storybook
10
14
  */
11
- export declare class MockContextProviderBuilder {
15
+ export declare class TrackunitProvidersMockBuilder {
12
16
  protected selectedEnvironmentContext: IEnvironmentContext;
13
17
  protected selectedTokenContext: ITokenContext;
14
- protected userSubscriptionPackageType: UserSubscriptionPackageType;
15
- protected features: IFeature[];
16
18
  protected selectedApolloMocks: MockedResponse[];
17
19
  protected selectedRouterProps: MemoryRouterProps;
18
20
  protected selectedToastContext: IToastContext;
@@ -21,96 +23,96 @@ export declare class MockContextProviderBuilder {
21
23
  protected selectedCurrentUserContext: ICurrentUserContext;
22
24
  protected selectedAnalyticsContext: IAnalyticsContext<{}>;
23
25
  protected selectedOemBrandingContext: IOemBrandingContext;
26
+ protected selectedUserSubscriptionContext: IUserSubscriptionContext;
24
27
  /**
25
28
  * Use this Analytics Context.
29
+ * Defaults to mockAnalyticsContext.
26
30
  *
31
+ * @see mockAnalyticsContext
27
32
  * @param analyticsContext - The analytics context to use.
28
- * @returns { MockContextProviderBuilder } - The builder.
33
+ * @returns { TrackunitProvidersMockBuilder } - The builder.
29
34
  */
30
- analytics(analyticsContext: IAnalyticsContext<{}>): this;
35
+ analytics(analyticsContext: Partial<IAnalyticsContext<any>>): this;
31
36
  /**
32
37
  * Use this Environment Context.
38
+ * Defaults to mockEnvironmentContext.
33
39
  *
40
+ * @see mockEnvironmentContext
34
41
  * @param environmentContext - The environment context to use.
35
- * @returns { MockContextProviderBuilder } - The builder.
42
+ * @returns { TrackunitProvidersMockBuilder } - The builder.
36
43
  */
37
- environment(environmentContext?: IEnvironmentContext): this;
44
+ environment(environmentContext: Partial<IEnvironmentContext>): this;
38
45
  /**
39
- * Use this token.
46
+ * Use this to pass in a differerent current user.
47
+ * Defaults to mockCurrentUserContext.
40
48
  *
41
- * @param token - The token to use.
42
- * @returns { MockContextProviderBuilder } - The builder.
49
+ * @see mockCurrentUserContext
50
+ * @returns { TrackunitProvidersMockBuilder } - The builder.
43
51
  */
44
- token(token: string): this;
52
+ currentUser(currentUserContext: Partial<ICurrentUserContext>): this;
45
53
  /**
46
- * User this to pass in a differerent current user.
54
+ * Use this to pass in a differerent current user subscription.
55
+ * Defaults to mockUserSubscriptionContext.
47
56
  *
48
- * @returns { MockContextProviderBuilder } - The builder.
57
+ * @see mockUserSubscriptionContext
58
+ * @returns { TrackunitProvidersMockBuilder } - The builder.
49
59
  */
50
- currentUser(currentUserContext: ICurrentUserContext): this;
60
+ userSubscription(userSubscription: Partial<IUserSubscriptionContext> | {
61
+ features: string[];
62
+ }): this;
51
63
  /**
52
- * Use this to pass in userSubscriptionPackage.
64
+ * Set global asset sorting context.
65
+ * Defaults to mockAssetSortingContext.
53
66
  *
54
- * @param userSubscriptionPackage - The developer settings context to use.
55
- * @returns { MockContextProviderBuilder } - The builder.
67
+ * @see mockAssetSortingContext
68
+ * @param assetSortingContext - Override the default context.
69
+ * @returns { TrackunitProvidersMockBuilder } - The builder.
56
70
  */
57
- userSubscriptionPackage(userSubscriptionPackage?: UserSubscriptionPackageType): this;
71
+ assetSorting(assetSortingContext: Partial<IAssetSortingContext>): this;
58
72
  /**
59
- * Use this to pass in SupportedFeatures.
73
+ * Set OEM Branding context.
74
+ * Defaults to mockOemBrandingContext.
60
75
  *
61
- * @param features - The developer settings context to use.
62
- * @returns { MockContextProviderBuilder } - The builder.
76
+ * @see mockOemBrandingContext
77
+ * @param oemBrandingContext - Override the default context.
63
78
  */
64
- supportedFeatures(features?: string[]): this;
79
+ oemBrandingContext(oemBrandingContext: Partial<IOemBrandingContext>): this;
65
80
  /**
66
- * Use this Router Props with the given mocks.
81
+ * Use this ToastContext with the given mocks.
82
+ * Defaults to mockToastContext.
67
83
  *
68
- * @param routerProps - The router props to use.
69
- * @returns { MockContextProviderBuilder } - The builder.
84
+ * @see mockToastContext
85
+ * @param toastContext - Override the default toast context.
70
86
  */
71
- routerProps(routerProps?: MemoryRouterProps): this;
87
+ toast(toastContext: Partial<IToastContext>): this;
72
88
  /**
73
89
  * Use this global selection.
90
+ * Defaults to null.
74
91
  *
75
92
  * @param globalSelection - The global selection to use.
76
- * @returns { MockContextProviderBuilder } - The builder.
93
+ * @returns { TrackunitProvidersMockBuilder } - The builder.
77
94
  */
78
95
  globalSelection(globalSelection: IGlobalSelectionContext["selection"]): this;
79
96
  /**
80
- * Set global asset sorting context.
97
+ * Use this token.
81
98
  *
82
- * @param overrides - Override the default context.
83
- * @returns { MockContextProviderBuilder } - The builder.
99
+ * @param token - The token to use.
100
+ * @returns { TrackunitProvidersMockBuilder } - The builder.
84
101
  */
85
- assetSorting(overrides: Partial<IAssetSortingContext>): this;
102
+ token(token: string): this;
86
103
  /**
87
- * This will return the mocked composition root.
104
+ * Use this Router Props with the given mocks.
105
+ *
106
+ * @param routerProps - The router props to use.
107
+ * @returns { TrackunitProvidersMockBuilder } - The builder.
88
108
  */
89
- renderHook<TProps, TResult>(callback: (props: TProps) => TResult, parentElement?: (children: React.ReactElement) => React.ReactElement): Promise<import("@testing-library/react").RenderHookResult<TResult, TProps>>;
109
+ routerProps(routerProps: MemoryRouterProps): this;
90
110
  /**
91
111
  * Use this Manager Apollo Context Provider with the given mocks.
92
112
  *
93
113
  * @param apolloMocks - The mocks to use for the ApolloProvider.
94
114
  */
95
115
  apollo(apolloMocks?: MockedResponse[]): this;
96
- /**
97
- * Use this ToastContext with the given mocks.
98
- *
99
- * @param toastContext - Override the default toast context.
100
- */
101
- toast(toastContext?: Partial<IToastContext>): this;
102
- /**
103
- * Set irisOemApp SDK context.
104
- *
105
- * @param overrides - Override the default context.
106
- */
107
- oemBrandingContext(overrides: Partial<IOemBrandingContext>): this;
108
- /**
109
- * This will use RTL.render the child in the correct mocked hierarchy of context providers.
110
- *
111
- * @param child - the child element being tested.
112
- */
113
- render(child: React.ReactElement): Promise<RenderResult<typeof import("@testing-library/dom/types/queries"), HTMLElement, HTMLElement>>;
114
116
  /**
115
117
  * Validate the mocks that has been supplied to make sure they make sense.
116
118
  * Note: This function is overriden in builders extending this one.
@@ -125,8 +127,23 @@ export declare class MockContextProviderBuilder {
125
127
  * @param addTestRootContainer - if you want to add a root container to the test.
126
128
  */
127
129
  protected getMockedCompositionRoot(testChildren: React.ReactNode, addTestRootContainer?: boolean): JSX.Element;
130
+ /**
131
+ * This will return the mocked composition root.
132
+ */
133
+ renderHook<TProps, TResult>(callback: (props: TProps) => TResult, parentElement?: (children: React.ReactElement) => React.ReactElement): Promise<import("@testing-library/react").RenderHookResult<TResult, TProps>>;
134
+ /**
135
+ * This will use react-testing-library.render the child in the correct mocked hierarchy of context providers.
136
+ *
137
+ * @see https://testing-library.com/docs/react-testing-library/api#render
138
+ * @param child - the child element being tested.
139
+ */
140
+ render(child: React.ReactElement): Promise<RenderResult<typeof import("@testing-library/dom/types/queries"), HTMLElement, HTMLElement>>;
141
+ /**
142
+ * This will return the children in the correct mocked hierarchy of context providers.
143
+ */
144
+ storybook(child: React.ReactNode): JSX.Element;
128
145
  }
129
146
  /**
130
- *
147
+ * This is the default mock builder for the TrackunitProviders.
131
148
  */
132
- export declare const trackunitProviders: () => MockContextProviderBuilder;
149
+ export declare const trackunitProviders: () => TrackunitProvidersMockBuilder;
package/src/index.d.ts CHANGED
@@ -1,8 +1,12 @@
1
1
  export * from "./debugger";
2
- export * from "./MockContextProviderBuilder";
3
2
  export * from "./mocks/mockAnalyticsContext";
3
+ export * from "./mocks/mockAssetSortingContext";
4
4
  export * from "./mocks/mockCurrentUserContext";
5
5
  export * from "./mocks/mockEnvironmentContext";
6
+ export * from "./mocks/mockOemBrandingContext";
7
+ export * from "./mocks/mockToastContext";
8
+ export * from "./mocks/mockUserSubscriptionContext";
9
+ export * from "./TrackunitProvidersMockBuilder";
6
10
  export * from "./utils/doNothing";
7
11
  export * from "./utils/queryFor";
8
12
  export * from "./utils/validateIrisApp";
@@ -2,7 +2,6 @@ import { ICurrentUserContext } from "@trackunit/react-core-contexts-api";
2
2
  /**
3
3
  * Mocks the current user context
4
4
  *
5
- * @param overrides - The overrides to apply to the mock
6
5
  * @returns {ICurrentUserContext} - Returns the mocked current user context
7
6
  */
8
- export declare const mockCurrentUserContext: (overrides?: Partial<ICurrentUserContext>) => ICurrentUserContext;
7
+ export declare const mockCurrentUserContext: ICurrentUserContext;
@@ -1,9 +1,7 @@
1
- import { IFeature, IUserSubscriptionContext, UserSubscriptionPackageType } from "@trackunit/react-core-contexts-api";
1
+ import { IUserSubscriptionContext } from "@trackunit/react-core-contexts-api";
2
2
  /**
3
3
  * This is a mock for the UserSubscriptionContext.
4
4
  *
5
- * @param features - array of features
6
- * @param packageType - package type
7
5
  * @returns { IUserSubscriptionContext }- mock for the UserSubscriptionContext
8
6
  */
9
- export declare const mockUserSubscriptionProviderValue: (features: IFeature[], packageType: UserSubscriptionPackageType) => IUserSubscriptionContext;
7
+ export declare const mockUserSubscriptionContext: IUserSubscriptionContext;