@khanacademy/wonder-blocks-testing 7.1.10 → 7.1.12
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/CHANGELOG.md +31 -0
- package/dist/es/index.js +183 -120
- package/dist/fetch/fetch-request-matches-mock.d.ts +5 -0
- package/dist/fetch/fetch-request-matches-mock.js.flow +17 -0
- package/dist/fetch/mock-fetch.d.ts +5 -0
- package/dist/fetch/mock-fetch.js.flow +13 -0
- package/dist/fetch/types.d.ts +9 -0
- package/dist/fetch/types.js.flow +19 -0
- package/dist/fixtures/fixtures.basic.stories.d.ts +13 -0
- package/dist/fixtures/fixtures.basic.stories.js.flow +22 -0
- package/dist/fixtures/fixtures.d.ts +19 -0
- package/dist/fixtures/fixtures.defaultwrapper.stories.d.ts +9 -0
- package/dist/fixtures/fixtures.defaultwrapper.stories.js.flow +17 -0
- package/dist/fixtures/fixtures.js.flow +33 -0
- package/dist/fixtures/types.d.ts +36 -0
- package/dist/fixtures/types.js.flow +37 -0
- package/dist/gql/gql-request-matches-mock.d.ts +3 -0
- package/dist/gql/gql-request-matches-mock.js.flow +15 -0
- package/dist/gql/mock-gql-fetch.d.ts +5 -0
- package/dist/gql/mock-gql-fetch.js.flow +13 -0
- package/dist/gql/types.d.ts +15 -0
- package/dist/gql/types.js.flow +39 -0
- package/dist/harness/adapters/adapters.d.ts +35 -0
- package/dist/harness/adapters/adapters.js.flow +69 -0
- package/dist/harness/adapters/css.d.ts +12 -0
- package/dist/harness/adapters/css.js.flow +23 -0
- package/dist/harness/adapters/data.d.ts +18 -0
- package/dist/harness/adapters/data.js.flow +32 -0
- package/dist/harness/adapters/portal.d.ts +12 -0
- package/dist/harness/adapters/portal.js.flow +18 -0
- package/dist/harness/adapters/router.d.ts +94 -0
- package/dist/harness/adapters/router.js.flow +122 -0
- package/dist/harness/hook-harness.d.ts +13 -0
- package/dist/harness/hook-harness.js.flow +23 -0
- package/dist/harness/make-hook-harness.d.ts +17 -0
- package/dist/harness/make-hook-harness.js.flow +42 -0
- package/dist/harness/make-test-harness.d.ts +18 -0
- package/dist/harness/make-test-harness.js.flow +48 -0
- package/dist/harness/render-adapters.d.ts +6 -0
- package/dist/harness/render-adapters.js.flow +24 -0
- package/dist/harness/test-harness.d.ts +32 -0
- package/dist/harness/test-harness.js.flow +83 -0
- package/dist/harness/types.d.ts +46 -0
- package/dist/harness/types.js.flow +66 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +185 -127
- package/dist/index.js.flow +26 -2
- package/dist/mock-requester.d.ts +5 -0
- package/dist/mock-requester.js.flow +22 -0
- package/dist/respond-with.d.ts +57 -0
- package/dist/respond-with.js.flow +91 -0
- package/dist/response-impl.d.ts +1 -0
- package/dist/response-impl.js.flow +8 -0
- package/dist/settle-controller.d.ts +19 -0
- package/dist/settle-controller.js.flow +26 -0
- package/dist/settle-signal.d.ts +18 -0
- package/dist/settle-signal.js.flow +26 -0
- package/dist/types.d.ts +25 -0
- package/dist/types.js.flow +46 -0
- package/package.json +6 -6
- package/src/__tests__/{mock-requester.test.js → mock-requester.test.ts} +1 -2
- package/src/__tests__/{respond-with.test.js → respond-with.test.ts} +0 -1
- package/src/__tests__/response-impl.test.js +1 -1
- package/src/__tests__/{settle-controller.test.js → settle-controller.test.ts} +0 -1
- package/src/__tests__/{settle-signal.test.js → settle-signal.test.ts} +0 -1
- package/src/fetch/__tests__/__snapshots__/{mock-fetch.test.js.snap → mock-fetch.test.ts.snap} +3 -3
- package/src/fetch/__tests__/{fetch-request-matches-mock.test.js → fetch-request-matches-mock.test.ts} +5 -6
- package/src/fetch/__tests__/{mock-fetch.test.js → mock-fetch.test.ts} +1 -2
- package/src/fetch/{fetch-request-matches-mock.js → fetch-request-matches-mock.ts} +3 -2
- package/src/fetch/{mock-fetch.js → mock-fetch.ts} +2 -3
- package/src/fetch/{types.js → types.ts} +5 -6
- package/src/fixtures/__tests__/{fixtures.test.js → fixtures.test.tsx} +6 -4
- package/src/fixtures/{fixtures.basic.stories.js → fixtures.basic.stories.tsx} +16 -13
- package/src/fixtures/{fixtures.defaultwrapper.stories.js → fixtures.defaultwrapper.stories.tsx} +8 -8
- package/src/fixtures/{fixtures.js → fixtures.tsx} +16 -11
- package/src/fixtures/{types.js → types.ts} +9 -13
- package/src/gql/__tests__/{gql-request-matches-mock.test.js → gql-request-matches-mock.test.ts} +17 -18
- package/src/gql/__tests__/{mock-gql-fetch.test.js → mock-gql-fetch.test.tsx} +44 -45
- package/src/gql/__tests__/{wb-data-integration.test.js → wb-data-integration.test.tsx} +21 -22
- package/src/gql/{gql-request-matches-mock.js → gql-request-matches-mock.ts} +1 -4
- package/src/gql/{mock-gql-fetch.js → mock-gql-fetch.ts} +3 -6
- package/src/gql/types.ts +33 -0
- package/src/harness/__tests__/{hook-harness.test.js → hook-harness.test.ts} +5 -6
- package/src/harness/__tests__/{make-hook-harness.test.js → make-hook-harness.test.tsx} +10 -11
- package/src/harness/__tests__/{make-test-harness.test.js → make-test-harness.test.tsx} +4 -5
- package/src/harness/__tests__/{render-adapters.test.js → render-adapters.test.tsx} +8 -9
- package/src/harness/__tests__/{test-harness.test.js → test-harness.test.ts} +5 -6
- package/src/harness/__tests__/{types.flowtest.js → types.flowtest.tsx} +24 -27
- package/src/harness/adapters/__tests__/{css.test.js → css.test.tsx} +2 -3
- package/src/harness/adapters/__tests__/{data.test.js → data.test.tsx} +4 -3
- package/src/harness/adapters/__tests__/{portal.test.js → portal.test.tsx} +0 -1
- package/src/harness/adapters/__tests__/{router.test.js → router.test.tsx} +75 -56
- package/src/harness/adapters/{adapters.js → adapters.ts} +1 -2
- package/src/harness/adapters/{css.js → css.tsx} +21 -18
- package/src/harness/adapters/{data.js → data.tsx} +7 -5
- package/src/harness/adapters/{portal.js → portal.tsx} +3 -4
- package/src/harness/adapters/router.tsx +218 -0
- package/src/harness/{hook-harness.js → hook-harness.ts} +2 -3
- package/src/harness/{make-hook-harness.js → make-hook-harness.ts} +6 -6
- package/src/harness/{make-test-harness.js → make-test-harness.tsx} +17 -20
- package/src/harness/{render-adapters.js → render-adapters.ts} +4 -4
- package/src/harness/{test-harness.js → test-harness.ts} +1 -12
- package/src/harness/{types.js → types.ts} +14 -12
- package/src/{index.js → index.ts} +0 -2
- package/src/{mock-requester.js → mock-requester.ts} +4 -3
- package/src/{respond-with.js → respond-with.ts} +42 -37
- package/src/{response-impl.js → response-impl.ts} +1 -2
- package/src/{settle-controller.js → settle-controller.ts} +9 -7
- package/src/{settle-signal.js → settle-signal.ts} +10 -7
- package/src/types.ts +40 -0
- package/tsconfig.json +11 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/__docs__/_overview_.stories.mdx +0 -18
- package/src/__docs__/_overview_fixtures.stories.mdx +0 -18
- package/src/__docs__/_overview_mocking.stories.mdx +0 -14
- package/src/__docs__/_overview_test_harness.stories.mdx +0 -18
- package/src/__docs__/exports.fixtures.stories.mdx +0 -31
- package/src/__docs__/exports.harness-adapters.stories.mdx +0 -187
- package/src/__docs__/exports.hook-harness.stories.mdx +0 -22
- package/src/__docs__/exports.make-hook-harness.stories.mdx +0 -25
- package/src/__docs__/exports.make-test-harness.stories.mdx +0 -28
- package/src/__docs__/exports.mock-fetch.stories.mdx +0 -40
- package/src/__docs__/exports.mock-gql-fetch.stories.mdx +0 -64
- package/src/__docs__/exports.respond-with.stories.mdx +0 -84
- package/src/__docs__/exports.settle-controller.stories.mdx +0 -32
- package/src/__docs__/exports.test-harness.stories.mdx +0 -23
- package/src/__docs__/types.fetch-mock-fn.stories.mdx +0 -22
- package/src/__docs__/types.fetch-mock-operation.stories.mdx +0 -18
- package/src/__docs__/types.fixture-fn.stories.mdx +0 -46
- package/src/__docs__/types.fixture-props.stories.mdx +0 -20
- package/src/__docs__/types.get-props-options.stories.mdx +0 -52
- package/src/__docs__/types.gql-fetch-mock-fn.stories.mdx +0 -27
- package/src/__docs__/types.gql-mock-operation.stories.mdx +0 -26
- package/src/__docs__/types.mock-response.stories.mdx +0 -22
- package/src/__docs__/types.test-harness-adapter.stories.mdx +0 -21
- package/src/__docs__/types.test-harness-adapters.stories.mdx +0 -46
- package/src/__docs__/types.test-harness-config.stories.mdx +0 -18
- package/src/__docs__/types.test-harness-configs.stories.mdx +0 -59
- package/src/gql/types.js +0 -34
- package/src/harness/adapters/router.js +0 -206
- package/src/types.js +0 -39
- /package/src/harness/adapters/__tests__/__snapshots__/{router.test.js.snap → router.test.tsx.snap} +0 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for types
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { MockResponse } from "../respond-with";
|
|
9
|
+
export type FetchMockOperation = RegExp | string;
|
|
10
|
+
declare type FetchMockOperationFn = (
|
|
11
|
+
operation: FetchMockOperation,
|
|
12
|
+
response: MockResponse<any>
|
|
13
|
+
) => FetchMockFn;
|
|
14
|
+
export type FetchMockFn = {
|
|
15
|
+
(input: RequestInfo, init?: RequestInit): Promise<Response>,
|
|
16
|
+
mockOperation: FetchMockOperationFn,
|
|
17
|
+
mockOperationOnce: FetchMockOperationFn,
|
|
18
|
+
...
|
|
19
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
type Props = {
|
|
3
|
+
propA: string;
|
|
4
|
+
propB?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const F1: unknown;
|
|
7
|
+
export declare const F2: unknown;
|
|
8
|
+
export declare const F3: unknown;
|
|
9
|
+
declare const _default: {
|
|
10
|
+
title: string;
|
|
11
|
+
component: React.FC<Props>;
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for fixtures.basic.stories
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
declare type Props = {
|
|
10
|
+
propA: string,
|
|
11
|
+
propB?: string,
|
|
12
|
+
...
|
|
13
|
+
};
|
|
14
|
+
declare export var F1: mixed;
|
|
15
|
+
declare export var F2: mixed;
|
|
16
|
+
declare export var F3: mixed;
|
|
17
|
+
declare var _default: {
|
|
18
|
+
title: string,
|
|
19
|
+
component: React.FC<Props>,
|
|
20
|
+
...
|
|
21
|
+
};
|
|
22
|
+
declare export default typeof _default;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { FixtureFn } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Describe a group of fixtures for a given component.
|
|
5
|
+
*
|
|
6
|
+
* Only one `fixtures` call should be used per fixture file as it returns
|
|
7
|
+
* the exports for that file.
|
|
8
|
+
*
|
|
9
|
+
* @param {component: React.ComponentType<any>} options Options describing the
|
|
10
|
+
* fixture group.
|
|
11
|
+
* @param {FixtureFn<TProps> => void} fn A function that provides a `fixture`
|
|
12
|
+
* function for defining fixtures.
|
|
13
|
+
* @returns {(
|
|
14
|
+
* description: string,
|
|
15
|
+
* props: FixtureProps<TProps>,
|
|
16
|
+
* wrapper?: React.ComponentType<TProps>,
|
|
17
|
+
* ) => mixed} A function to create a CSF compatible story.
|
|
18
|
+
*/
|
|
19
|
+
export declare const fixtures: <TComponent extends React.ComponentType<any>, TProps extends JSX.LibraryManagedAttributes<TComponent, React.ComponentProps<TComponent>>>(Component: TComponent) => FixtureFn<TProps>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for fixtures.defaultwrapper.stories
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
declare type Props = { [key: any]: any, ... };
|
|
10
|
+
declare export var F1: mixed;
|
|
11
|
+
declare export var F2: mixed;
|
|
12
|
+
declare var _default: {
|
|
13
|
+
title: string,
|
|
14
|
+
component: React.FC<Props>,
|
|
15
|
+
...
|
|
16
|
+
};
|
|
17
|
+
declare export default typeof _default;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for fixtures
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import type { FixtureFn } from "./types";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Describe a group of fixtures for a given component.
|
|
13
|
+
*
|
|
14
|
+
* Only one `fixtures` call should be used per fixture file as it returns
|
|
15
|
+
* the exports for that file.
|
|
16
|
+
* @param {component} : React.ComponentType<any>} options Options describing the
|
|
17
|
+
* fixture group.
|
|
18
|
+
* @param {FixtureFn<TProps>} => void} fn A function that provides a `fixture`
|
|
19
|
+
* function for defining fixtures.
|
|
20
|
+
* @returns {(
|
|
21
|
+
description: string,
|
|
22
|
+
props: FixtureProps<TProps>,
|
|
23
|
+
wrapper?: React.ComponentType<TProps>) => mixed} A function to create a CSF compatible story.
|
|
24
|
+
*/
|
|
25
|
+
declare export var fixtures: <
|
|
26
|
+
TComponent: React.ComponentType<any>,
|
|
27
|
+
TProps: JSX.LibraryManagedAttributes<
|
|
28
|
+
TComponent,
|
|
29
|
+
React.ComponentProps<TComponent>
|
|
30
|
+
>
|
|
31
|
+
>(
|
|
32
|
+
Component: TComponent
|
|
33
|
+
) => FixtureFn<TProps>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Options injected to the function that returns the fixture props.
|
|
4
|
+
*/
|
|
5
|
+
export type GetPropsOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* A function to call that will log output.
|
|
8
|
+
*/
|
|
9
|
+
log: (message: string, ...args: Array<any>) => void;
|
|
10
|
+
/**
|
|
11
|
+
* A function to make a handler that will log all arguments with the given
|
|
12
|
+
* name or message. Useful for logging events as it avoids the boilerplate
|
|
13
|
+
* of the `log` function.
|
|
14
|
+
*/
|
|
15
|
+
logHandler: (name: string) => (...args: Array<any>) => void;
|
|
16
|
+
};
|
|
17
|
+
export type FixtureProps<TProps extends Record<any, any>> = Readonly<TProps> | ((options: Readonly<GetPropsOptions>) => Readonly<TProps>);
|
|
18
|
+
/**
|
|
19
|
+
* A function for defining a fixture.
|
|
20
|
+
*/
|
|
21
|
+
export type FixtureFn<TProps extends Record<any, any>> = (
|
|
22
|
+
/**
|
|
23
|
+
* The name of the fixture.
|
|
24
|
+
*/
|
|
25
|
+
description: string,
|
|
26
|
+
/**
|
|
27
|
+
* The props for the fixture or a function that returns the props.
|
|
28
|
+
* The function is injected with an API to facilitate logging.
|
|
29
|
+
*/
|
|
30
|
+
props: FixtureProps<TProps>,
|
|
31
|
+
/**
|
|
32
|
+
* An alternative component to render for the fixture.
|
|
33
|
+
* Useful if the fixture requires some additional setup for testing the
|
|
34
|
+
* component.
|
|
35
|
+
*/
|
|
36
|
+
wrapper?: React.ComponentType<TProps>) => unknown;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for types
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Options injected to the function that returns the fixture props.
|
|
12
|
+
*/
|
|
13
|
+
export type GetPropsOptions = {
|
|
14
|
+
/**
|
|
15
|
+
* A function to call that will log output.
|
|
16
|
+
*/
|
|
17
|
+
log: (message: string, ...args: Array<any>) => void,
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A function to make a handler that will log all arguments with the given
|
|
21
|
+
* name or message. Useful for logging events as it avoids the boilerplate
|
|
22
|
+
* of the `log` function.
|
|
23
|
+
*/
|
|
24
|
+
logHandler: (name: string) => (...args: Array<any>) => void,
|
|
25
|
+
...
|
|
26
|
+
};
|
|
27
|
+
export type FixtureProps<TProps: { [key: any]: any, ... }> =
|
|
28
|
+
| $ReadOnly<TProps>
|
|
29
|
+
| ((options: $ReadOnly<GetPropsOptions>) => $ReadOnly<TProps>);
|
|
30
|
+
/**
|
|
31
|
+
* A function for defining a fixture.
|
|
32
|
+
*/
|
|
33
|
+
export type FixtureFn<TProps: { [key: any]: any, ... }> = (
|
|
34
|
+
description: string,
|
|
35
|
+
props: FixtureProps<TProps>,
|
|
36
|
+
wrapper?: React.ComponentType<TProps>
|
|
37
|
+
) => mixed;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { GqlOperation, GqlContext } from "@khanacademy/wonder-blocks-data";
|
|
2
|
+
import type { GqlMockOperation } from "./types";
|
|
3
|
+
export declare const gqlRequestMatchesMock: (mock: GqlMockOperation<any, any, any>, operation: GqlOperation<any, any>, variables: Record<any, any> | null | undefined, context: GqlContext) => boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for gql-request-matches-mock
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { GqlOperation, GqlContext } from "@khanacademy/wonder-blocks-data";
|
|
9
|
+
import type { GqlMockOperation } from "./types";
|
|
10
|
+
declare export var gqlRequestMatchesMock: (
|
|
11
|
+
mock: GqlMockOperation<any, any, any>,
|
|
12
|
+
operation: GqlOperation<any, any>,
|
|
13
|
+
variables: { [key: any]: any, ... } | null | void,
|
|
14
|
+
context: GqlContext
|
|
15
|
+
) => boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for mock-gql-fetch
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { GqlFetchMockFn } from "./types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A mock for the fetch function passed to GqlRouter.
|
|
12
|
+
*/
|
|
13
|
+
declare export var mockGqlFetch: () => GqlFetchMockFn;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { GqlOperation, GqlContext } from "@khanacademy/wonder-blocks-data";
|
|
2
|
+
import type { GraphQLJson } from "../types";
|
|
3
|
+
import type { MockResponse } from "../respond-with";
|
|
4
|
+
export type GqlMockOperation<TData extends Record<any, any>, TVariables extends Record<any, any>, TContext extends GqlContext> = {
|
|
5
|
+
operation: GqlOperation<TData, TVariables>;
|
|
6
|
+
variables?: TVariables;
|
|
7
|
+
context?: TContext;
|
|
8
|
+
};
|
|
9
|
+
type GqlMockOperationFn = <TData extends Record<any, any>, TVariables extends Record<any, any>, TContext extends GqlContext, TResponseData extends GraphQLJson<TData>>(operation: GqlMockOperation<TData, TVariables, TContext>, response: MockResponse<TResponseData>) => GqlFetchMockFn;
|
|
10
|
+
export type GqlFetchMockFn = {
|
|
11
|
+
(operation: GqlOperation<any, any>, variables: Record<any, any> | null | undefined, context: GqlContext): Promise<Response>;
|
|
12
|
+
mockOperation: GqlMockOperationFn;
|
|
13
|
+
mockOperationOnce: GqlMockOperationFn;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for types
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { GqlOperation, GqlContext } from "@khanacademy/wonder-blocks-data";
|
|
9
|
+
import type { GraphQLJson } from "../types";
|
|
10
|
+
import type { MockResponse } from "../respond-with";
|
|
11
|
+
export type GqlMockOperation<
|
|
12
|
+
TData: { [key: any]: any, ... },
|
|
13
|
+
TVariables: { [key: any]: any, ... },
|
|
14
|
+
TContext: GqlContext
|
|
15
|
+
> = {
|
|
16
|
+
operation: GqlOperation<TData, TVariables>,
|
|
17
|
+
variables?: TVariables,
|
|
18
|
+
context?: TContext,
|
|
19
|
+
...
|
|
20
|
+
};
|
|
21
|
+
declare type GqlMockOperationFn = <
|
|
22
|
+
TData: { [key: any]: any, ... },
|
|
23
|
+
TVariables: { [key: any]: any, ... },
|
|
24
|
+
TContext: GqlContext,
|
|
25
|
+
TResponseData: GraphQLJson<TData>
|
|
26
|
+
>(
|
|
27
|
+
operation: GqlMockOperation<TData, TVariables, TContext>,
|
|
28
|
+
response: MockResponse<TResponseData>
|
|
29
|
+
) => GqlFetchMockFn;
|
|
30
|
+
export type GqlFetchMockFn = {
|
|
31
|
+
(
|
|
32
|
+
operation: GqlOperation<any, any>,
|
|
33
|
+
variables: { [key: any]: any, ... } | null | void,
|
|
34
|
+
context: GqlContext
|
|
35
|
+
): Promise<Response>,
|
|
36
|
+
mockOperation: GqlMockOperationFn,
|
|
37
|
+
mockOperationOnce: GqlMockOperationFn,
|
|
38
|
+
...
|
|
39
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference path="../../../types/aphrodite.d.ts" />
|
|
2
|
+
import type { TestHarnessConfigs } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* NOTE: We do not type `DefaultAdapters` with `Adapters` here because we want
|
|
5
|
+
* the individual config types of each adapter to remain intact rather than
|
|
6
|
+
* getting changed to `any`.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The default adapters provided by Wonder Blocks.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DefaultAdapters: {
|
|
12
|
+
readonly css: import("../types").TestHarnessAdapter<string | string[] | import("aphrodite").CSSProperties | {
|
|
13
|
+
classes: string[];
|
|
14
|
+
style: import("aphrodite").CSSProperties;
|
|
15
|
+
}>;
|
|
16
|
+
readonly data: import("../types").TestHarnessAdapter<((requestId: string) => Promise<any> | null | undefined) | ((requestId: string) => Promise<any> | null | undefined)[]>;
|
|
17
|
+
readonly portal: import("../types").TestHarnessAdapter<string>;
|
|
18
|
+
readonly router: import("../types").TestHarnessAdapter<string | Readonly<{
|
|
19
|
+
initialEntries: import("history").LocationDescriptor<unknown>[] | undefined;
|
|
20
|
+
initialIndex?: number | undefined;
|
|
21
|
+
getUserConfirmation?: ((message: string, callback: (ok: boolean) => void) => void) | undefined;
|
|
22
|
+
path?: string | undefined;
|
|
23
|
+
} | {
|
|
24
|
+
location: any;
|
|
25
|
+
forceStatic: true;
|
|
26
|
+
path?: string | undefined;
|
|
27
|
+
} | {
|
|
28
|
+
location: any;
|
|
29
|
+
path?: string | undefined;
|
|
30
|
+
}>>;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The default configurations to use with the `DefaultAdapters`.
|
|
34
|
+
*/
|
|
35
|
+
export declare const DefaultConfigs: TestHarnessConfigs<typeof DefaultAdapters>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for adapters
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as $Flowgen$Import$_2e__2e__2f_types from "../types";
|
|
9
|
+
import * as $Flowgen$Import$aphrodite from "aphrodite";
|
|
10
|
+
import * as $Flowgen$Import$history from "history";
|
|
11
|
+
import type { TestHarnessConfigs } from "../types";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* NOTE: We do not type `DefaultAdapters` with `Adapters` here because we want
|
|
15
|
+
* the individual config types of each adapter to remain intact rather than
|
|
16
|
+
* getting changed to `any`.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* The default adapters provided by Wonder Blocks.
|
|
20
|
+
*/
|
|
21
|
+
declare export var DefaultAdapters: {
|
|
22
|
+
+css: $Flowgen$Import$_2e__2e__2f_types.TestHarnessAdapter<
|
|
23
|
+
| string
|
|
24
|
+
| string[]
|
|
25
|
+
| $Flowgen$Import$aphrodite.CSSProperties
|
|
26
|
+
| {
|
|
27
|
+
classes: string[],
|
|
28
|
+
style: $Flowgen$Import$aphrodite.CSSProperties,
|
|
29
|
+
...
|
|
30
|
+
}
|
|
31
|
+
>,
|
|
32
|
+
+data: $Flowgen$Import$_2e__2e__2f_types.TestHarnessAdapter<
|
|
33
|
+
| ((requestId: string) => Promise<any> | null | void)
|
|
34
|
+
| ((requestId: string) => Promise<any> | null | void)[]
|
|
35
|
+
>,
|
|
36
|
+
+portal: $Flowgen$Import$_2e__2e__2f_types.TestHarnessAdapter<string>,
|
|
37
|
+
+router: $Flowgen$Import$_2e__2e__2f_types.TestHarnessAdapter<
|
|
38
|
+
| string
|
|
39
|
+
| $ReadOnly<
|
|
40
|
+
| {
|
|
41
|
+
initialEntries:
|
|
42
|
+
| $Flowgen$Import$history.LocationDescriptor<mixed>[]
|
|
43
|
+
| void,
|
|
44
|
+
initialIndex?: number | void,
|
|
45
|
+
getUserConfirmation?:
|
|
46
|
+
| ((message: string, callback: (ok: boolean) => void) => void)
|
|
47
|
+
| void,
|
|
48
|
+
path?: string | void,
|
|
49
|
+
...
|
|
50
|
+
}
|
|
51
|
+
| {
|
|
52
|
+
location: any,
|
|
53
|
+
forceStatic: true,
|
|
54
|
+
path?: string | void,
|
|
55
|
+
...
|
|
56
|
+
}
|
|
57
|
+
| {
|
|
58
|
+
location: any,
|
|
59
|
+
path?: string | void,
|
|
60
|
+
...
|
|
61
|
+
}
|
|
62
|
+
>
|
|
63
|
+
>,
|
|
64
|
+
...
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* The default configurations to use with the `DefaultAdapters`.
|
|
68
|
+
*/
|
|
69
|
+
declare export var DefaultConfigs: TestHarnessConfigs<typeof DefaultAdapters>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CSSProperties } from "aphrodite";
|
|
2
|
+
import type { TestHarnessAdapter } from "../types";
|
|
3
|
+
type Config = string | Array<string> | CSSProperties | {
|
|
4
|
+
classes: Array<string>;
|
|
5
|
+
style: CSSProperties;
|
|
6
|
+
};
|
|
7
|
+
export declare const defaultConfig: Config | null | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Test harness adapter for adding CSS to the harnessed component wrapper.
|
|
10
|
+
*/
|
|
11
|
+
export declare const adapter: TestHarnessAdapter<Config>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for css
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { CSSProperties } from "aphrodite";
|
|
9
|
+
import type { TestHarnessAdapter } from "../types";
|
|
10
|
+
declare type Config =
|
|
11
|
+
| string
|
|
12
|
+
| Array<string>
|
|
13
|
+
| CSSProperties
|
|
14
|
+
| {
|
|
15
|
+
classes: Array<string>,
|
|
16
|
+
style: CSSProperties,
|
|
17
|
+
...
|
|
18
|
+
};
|
|
19
|
+
declare export var defaultConfig: Config | null | void;
|
|
20
|
+
/**
|
|
21
|
+
* Test harness adapter for adding CSS to the harnessed component wrapper.
|
|
22
|
+
*/
|
|
23
|
+
declare export var adapter: TestHarnessAdapter<Config>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { InterceptRequests } from "@khanacademy/wonder-blocks-data";
|
|
3
|
+
import type { TestHarnessAdapter } from "../types";
|
|
4
|
+
type Interceptor = JSX.LibraryManagedAttributes<typeof InterceptRequests, React.ComponentProps<typeof InterceptRequests>>["interceptor"];
|
|
5
|
+
type Config = Interceptor | Array<Interceptor>;
|
|
6
|
+
/**
|
|
7
|
+
* Default configuration for the Wonder Blocks Data adapter.
|
|
8
|
+
*/
|
|
9
|
+
export declare const defaultConfig: ((requestId: string) => Promise<any> | null | undefined)[];
|
|
10
|
+
/**
|
|
11
|
+
* Test harness adapter to mock Wonder Blocks Data usage.
|
|
12
|
+
*
|
|
13
|
+
* NOTE: Consumers are responsible for properly defining their intercepts.
|
|
14
|
+
* This component does not validate the configuration to ensure interceptors
|
|
15
|
+
* are not overriding one another.
|
|
16
|
+
*/
|
|
17
|
+
export declare const adapter: TestHarnessAdapter<Config>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for data
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import { InterceptRequests } from "@khanacademy/wonder-blocks-data";
|
|
10
|
+
import type { TestHarnessAdapter } from "../types";
|
|
11
|
+
declare type Interceptor = $PropertyType<
|
|
12
|
+
JSX.LibraryManagedAttributes<
|
|
13
|
+
typeof InterceptRequests,
|
|
14
|
+
React.ComponentProps<typeof InterceptRequests>
|
|
15
|
+
>,
|
|
16
|
+
"interceptor"
|
|
17
|
+
>;
|
|
18
|
+
declare type Config = Interceptor | Array<Interceptor>;
|
|
19
|
+
/**
|
|
20
|
+
* Default configuration for the Wonder Blocks Data adapter.
|
|
21
|
+
*/
|
|
22
|
+
declare export var defaultConfig: ((
|
|
23
|
+
requestId: string
|
|
24
|
+
) => Promise<any> | null | void)[];
|
|
25
|
+
/**
|
|
26
|
+
* Test harness adapter to mock Wonder Blocks Data usage.
|
|
27
|
+
*
|
|
28
|
+
* NOTE: Consumers are responsible for properly defining their intercepts.
|
|
29
|
+
* This component does not validate the configuration to ensure interceptors
|
|
30
|
+
* are not overriding one another.
|
|
31
|
+
*/
|
|
32
|
+
declare export var adapter: TestHarnessAdapter<Config>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TestHarnessAdapter } from "../types";
|
|
2
|
+
type Config = string;
|
|
3
|
+
export declare const defaultConfig: Config | null | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* Test harness adapter for supporting portals.
|
|
6
|
+
*
|
|
7
|
+
* Some components rely on rendering with a React Portal. This adapter ensures
|
|
8
|
+
* that the DOM contains a mounting point for the portal with the expected
|
|
9
|
+
* identifier.
|
|
10
|
+
*/
|
|
11
|
+
export declare const adapter: TestHarnessAdapter<Config>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for portal
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { TestHarnessAdapter } from "../types";
|
|
9
|
+
declare type Config = string;
|
|
10
|
+
declare export var defaultConfig: Config | null | void;
|
|
11
|
+
/**
|
|
12
|
+
* Test harness adapter for supporting portals.
|
|
13
|
+
*
|
|
14
|
+
* Some components rely on rendering with a React Portal. This adapter ensures
|
|
15
|
+
* that the DOM contains a mounting point for the portal with the expected
|
|
16
|
+
* identifier.
|
|
17
|
+
*/
|
|
18
|
+
declare export var adapter: TestHarnessAdapter<Config>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { MemoryRouter } from "react-router-dom";
|
|
3
|
+
import type { LocationShape, Location } from "react-router-dom";
|
|
4
|
+
import type { TestHarnessAdapter } from "../types";
|
|
5
|
+
type MemoryRouterProps = JSX.LibraryManagedAttributes<typeof MemoryRouter, React.ComponentProps<typeof MemoryRouter>>;
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for the withLocation test harness adapter.
|
|
8
|
+
*/
|
|
9
|
+
type Config = Readonly<{
|
|
10
|
+
/**
|
|
11
|
+
* See MemoryRouter prop for initialEntries.
|
|
12
|
+
*/
|
|
13
|
+
initialEntries: MemoryRouterProps["initialEntries"];
|
|
14
|
+
/**
|
|
15
|
+
* See MemoryRouter prop for initialIndex.
|
|
16
|
+
*/
|
|
17
|
+
initialIndex?: MemoryRouterProps["initialIndex"];
|
|
18
|
+
/**
|
|
19
|
+
* See MemoryRouter prop for getUserConfirmation.
|
|
20
|
+
*/
|
|
21
|
+
getUserConfirmation?: MemoryRouterProps["getUserConfirmation"];
|
|
22
|
+
/**
|
|
23
|
+
* A path match to use.
|
|
24
|
+
*
|
|
25
|
+
* When this is specified, the harnessed component will be
|
|
26
|
+
* rendered inside a `Route` handler with this path.
|
|
27
|
+
*
|
|
28
|
+
* If the path matches the location, then the route will
|
|
29
|
+
* render the component.
|
|
30
|
+
*
|
|
31
|
+
* If the path does not match the location, then the route
|
|
32
|
+
* will not render the component.
|
|
33
|
+
*/
|
|
34
|
+
path?: string;
|
|
35
|
+
} | {
|
|
36
|
+
/**
|
|
37
|
+
* The location to use.
|
|
38
|
+
*/
|
|
39
|
+
location: string | Location;
|
|
40
|
+
/**
|
|
41
|
+
* Force the use of a StaticRouter, instead of MemoryRouter.
|
|
42
|
+
*/
|
|
43
|
+
forceStatic: true;
|
|
44
|
+
/**
|
|
45
|
+
* A path match to use.
|
|
46
|
+
*
|
|
47
|
+
* When this is specified, the harnessed component will be
|
|
48
|
+
* rendered inside a `Route` handler with this path.
|
|
49
|
+
*
|
|
50
|
+
* If the path matches the location, then the route will
|
|
51
|
+
* render the component.
|
|
52
|
+
*
|
|
53
|
+
* If the path does not match the location, then the route
|
|
54
|
+
* will not render the component.
|
|
55
|
+
*/
|
|
56
|
+
path?: string;
|
|
57
|
+
} | {
|
|
58
|
+
/**
|
|
59
|
+
* The initial location to use.
|
|
60
|
+
*/
|
|
61
|
+
location: string | LocationShape;
|
|
62
|
+
/**
|
|
63
|
+
* A path match to use.
|
|
64
|
+
*
|
|
65
|
+
* When this is specified, the harnessed component will be
|
|
66
|
+
* rendered inside a `Route` handler with this path.
|
|
67
|
+
*
|
|
68
|
+
* If the path matches the location, then the route will
|
|
69
|
+
* render the component.
|
|
70
|
+
*
|
|
71
|
+
* If the path does not match the location, then the route
|
|
72
|
+
* will not render the component.
|
|
73
|
+
*/
|
|
74
|
+
path?: string;
|
|
75
|
+
}> | string;
|
|
76
|
+
/**
|
|
77
|
+
* The default configuration for this adapter.
|
|
78
|
+
*/
|
|
79
|
+
export declare const defaultConfig: {
|
|
80
|
+
readonly location: "/";
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Adapter that sets up a router and AppShell location-specific contexts.
|
|
84
|
+
*
|
|
85
|
+
* This allows you to ensure that components are being tested in the
|
|
86
|
+
* AppShell world.
|
|
87
|
+
*
|
|
88
|
+
* NOTE(somewhatabstract): The AppShell component itself already does
|
|
89
|
+
* the work of setting up routing and the AppShellContext and so using this
|
|
90
|
+
* adapter with the App component will have zero-effect since AppShell will
|
|
91
|
+
* override it.
|
|
92
|
+
*/
|
|
93
|
+
export declare const adapter: TestHarnessAdapter<Config>;
|
|
94
|
+
export {};
|