@trackunit/react-core-contexts-test 0.0.1-alpha-afcc978985.0

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,38 @@
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/tailwind-styled-components';
9
+ import 'react-router-dom';
10
+ import '@apollo/client';
11
+ import '@apollo/client/link/error';
12
+ import '@apollo/client/testing';
13
+ import 'graphql';
14
+
15
+ const reactHooksRenderHook = (callback, getMockedCompositionRoot) => __awaiter(void 0, void 0, void 0, function* () {
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ const wrapper = ({
18
+ children
19
+ }) => {
20
+ // eslint-disable-next-line react/jsx-no-useless-fragment
21
+ return getMockedCompositionRoot(jsx(Fragment, {
22
+ children: children
23
+ }));
24
+ };
25
+
26
+ let renderedHook; // This is added here to make storybook work and to ensure the right act is loaded for hooks.
27
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
28
+
29
+ yield act(() => __awaiter(void 0, void 0, void 0, function* () {
30
+ renderedHook = renderHook(callback, {
31
+ wrapper
32
+ });
33
+ yield flushPromises();
34
+ }));
35
+ return renderedHook;
36
+ });
37
+
38
+ 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,15 @@
1
+ > **⚠️ Beta**
2
+ >
3
+ > This is a beta version and subject to change without notice.
4
+
5
+ # Trackunit React Core Contexts Tests
6
+ The `@trackunit/react-core-contexts-test` package contains testing utilities for [@trackunit/react-core-contexts](https://www.npmjs.com/package/@trackunit/react-core-contexts).
7
+
8
+ For more info and a full guide on Iris App SDK Development, please visit our [Developer Hub](https://developers.trackunit.com/).
9
+
10
+ ## Trackunit
11
+ This package was developed by Trackunit ApS.
12
+ Trackunit is the leading SaaS-based IoT solution for the construction industry, offering an ecosystem of hardware, fleet management software & telematics.
13
+
14
+ ![The Trackunit logo](https://trackunit.com/wp-content/uploads/2022/03/top-logo.svg)
15
+
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./MockContextProviderBuilder";
2
+ export * from "./mocks/mockCurrentUserContext";
3
+ export * from "./mocks/mockEnvironmentContext";
4
+ export * from "./utils/doNothing";
5
+ export * from "./utils/queryFor";
package/index.js ADDED
@@ -0,0 +1,11 @@
1
+ export { M as MockContextProviderBuilder, d as doNothing, m as mockCurrentUserContext, a 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/tailwind-styled-components';
7
+ import 'react-router-dom';
8
+ import '@apollo/client';
9
+ import '@apollo/client/link/error';
10
+ import '@apollo/client/testing';
11
+ import 'graphql';