@trackunit/react-core-contexts-test 0.1.69 → 0.1.71
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/HookRenderer.cjs +1 -0
- package/HookRenderer.js +1 -0
- package/index.cjs +7 -2
- package/index.js +3 -2
- package/index2.cjs +202 -171
- package/index2.js +198 -171
- package/package.json +3 -2
- package/src/{MockContextProviderBuilder.d.ts → TrackunitProvidersMockBuilder.d.ts} +73 -56
- package/src/index.d.ts +5 -1
- package/src/mocks/mockCurrentUserContext.d.ts +1 -2
- package/src/mocks/mockUserSubscriptionContext.d.ts +2 -4
- /package/src/mocks/{mockIrisOemAppSDKContext.d.ts → mockOemBrandingContext.d.ts} +0 -0
|
@@ -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,
|
|
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
|
-
*
|
|
10
|
+
* For React Hooks:
|
|
11
|
+
* - renderHook
|
|
12
|
+
* For Storybook:
|
|
13
|
+
* - storybook
|
|
10
14
|
*/
|
|
11
|
-
export declare class
|
|
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 {
|
|
33
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
29
34
|
*/
|
|
30
|
-
analytics(analyticsContext: IAnalyticsContext<
|
|
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 {
|
|
42
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
36
43
|
*/
|
|
37
|
-
environment(environmentContext
|
|
44
|
+
environment(environmentContext: Partial<IEnvironmentContext>): this;
|
|
38
45
|
/**
|
|
39
|
-
* Use this
|
|
46
|
+
* Use this to pass in a differerent current user.
|
|
47
|
+
* Defaults to mockCurrentUserContext.
|
|
40
48
|
*
|
|
41
|
-
* @
|
|
42
|
-
* @returns {
|
|
49
|
+
* @see mockCurrentUserContext
|
|
50
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
43
51
|
*/
|
|
44
|
-
|
|
52
|
+
currentUser(currentUserContext: Partial<ICurrentUserContext>): this;
|
|
45
53
|
/**
|
|
46
|
-
*
|
|
54
|
+
* Use this to pass in a differerent current user subscription.
|
|
55
|
+
* Defaults to mockUserSubscriptionContext.
|
|
47
56
|
*
|
|
48
|
-
* @
|
|
57
|
+
* @see mockUserSubscriptionContext
|
|
58
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
49
59
|
*/
|
|
50
|
-
|
|
60
|
+
userSubscription(userSubscription: Partial<IUserSubscriptionContext> | {
|
|
61
|
+
features: string[];
|
|
62
|
+
}): this;
|
|
51
63
|
/**
|
|
52
|
-
*
|
|
64
|
+
* Set global asset sorting context.
|
|
65
|
+
* Defaults to mockAssetSortingContext.
|
|
53
66
|
*
|
|
54
|
-
* @
|
|
55
|
-
* @
|
|
67
|
+
* @see mockAssetSortingContext
|
|
68
|
+
* @param assetSortingContext - Override the default context.
|
|
69
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
56
70
|
*/
|
|
57
|
-
|
|
71
|
+
assetSorting(assetSortingContext: Partial<IAssetSortingContext>): this;
|
|
58
72
|
/**
|
|
59
|
-
*
|
|
73
|
+
* Set OEM Branding context.
|
|
74
|
+
* Defaults to mockOemBrandingContext.
|
|
60
75
|
*
|
|
61
|
-
* @
|
|
62
|
-
* @
|
|
76
|
+
* @see mockOemBrandingContext
|
|
77
|
+
* @param oemBrandingContext - Override the default context.
|
|
63
78
|
*/
|
|
64
|
-
|
|
79
|
+
oemBrandingContext(oemBrandingContext: Partial<IOemBrandingContext>): this;
|
|
65
80
|
/**
|
|
66
|
-
* Use this
|
|
81
|
+
* Use this ToastContext with the given mocks.
|
|
82
|
+
* Defaults to mockToastContext.
|
|
67
83
|
*
|
|
68
|
-
* @
|
|
69
|
-
* @
|
|
84
|
+
* @see mockToastContext
|
|
85
|
+
* @param toastContext - Override the default toast context.
|
|
70
86
|
*/
|
|
71
|
-
|
|
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 {
|
|
93
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
77
94
|
*/
|
|
78
95
|
globalSelection(globalSelection: IGlobalSelectionContext["selection"]): this;
|
|
79
96
|
/**
|
|
80
|
-
*
|
|
97
|
+
* Use this token.
|
|
81
98
|
*
|
|
82
|
-
* @param
|
|
83
|
-
* @returns {
|
|
99
|
+
* @param token - The token to use.
|
|
100
|
+
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
84
101
|
*/
|
|
85
|
-
|
|
102
|
+
token(token: string): this;
|
|
86
103
|
/**
|
|
87
|
-
*
|
|
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
|
-
|
|
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: () =>
|
|
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:
|
|
7
|
+
export declare const mockCurrentUserContext: ICurrentUserContext;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
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
|
|
7
|
+
export declare const mockUserSubscriptionContext: IUserSubscriptionContext;
|
|
File without changes
|