@khanacademy/wonder-blocks-data 2.3.4 → 3.0.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.
- package/CHANGELOG.md +7 -0
- package/dist/es/index.js +212 -446
- package/dist/index.js +230 -478
- package/docs.md +19 -13
- package/package.json +2 -3
- package/src/__tests__/__snapshots__/generated-snapshot.test.js.snap +40 -160
- package/src/__tests__/generated-snapshot.test.js +15 -195
- package/src/components/__tests__/data.test.js +159 -965
- package/src/components/__tests__/intercept-data.test.js +9 -66
- package/src/components/__tests__/track-data.test.js +6 -5
- package/src/components/data.js +9 -117
- package/src/components/data.md +38 -60
- package/src/components/intercept-data.js +2 -34
- package/src/components/intercept-data.md +7 -105
- package/src/hooks/__tests__/use-data.test.js +790 -0
- package/src/hooks/use-data.js +138 -0
- package/src/index.js +1 -3
- package/src/util/__tests__/memory-cache.test.js +134 -35
- package/src/util/__tests__/request-fulfillment.test.js +21 -36
- package/src/util/__tests__/request-handler.test.js +30 -30
- package/src/util/__tests__/request-tracking.test.js +29 -30
- package/src/util/__tests__/response-cache.test.js +521 -561
- package/src/util/__tests__/result-from-cache-entry.test.js +68 -0
- package/src/util/memory-cache.js +18 -14
- package/src/util/request-fulfillment.js +4 -0
- package/src/util/request-handler.js +2 -27
- package/src/util/request-handler.md +0 -32
- package/src/util/response-cache.js +50 -110
- package/src/util/result-from-cache-entry.js +38 -0
- package/src/util/types.js +14 -35
- package/LICENSE +0 -21
- package/src/components/__tests__/intercept-cache.test.js +0 -124
- package/src/components/__tests__/internal-data.test.js +0 -1030
- package/src/components/intercept-cache.js +0 -79
- package/src/components/intercept-cache.md +0 -103
- package/src/components/internal-data.js +0 -219
- package/src/util/__tests__/no-cache.test.js +0 -112
- package/src/util/no-cache.js +0 -67
- package/src/util/no-cache.md +0 -66
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import {mount} from "enzyme";
|
|
4
|
-
|
|
5
|
-
import InterceptContext from "../intercept-context.js";
|
|
6
|
-
import InterceptData from "../intercept-data.js";
|
|
7
|
-
import InterceptCache from "../intercept-cache.js";
|
|
8
|
-
|
|
9
|
-
import type {IRequestHandler} from "../../util/types.js";
|
|
10
|
-
|
|
11
|
-
describe("InterceptCache", () => {
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
jest.resetAllMocks();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("should update context with getEntry", () => {
|
|
17
|
-
// Arrange
|
|
18
|
-
const fakeHandler: IRequestHandler<string, string> = {
|
|
19
|
-
fulfillRequest: () => Promise.resolve("data"),
|
|
20
|
-
getKey: (o) => o,
|
|
21
|
-
shouldRefreshCache: () => false,
|
|
22
|
-
type: "MY_HANDLER",
|
|
23
|
-
cache: null,
|
|
24
|
-
hydrate: true,
|
|
25
|
-
};
|
|
26
|
-
const getEntryFn = jest.fn();
|
|
27
|
-
const captureContextFn = jest.fn();
|
|
28
|
-
|
|
29
|
-
// Act
|
|
30
|
-
mount(
|
|
31
|
-
<InterceptCache handler={fakeHandler} getEntry={getEntryFn}>
|
|
32
|
-
<InterceptContext.Consumer>
|
|
33
|
-
{captureContextFn}
|
|
34
|
-
</InterceptContext.Consumer>
|
|
35
|
-
</InterceptCache>,
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
// Assert
|
|
39
|
-
expect(captureContextFn).toHaveBeenCalledWith(
|
|
40
|
-
expect.objectContaining({
|
|
41
|
-
MY_HANDLER: {
|
|
42
|
-
getEntry: getEntryFn,
|
|
43
|
-
},
|
|
44
|
-
}),
|
|
45
|
-
);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("should override parent InterceptData", () => {
|
|
49
|
-
// Arrange
|
|
50
|
-
const fakeHandler: IRequestHandler<string, string> = {
|
|
51
|
-
fulfillRequest: () => Promise.resolve("data"),
|
|
52
|
-
getKey: (o) => o,
|
|
53
|
-
shouldRefreshCache: () => false,
|
|
54
|
-
type: "MY_HANDLER",
|
|
55
|
-
cache: null,
|
|
56
|
-
hydrate: true,
|
|
57
|
-
};
|
|
58
|
-
const getEntry1Fn = jest.fn();
|
|
59
|
-
const getEntry2Fn = jest.fn();
|
|
60
|
-
const captureContextFn = jest.fn();
|
|
61
|
-
|
|
62
|
-
// Act
|
|
63
|
-
mount(
|
|
64
|
-
<InterceptCache handler={fakeHandler} getEntry={getEntry1Fn}>
|
|
65
|
-
<InterceptCache handler={fakeHandler} getEntry={getEntry2Fn}>
|
|
66
|
-
<InterceptContext.Consumer>
|
|
67
|
-
{captureContextFn}
|
|
68
|
-
</InterceptContext.Consumer>
|
|
69
|
-
</InterceptCache>
|
|
70
|
-
</InterceptCache>,
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
// Assert
|
|
74
|
-
expect(captureContextFn).toHaveBeenCalledWith(
|
|
75
|
-
expect.objectContaining({
|
|
76
|
-
MY_HANDLER: {
|
|
77
|
-
getEntry: getEntry2Fn,
|
|
78
|
-
},
|
|
79
|
-
}),
|
|
80
|
-
);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("should not change InterceptData methods on existing interceptor", () => {
|
|
84
|
-
// Arrange
|
|
85
|
-
const fakeHandler: IRequestHandler<string, string> = {
|
|
86
|
-
fulfillRequest: () => Promise.resolve("data"),
|
|
87
|
-
getKey: (o) => o,
|
|
88
|
-
shouldRefreshCache: () => false,
|
|
89
|
-
type: "MY_HANDLER",
|
|
90
|
-
cache: null,
|
|
91
|
-
hydrate: true,
|
|
92
|
-
};
|
|
93
|
-
const fulfillRequestFn = jest.fn();
|
|
94
|
-
const shouldRefreshCacheFn = jest.fn();
|
|
95
|
-
const getEntryFn = jest.fn();
|
|
96
|
-
const captureContextFn = jest.fn();
|
|
97
|
-
|
|
98
|
-
// Act
|
|
99
|
-
mount(
|
|
100
|
-
<InterceptData
|
|
101
|
-
handler={fakeHandler}
|
|
102
|
-
fulfillRequest={fulfillRequestFn}
|
|
103
|
-
shouldRefreshCache={shouldRefreshCacheFn}
|
|
104
|
-
>
|
|
105
|
-
<InterceptCache handler={fakeHandler} getEntry={getEntryFn}>
|
|
106
|
-
<InterceptContext.Consumer>
|
|
107
|
-
{captureContextFn}
|
|
108
|
-
</InterceptContext.Consumer>
|
|
109
|
-
</InterceptCache>
|
|
110
|
-
</InterceptData>,
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
// Assert
|
|
114
|
-
expect(captureContextFn).toHaveBeenCalledWith(
|
|
115
|
-
expect.objectContaining({
|
|
116
|
-
MY_HANDLER: {
|
|
117
|
-
fulfillRequest: fulfillRequestFn,
|
|
118
|
-
shouldRefreshCache: shouldRefreshCacheFn,
|
|
119
|
-
getEntry: getEntryFn,
|
|
120
|
-
},
|
|
121
|
-
}),
|
|
122
|
-
);
|
|
123
|
-
});
|
|
124
|
-
});
|