@trackunit/react-core-contexts-test 0.0.3

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.
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare function ApolloMockedProviderWithError(props: any): JSX.Element;
@@ -0,0 +1,3 @@
1
+ import { Renderer, RenderHookResult } from "@testing-library/react-hooks/pure";
2
+ import * as React from "react";
3
+ export declare const reactHooksRenderHook: <TProps, TResult>(callback: (props: TProps) => TResult, getMockedCompositionRoot: (children: React.ReactElement) => React.ReactElement) => Promise<RenderHookResult<TProps, TResult, Renderer<TProps>>>;
@@ -0,0 +1,37 @@
1
+ import { _ as __awaiter, f as flushPromises } from './index2.js';
2
+ import { jsx, Fragment } from 'react/jsx-runtime';
3
+ import { renderHook } from '@testing-library/react-hooks/pure';
4
+ import { act } from 'react-test-renderer';
5
+ import '@testing-library/react';
6
+ import '@trackunit/react-core-contexts-api';
7
+ import '@trackunit/react-core-hooks';
8
+ import '@trackunit/ui-theme';
9
+ import 'react-router-dom';
10
+ import '@apollo/client';
11
+ import '@apollo/client/link/error';
12
+ import '@apollo/client/testing';
13
+
14
+ const reactHooksRenderHook = (callback, getMockedCompositionRoot) => __awaiter(void 0, void 0, void 0, function* () {
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ const wrapper = ({
17
+ children
18
+ }) => {
19
+ // eslint-disable-next-line react/jsx-no-useless-fragment
20
+ return getMockedCompositionRoot(jsx(Fragment, {
21
+ children: children
22
+ }));
23
+ };
24
+
25
+ let renderedHook; // This is added here to make storybook work and to ensure the right act is loaded for hooks.
26
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
27
+
28
+ yield act(() => __awaiter(void 0, void 0, void 0, function* () {
29
+ renderedHook = renderHook(callback, {
30
+ wrapper
31
+ });
32
+ yield flushPromises();
33
+ }));
34
+ return renderedHook;
35
+ });
36
+
37
+ export { reactHooksRenderHook };
@@ -0,0 +1,76 @@
1
+ import { MockedResponse } from "@apollo/client/testing";
2
+ import { RenderResult } from "@testing-library/react";
3
+ import { ICurrentUserContext, IEnvironmentContext, IFeature, ITokenContext, UserSubscriptionPackageType } from "@trackunit/react-core-contexts-api";
4
+ import * as React from "react";
5
+ import { MemoryRouterProps } from "react-router-dom";
6
+ /**
7
+ * This builder allows you to enable providers using the builder pattern, and then call 1 of either:
8
+ * - render
9
+ * - mount
10
+ */
11
+ export declare class MockContextProviderBuilder {
12
+ protected selectedEnvironmentContext: IEnvironmentContext;
13
+ protected selectedTokenContext: ITokenContext;
14
+ protected userSubscriptionPackageType: UserSubscriptionPackageType;
15
+ protected features: IFeature[];
16
+ protected selectedApolloMocks: MockedResponse[];
17
+ protected selectedRouterProps: MemoryRouterProps;
18
+ protected selectedAssumedUser: ICurrentUserContext["assumedUser"];
19
+ /**
20
+ * Use this Environment Context.
21
+ *
22
+ * @param environmentContext
23
+ */
24
+ environment(environmentContext?: IEnvironmentContext): this;
25
+ /**
26
+ * Use this token.
27
+ *
28
+ * @param token
29
+ */
30
+ token(token: string): this;
31
+ /**
32
+ * Use this to pass in userSubscriptionPackage.
33
+ *
34
+ * @param developerSettingsContext
35
+ */
36
+ userSubscriptionPackage(userSubscriptionPackage?: UserSubscriptionPackageType): this;
37
+ /**
38
+ * Use this to pass in SupportedFeatures.
39
+ *
40
+ * @param developerSettingsContext
41
+ */
42
+ supportedFeatures(features?: string[]): this;
43
+ /**
44
+ * Assume this user
45
+ *
46
+ * @param assumeUser
47
+ */
48
+ assumeUser(assumeUser: ICurrentUserContext["assumedUser"]): this;
49
+ /**
50
+ * Use this Router Props with the given mocks.
51
+ *
52
+ * @param routerProps
53
+ */
54
+ routerProps(routerProps?: MemoryRouterProps): this;
55
+ 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
+ /**
57
+ * Use this Manager Apollo Context Provider with the given mocks.
58
+ *
59
+ * @param apolloMocks
60
+ */
61
+ apollo(apolloMocks?: MockedResponse[]): this;
62
+ /**
63
+ * This will use RTL.render the child in the correct mocked hierarchy of context providers.
64
+ *
65
+ * @param child - the child element being tested.
66
+ */
67
+ render(child: React.ReactElement): Promise<RenderResult<typeof import("@testing-library/dom/types/queries"), HTMLElement, HTMLElement>>;
68
+ /**
69
+ * Make sure this represent the same structure as the main index.tsx does.
70
+ *
71
+ * @param testChildren - the child element being tested.
72
+ * @param addTestRootContainer - if you want to add a root container to the test.
73
+ */
74
+ protected getMockedCompositionRoot(testChildren: React.ReactNode, addTestRootContainer?: boolean): JSX.Element;
75
+ }
76
+ export declare const rootContext: () => MockContextProviderBuilder;
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ This is the documentation for library
2
+
3
+ # core-contexts-test
4
+
5
+ The purpose of this library is to contain the
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./MockContextProviderBuilder";
2
+ export * from "./mocks/mockEnvironmentContext";
3
+ export * from "./utils/doNothing";
4
+ export * from "./utils/queryFor";
package/index.js ADDED
@@ -0,0 +1,10 @@
1
+ export { M as MockContextProviderBuilder, d as doNothing, m as mockEnvironmentContext, q as queryFor, r as rootContext } from './index2.js';
2
+ import 'react/jsx-runtime';
3
+ import '@testing-library/react';
4
+ import '@trackunit/react-core-contexts-api';
5
+ import '@trackunit/react-core-hooks';
6
+ import '@trackunit/ui-theme';
7
+ import 'react-router-dom';
8
+ import '@apollo/client';
9
+ import '@apollo/client/link/error';
10
+ import '@apollo/client/testing';