@khanacademy/wonder-blocks-testing 7.1.9 → 7.1.11
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 +36 -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} +3 -4
- package/src/__tests__/{respond-with.test.js → respond-with.test.ts} +2 -3
- package/src/__tests__/response-impl.test.js +3 -3
- package/src/__tests__/{settle-controller.test.js → settle-controller.test.ts} +2 -3
- package/src/__tests__/{settle-signal.test.js → settle-signal.test.ts} +1 -2
- 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} +6 -7
- package/src/fetch/__tests__/{mock-fetch.test.js → mock-fetch.test.ts} +3 -4
- package/src/fetch/{fetch-request-matches-mock.js → fetch-request-matches-mock.ts} +4 -3
- package/src/fetch/{mock-fetch.js → mock-fetch.ts} +5 -6
- package/src/fetch/types.ts +14 -0
- package/src/fixtures/__tests__/{fixtures.test.js → fixtures.test.tsx} +7 -5
- package/src/fixtures/{fixtures.basic.stories.js → fixtures.basic.stories.tsx} +17 -14
- package/src/fixtures/{fixtures.defaultwrapper.stories.js → fixtures.defaultwrapper.stories.tsx} +9 -9
- package/src/fixtures/{fixtures.js → fixtures.tsx} +17 -12
- 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} +18 -19
- package/src/gql/__tests__/{mock-gql-fetch.test.js → mock-gql-fetch.test.tsx} +46 -47
- package/src/gql/__tests__/{wb-data-integration.test.js → wb-data-integration.test.tsx} +23 -24
- package/src/gql/{gql-request-matches-mock.js → gql-request-matches-mock.ts} +2 -5
- package/src/gql/mock-gql-fetch.ts +15 -0
- package/src/gql/types.ts +33 -0
- package/src/harness/__tests__/{hook-harness.test.js → hook-harness.test.ts} +13 -14
- package/src/harness/__tests__/{make-hook-harness.test.js → make-hook-harness.test.tsx} +12 -13
- package/src/harness/__tests__/{make-test-harness.test.js → make-test-harness.test.tsx} +7 -8
- package/src/harness/__tests__/{render-adapters.test.js → render-adapters.test.tsx} +10 -11
- package/src/harness/__tests__/{test-harness.test.js → test-harness.test.ts} +13 -14
- package/src/harness/__tests__/{types.flowtest.js → types.flowtest.tsx} +25 -28
- package/src/harness/adapters/__tests__/{css.test.js → css.test.tsx} +3 -4
- package/src/harness/adapters/__tests__/{data.test.js → data.test.tsx} +5 -4
- package/src/harness/adapters/__tests__/{portal.test.js → portal.test.tsx} +1 -2
- package/src/harness/adapters/__tests__/{router.test.js → router.test.tsx} +76 -57
- package/src/harness/adapters/{adapters.js → adapters.ts} +6 -7
- package/src/harness/adapters/{css.js → css.tsx} +22 -19
- package/src/harness/adapters/{data.js → data.tsx} +8 -6
- package/src/harness/adapters/{portal.js → portal.tsx} +4 -5
- package/src/harness/adapters/router.tsx +218 -0
- package/src/harness/{hook-harness.js → hook-harness.ts} +5 -6
- package/src/harness/{make-hook-harness.js → make-hook-harness.ts} +8 -8
- package/src/harness/{make-test-harness.js → make-test-harness.tsx} +19 -22
- package/src/harness/{render-adapters.js → render-adapters.ts} +5 -5
- package/src/harness/test-harness.ts +13 -0
- package/src/harness/{types.js → types.ts} +14 -12
- package/src/index.ts +20 -0
- package/src/{mock-requester.js → mock-requester.ts} +6 -5
- package/src/{respond-with.js → respond-with.ts} +45 -40
- package/src/{response-impl.js → response-impl.ts} +1 -2
- package/src/settle-controller.ts +37 -0
- 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/fetch/types.js +0 -15
- package/src/gql/mock-gql-fetch.js +0 -18
- package/src/gql/types.js +0 -34
- package/src/harness/adapters/router.js +0 -206
- package/src/harness/test-harness.js +0 -24
- package/src/index.js +0 -26
- package/src/settle-controller.js +0 -35
- package/src/types.js +0 -39
- /package/src/harness/adapters/__tests__/__snapshots__/{router.test.js.snap → router.test.tsx.snap} +0 -0
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import {render, screen} from "@testing-library/react";
|
|
4
3
|
|
|
5
|
-
import * as Css from "../css
|
|
4
|
+
import * as Css from "../css";
|
|
6
5
|
|
|
7
6
|
describe("Css.adapter", () => {
|
|
8
7
|
it("should throw if the config is invalid", () => {
|
|
@@ -62,7 +61,7 @@ describe("Css.adapter", () => {
|
|
|
62
61
|
${{classes: ["class1", "class2"], style: {backgroundColor: "red"}}} | ${"class1 class2"}
|
|
63
62
|
`(
|
|
64
63
|
"should apply the given class names from $config to the container element",
|
|
65
|
-
({config, expectation}) => {
|
|
64
|
+
({config, expectation}: any) => {
|
|
66
65
|
// Arrange
|
|
67
66
|
const children = <div data-test-id="children">CHILDREN!</div>;
|
|
68
67
|
|
|
@@ -81,7 +80,7 @@ describe("Css.adapter", () => {
|
|
|
81
80
|
${{style: {backgroundColor: "red"}, classes: []}} | ${{backgroundColor: "red"}}
|
|
82
81
|
`(
|
|
83
82
|
"should apply the given styles from $config to the container element",
|
|
84
|
-
({config, expectation}) => {
|
|
83
|
+
({config, expectation}: any) => {
|
|
85
84
|
// Arrange
|
|
86
85
|
const children = <div data-test-id="children">CHILDREN!</div>;
|
|
87
86
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import {render, screen, waitFor} from "@testing-library/react";
|
|
4
3
|
import {useCachedEffect} from "@khanacademy/wonder-blocks-data";
|
|
5
|
-
import * as Data from "../data
|
|
4
|
+
import * as Data from "../data";
|
|
6
5
|
|
|
7
6
|
describe("WonderBlocksData.adapter", () => {
|
|
8
7
|
it("should render children when configuration arrays are empty", () => {
|
|
@@ -22,13 +21,14 @@ describe("WonderBlocksData.adapter", () => {
|
|
|
22
21
|
const TestFixture = () => {
|
|
23
22
|
const [result] = useCachedEffect("ID", jest.fn());
|
|
24
23
|
|
|
24
|
+
// @ts-expect-error [FEI-5019] - TS2339 - Property 'data' does not exist on type 'Result<ValidCacheData>'.
|
|
25
25
|
return <div>CONTENT: {result?.data}</div>;
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
// Act
|
|
29
29
|
const {container} = render(
|
|
30
30
|
Data.adapter(<TestFixture />, () =>
|
|
31
|
-
Promise.resolve(
|
|
31
|
+
Promise.resolve("INTERCEPTED!" as any),
|
|
32
32
|
),
|
|
33
33
|
);
|
|
34
34
|
|
|
@@ -43,13 +43,14 @@ describe("WonderBlocksData.adapter", () => {
|
|
|
43
43
|
const TestFixture = () => {
|
|
44
44
|
const [result] = useCachedEffect("ID", jest.fn());
|
|
45
45
|
|
|
46
|
+
// @ts-expect-error [FEI-5019] - TS2339 - Property 'data' does not exist on type 'Result<ValidCacheData>'.
|
|
46
47
|
return <div>CONTENT:{result?.data}</div>;
|
|
47
48
|
};
|
|
48
49
|
|
|
49
50
|
// Act
|
|
50
51
|
const {container} = render(
|
|
51
52
|
Data.adapter(<TestFixture />, () =>
|
|
52
|
-
Promise.resolve(
|
|
53
|
+
Promise.resolve("INTERCEPTED!" as any),
|
|
53
54
|
),
|
|
54
55
|
);
|
|
55
56
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import {render, screen} from "@testing-library/react";
|
|
4
3
|
|
|
5
|
-
import * as Portal from "../portal
|
|
4
|
+
import * as Portal from "../portal";
|
|
6
5
|
|
|
7
6
|
describe("Portal.adapter", () => {
|
|
8
7
|
it("should render a portal root element", () => {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import {withRouter, Prompt} from "react-router-dom";
|
|
4
3
|
import {render} from "@testing-library/react";
|
|
5
|
-
import * as Router from "../router
|
|
4
|
+
import * as Router from "../router";
|
|
6
5
|
|
|
7
6
|
describe("Router.adapter", () => {
|
|
8
7
|
it("should throw if the config does not match any expecations", () => {
|
|
@@ -25,17 +24,22 @@ describe("Router.adapter", () => {
|
|
|
25
24
|
${"string"} | ${"/math"}
|
|
26
25
|
${"location"} | ${{location: "/math"}}
|
|
27
26
|
${"full"} | ${{initialEntries: ["/math"]}}
|
|
28
|
-
`("with $type config", ({config}) => {
|
|
27
|
+
`("with $type config", ({config}: any) => {
|
|
29
28
|
it("should allow navigation", () => {
|
|
30
29
|
// Arrange
|
|
31
30
|
const historyListen = jest.fn();
|
|
32
|
-
const HistoryListener = withRouter(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
const HistoryListener = withRouter(
|
|
32
|
+
({history}: any): React.ReactElement | null => {
|
|
33
|
+
React.useEffect(
|
|
34
|
+
() => history.listen(historyListen),
|
|
35
|
+
[history],
|
|
36
|
+
);
|
|
37
|
+
if (history.location.pathname === "/math") {
|
|
38
|
+
history.push("/math/calculator");
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
},
|
|
42
|
+
);
|
|
39
43
|
|
|
40
44
|
// Act
|
|
41
45
|
render(Router.adapter(<HistoryListener />, config));
|
|
@@ -47,15 +51,17 @@ describe("Router.adapter", () => {
|
|
|
47
51
|
it("should have default route match of root /", () => {
|
|
48
52
|
// Arrange
|
|
49
53
|
const matchCatcherFn = jest.fn();
|
|
50
|
-
const MatchCatcher = withRouter(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
history.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
const MatchCatcher = withRouter(
|
|
55
|
+
({match, history}: any): React.ReactElement | null => {
|
|
56
|
+
React.useEffect(() => {
|
|
57
|
+
if (history.location.pathname === "/math") {
|
|
58
|
+
history.push("/math/calculator");
|
|
59
|
+
}
|
|
60
|
+
matchCatcherFn(match);
|
|
61
|
+
}, [match, history]);
|
|
62
|
+
return null;
|
|
63
|
+
},
|
|
64
|
+
);
|
|
59
65
|
|
|
60
66
|
// Act
|
|
61
67
|
render(Router.adapter(<MatchCatcher />, config));
|
|
@@ -74,16 +80,18 @@ describe("Router.adapter", () => {
|
|
|
74
80
|
type | config
|
|
75
81
|
${"location"} | ${{location: "/math/calculator", path: "/math/*"}}
|
|
76
82
|
${"full"} | ${{initialEntries: ["/math/calculator"], path: "/math/*"}}
|
|
77
|
-
`("with $type config including path", ({config}) => {
|
|
83
|
+
`("with $type config including path", ({config}: any) => {
|
|
78
84
|
it("should include routing for the given path", () => {
|
|
79
85
|
// Arrange
|
|
80
86
|
const matchCatcherFn = jest.fn();
|
|
81
|
-
const MatchCatcher = withRouter(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
const MatchCatcher = withRouter(
|
|
88
|
+
({match}: any): React.ReactElement | null => {
|
|
89
|
+
React.useEffect(() => {
|
|
90
|
+
matchCatcherFn(match);
|
|
91
|
+
}, [match]);
|
|
92
|
+
return null;
|
|
93
|
+
},
|
|
94
|
+
);
|
|
87
95
|
|
|
88
96
|
// Act
|
|
89
97
|
render(Router.adapter(<MatchCatcher />, config));
|
|
@@ -106,7 +114,7 @@ describe("Router.adapter", () => {
|
|
|
106
114
|
const badConfig = {
|
|
107
115
|
...config,
|
|
108
116
|
path: "/something/else/entirely",
|
|
109
|
-
};
|
|
117
|
+
} as const;
|
|
110
118
|
|
|
111
119
|
// Act
|
|
112
120
|
const underTest = () =>
|
|
@@ -121,13 +129,18 @@ describe("Router.adapter", () => {
|
|
|
121
129
|
it("should not navigate", () => {
|
|
122
130
|
// Arrange
|
|
123
131
|
const historyListen = jest.fn();
|
|
124
|
-
const HistoryListener = withRouter(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
132
|
+
const HistoryListener = withRouter(
|
|
133
|
+
({history}: any): React.ReactElement | null => {
|
|
134
|
+
React.useEffect(
|
|
135
|
+
() => history.listen(historyListen),
|
|
136
|
+
[history],
|
|
137
|
+
);
|
|
138
|
+
if (history.location.pathname === "/math") {
|
|
139
|
+
history.push("/math/calculator");
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
},
|
|
143
|
+
);
|
|
131
144
|
|
|
132
145
|
// Act
|
|
133
146
|
render(
|
|
@@ -146,12 +159,14 @@ describe("Router.adapter", () => {
|
|
|
146
159
|
it("should use the defaultConfig location if initialEntries is empty", () => {
|
|
147
160
|
// Arrange
|
|
148
161
|
const matchCatcherFn = jest.fn();
|
|
149
|
-
const MatchCatcher = withRouter(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
162
|
+
const MatchCatcher = withRouter(
|
|
163
|
+
({match, history}: any): React.ReactElement | null => {
|
|
164
|
+
React.useEffect(() => {
|
|
165
|
+
matchCatcherFn(match);
|
|
166
|
+
}, [match, history]);
|
|
167
|
+
return null;
|
|
168
|
+
},
|
|
169
|
+
);
|
|
155
170
|
|
|
156
171
|
// Act
|
|
157
172
|
render(
|
|
@@ -171,12 +186,14 @@ describe("Router.adapter", () => {
|
|
|
171
186
|
it("should set initialIndex prop on MemoryRouter if given in configuration", () => {
|
|
172
187
|
// Arrange
|
|
173
188
|
const matchCatcherFn = jest.fn();
|
|
174
|
-
const MatchCatcher = withRouter(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
189
|
+
const MatchCatcher = withRouter(
|
|
190
|
+
({match}: any): React.ReactElement | null => {
|
|
191
|
+
React.useEffect(() => {
|
|
192
|
+
matchCatcherFn(match);
|
|
193
|
+
}, [match]);
|
|
194
|
+
return null;
|
|
195
|
+
},
|
|
196
|
+
);
|
|
180
197
|
|
|
181
198
|
// Act
|
|
182
199
|
render(
|
|
@@ -199,20 +216,22 @@ describe("Router.adapter", () => {
|
|
|
199
216
|
// Arrange
|
|
200
217
|
const getUserConfirmationSpy = jest
|
|
201
218
|
.fn()
|
|
202
|
-
.mockImplementation((message, cb) => {
|
|
219
|
+
.mockImplementation((message: any, cb: any) => {
|
|
203
220
|
cb(true);
|
|
204
221
|
});
|
|
205
222
|
const matchCatcherFn = jest.fn();
|
|
206
|
-
const MatchCatcher = withRouter(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
223
|
+
const MatchCatcher = withRouter(
|
|
224
|
+
({match, history}: any): React.ReactElement => {
|
|
225
|
+
React.useEffect(() => {
|
|
226
|
+
if (history.location.pathname === "/location/old") {
|
|
227
|
+
// Fire off a location change.
|
|
228
|
+
history.goForward();
|
|
229
|
+
}
|
|
230
|
+
matchCatcherFn(match);
|
|
231
|
+
}, [match, history]);
|
|
232
|
+
return <Prompt message="Are you sure?" />;
|
|
233
|
+
},
|
|
234
|
+
);
|
|
216
235
|
|
|
217
236
|
// Act
|
|
218
237
|
render(
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
5
|
-
import * as router from "./router.js";
|
|
1
|
+
import * as css from "./css";
|
|
2
|
+
import * as data from "./data";
|
|
3
|
+
import * as portal from "./portal";
|
|
4
|
+
import * as router from "./router";
|
|
6
5
|
|
|
7
|
-
import type {TestHarnessConfigs} from "../types
|
|
6
|
+
import type {TestHarnessConfigs} from "../types";
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* NOTE: We do not type `DefaultAdapters` with `Adapters` here because we want
|
|
@@ -20,7 +19,7 @@ export const DefaultAdapters = {
|
|
|
20
19
|
data: data.adapter,
|
|
21
20
|
portal: portal.adapter,
|
|
22
21
|
router: router.adapter,
|
|
23
|
-
};
|
|
22
|
+
} as const;
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
25
|
* The default configurations to use with the `DefaultAdapters`.
|
|
@@ -1,44 +1,47 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
|
|
4
3
|
import type {CSSProperties} from "aphrodite";
|
|
5
4
|
|
|
6
|
-
import type {TestHarnessAdapter} from "../types
|
|
5
|
+
import type {TestHarnessAdapter} from "../types";
|
|
7
6
|
|
|
8
7
|
type Config =
|
|
9
8
|
| string
|
|
10
9
|
| Array<string>
|
|
11
10
|
| CSSProperties
|
|
12
|
-
| {
|
|
13
|
-
classes: Array<string
|
|
14
|
-
style: CSSProperties
|
|
15
|
-
|
|
11
|
+
| {
|
|
12
|
+
classes: Array<string>;
|
|
13
|
+
style: CSSProperties;
|
|
14
|
+
};
|
|
16
15
|
|
|
17
16
|
// The default configuration is to omit this adapter.
|
|
18
|
-
export const defaultConfig:
|
|
17
|
+
export const defaultConfig: Config | null | undefined = null;
|
|
19
18
|
|
|
20
19
|
const normalizeConfig = (
|
|
21
20
|
config: Config,
|
|
22
|
-
): {
|
|
21
|
+
): {
|
|
22
|
+
classes: Array<string>;
|
|
23
|
+
style: CSSProperties;
|
|
24
|
+
} => {
|
|
23
25
|
if (typeof config === "string") {
|
|
24
|
-
return {classes: [config], style:
|
|
26
|
+
return {classes: [config], style: {} as Partial<CSSProperties>};
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
if (Array.isArray(config)) {
|
|
28
|
-
return {classes: config, style:
|
|
30
|
+
return {classes: config, style: {} as Partial<CSSProperties>};
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
if (typeof config === "object") {
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
if (
|
|
35
|
+
"classes" in config &&
|
|
36
|
+
config.classes != null &&
|
|
37
|
+
"style" in config &&
|
|
38
|
+
config.style != null
|
|
39
|
+
) {
|
|
36
40
|
return config;
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
// $FlowIgnore[prop-missing]
|
|
43
|
+
// @ts-expect-error: at this point, `CSSProperties` is the only thing
|
|
44
|
+
// that `config` can be.
|
|
42
45
|
return {classes: [], style: config};
|
|
43
46
|
}
|
|
44
47
|
|
|
@@ -49,9 +52,9 @@ const normalizeConfig = (
|
|
|
49
52
|
* Test harness adapter for adding CSS to the harnessed component wrapper.
|
|
50
53
|
*/
|
|
51
54
|
export const adapter: TestHarnessAdapter<Config> = (
|
|
52
|
-
children: React.
|
|
55
|
+
children: React.ReactNode,
|
|
53
56
|
config: Config,
|
|
54
|
-
): React.
|
|
57
|
+
): React.ReactElement<any> => {
|
|
55
58
|
const {classes, style} = normalizeConfig(config);
|
|
56
59
|
return (
|
|
57
60
|
<div
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import {InterceptRequests} from "@khanacademy/wonder-blocks-data";
|
|
4
|
-
import type {TestHarnessAdapter} from "../types
|
|
3
|
+
import type {TestHarnessAdapter} from "../types";
|
|
5
4
|
|
|
6
|
-
type Interceptor =
|
|
5
|
+
type Interceptor = JSX.LibraryManagedAttributes<
|
|
6
|
+
typeof InterceptRequests,
|
|
7
|
+
React.ComponentProps<typeof InterceptRequests>
|
|
8
|
+
>["interceptor"];
|
|
7
9
|
|
|
8
10
|
type Config = Interceptor | Array<Interceptor>;
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Default configuration for the Wonder Blocks Data adapter.
|
|
12
14
|
*/
|
|
13
|
-
export const defaultConfig =
|
|
15
|
+
export const defaultConfig = [] as Array<Interceptor>;
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* Test harness adapter to mock Wonder Blocks Data usage.
|
|
@@ -20,9 +22,9 @@ export const defaultConfig = ([]: Array<Interceptor>);
|
|
|
20
22
|
* are not overriding one another.
|
|
21
23
|
*/
|
|
22
24
|
export const adapter: TestHarnessAdapter<Config> = (
|
|
23
|
-
children: React.
|
|
25
|
+
children: React.ReactNode,
|
|
24
26
|
config: Config,
|
|
25
|
-
): React.
|
|
27
|
+
): React.ReactElement<any> => {
|
|
26
28
|
// First we render the cache intercepts.
|
|
27
29
|
let currentChildren = children;
|
|
28
30
|
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
|
|
4
|
-
import type {TestHarnessAdapter} from "../types
|
|
3
|
+
import type {TestHarnessAdapter} from "../types";
|
|
5
4
|
|
|
6
5
|
type Config = string;
|
|
7
6
|
|
|
8
7
|
// The default configuration is to omit this adapter.
|
|
9
|
-
export const defaultConfig:
|
|
8
|
+
export const defaultConfig: Config | null | undefined = null;
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* Test harness adapter for supporting portals.
|
|
@@ -16,9 +15,9 @@ export const defaultConfig: ?Config = null;
|
|
|
16
15
|
* identifier.
|
|
17
16
|
*/
|
|
18
17
|
export const adapter: TestHarnessAdapter<Config> = (
|
|
19
|
-
children: React.
|
|
18
|
+
children: React.ReactNode,
|
|
20
19
|
config: Config,
|
|
21
|
-
): React.
|
|
20
|
+
): React.ReactElement<any> => (
|
|
22
21
|
<>
|
|
23
22
|
<div id={config} data-test-id={config} />
|
|
24
23
|
{children}
|