@jobber/hooks 2.17.2 → 2.17.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.
- package/dist/index.js +34 -18
- package/dist/useBool/index.js +5 -1
- package/dist/useBool/useBool.js +9 -6
- package/dist/useBool/useBool.test.js +11 -9
- package/dist/useBreakpoints/index.js +20 -2
- package/dist/useBreakpoints/mockViewportWidth/index.js +17 -1
- package/dist/useBreakpoints/mockViewportWidth/mockViewportWidth.js +6 -2
- package/dist/useBreakpoints/mockViewportWidth/mockViewportWidth.test.js +6 -4
- package/dist/useBreakpoints/useBreakpoints.js +13 -9
- package/dist/useBreakpoints/useBreakpoints.test.js +35 -30
- package/dist/useBreakpoints/useMediaQuery.js +9 -5
- package/dist/useCallbackRef/index.js +5 -1
- package/dist/useCallbackRef/useCallbackRef.js +8 -5
- package/dist/useCallbackRef/useCallbackRef.test.js +6 -4
- package/dist/useCollectionQuery/index.js +5 -1
- package/dist/useCollectionQuery/mdxUtils.js +12 -8
- package/dist/useCollectionQuery/test-utilities/index.js +19 -3
- package/dist/useCollectionQuery/test-utilities/mocks.js +30 -19
- package/dist/useCollectionQuery/test-utilities/queries.js +7 -4
- package/dist/useCollectionQuery/test-utilities/utils.js +4 -1
- package/dist/useCollectionQuery/uniqueEdges.js +6 -2
- package/dist/useCollectionQuery/uniqueNodes.js +4 -1
- package/dist/useCollectionQuery/useCollectionQuery.js +34 -27
- package/dist/useCollectionQuery/useCollectionQuery.test.js +128 -126
- package/dist/useDebounce/index.js +5 -1
- package/dist/useDebounce/useDebounce.js +11 -8
- package/dist/useDebounce/useDebounce.test.js +70 -42
- package/dist/useFocusTrap/index.js +5 -1
- package/dist/useFocusTrap/useFocusTrap.js +7 -4
- package/dist/useFocusTrap/useFocusTrap.test.js +31 -26
- package/dist/useFormState/index.js +5 -1
- package/dist/useFormState/useFormState.js +6 -3
- package/dist/useInView/index.js +17 -1
- package/dist/useInView/useInView.js +9 -6
- package/dist/useInView/useInView.test.js +17 -12
- package/dist/useIsMounted/index.js +5 -1
- package/dist/useIsMounted/useIsMounted.js +8 -5
- package/dist/useIsMounted/useIsMounted.test.js +6 -4
- package/dist/useLiveAnnounce/index.js +5 -1
- package/dist/useLiveAnnounce/useLiveAnnounce.js +7 -4
- package/dist/useLiveAnnounce/useLiveAnnounce.test.js +24 -19
- package/dist/useOnKeyDown/index.js +5 -1
- package/dist/useOnKeyDown/useOnKeyDown.js +6 -3
- package/dist/useOnKeyDown/useOnKeyDown.test.js +12 -7
- package/dist/useOnMount/index.js +5 -1
- package/dist/useOnMount/useOnMount.js +10 -6
- package/dist/useOnMount/useOnMount.test.js +6 -4
- package/dist/useRefocusOnActivator/index.js +5 -1
- package/dist/useRefocusOnActivator/useRefocusOnActivator.js +6 -3
- package/dist/useResizeObserver/index.js +17 -1
- package/dist/useResizeObserver/useResizeObserver.js +16 -9
- package/dist/useSafeLayoutEffect/index.js +5 -1
- package/dist/useSafeLayoutEffect/useSafeLayoutEffect.js +7 -4
- package/dist/useShowClear/index.js +5 -1
- package/dist/useShowClear/useShowClear.js +4 -1
- package/dist/useShowClear/useShowClear.test.js +8 -6
- package/dist/useStepper/index.js +5 -1
- package/dist/useStepper/useStepper.js +15 -9
- package/dist/useStepper/useStepper.test.js +17 -15
- package/dist/useWindowDimensions/index.js +5 -1
- package/dist/useWindowDimensions/useWIndowDimensions.test.js +8 -6
- package/dist/useWindowDimensions/useWindowDimensions.js +7 -4
- package/package.json +5 -102
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -7,17 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
9
|
});
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const react_hooks_1 = require("@testing-library/react-hooks");
|
|
13
|
+
const react_1 = require("@testing-library/react");
|
|
14
|
+
const useCollectionQuery_1 = require("./useCollectionQuery");
|
|
15
|
+
const test_utilities_1 = require("./test-utilities");
|
|
14
16
|
beforeEach(() => {
|
|
15
|
-
setListQueryMockHasNextPage(true);
|
|
16
|
-
listQueryResponseMock.mockClear();
|
|
17
|
-
subscriptionQueryMock.mockClear();
|
|
17
|
+
(0, test_utilities_1.setListQueryMockHasNextPage)(true);
|
|
18
|
+
test_utilities_1.listQueryResponseMock.mockClear();
|
|
19
|
+
test_utilities_1.subscriptionQueryMock.mockClear();
|
|
18
20
|
});
|
|
19
21
|
function useCollectionQueryHook(query) {
|
|
20
|
-
return useCollectionQuery({
|
|
22
|
+
return (0, useCollectionQuery_1.useCollectionQuery)({
|
|
21
23
|
query: query,
|
|
22
24
|
getCollectionByPath(data) {
|
|
23
25
|
var _a;
|
|
@@ -26,14 +28,14 @@ function useCollectionQueryHook(query) {
|
|
|
26
28
|
});
|
|
27
29
|
}
|
|
28
30
|
function useCollectionQueryHookWithSubscription(query) {
|
|
29
|
-
return useCollectionQuery({
|
|
31
|
+
return (0, useCollectionQuery_1.useCollectionQuery)({
|
|
30
32
|
query: query,
|
|
31
33
|
getCollectionByPath(data) {
|
|
32
34
|
var _a;
|
|
33
35
|
return (_a = data === null || data === void 0 ? void 0 : data.conversation) === null || _a === void 0 ? void 0 : _a.smsMessages;
|
|
34
36
|
},
|
|
35
37
|
subscription: {
|
|
36
|
-
document: SUBSCRIPTION_QUERY,
|
|
38
|
+
document: test_utilities_1.SUBSCRIPTION_QUERY,
|
|
37
39
|
getNodeByPath(conversationData) {
|
|
38
40
|
var _a;
|
|
39
41
|
return (_a = conversationData === null || conversationData === void 0 ? void 0 : conversationData.conversationMessage) === null || _a === void 0 ? void 0 : _a.smsMessage;
|
|
@@ -42,7 +44,7 @@ function useCollectionQueryHookWithSubscription(query) {
|
|
|
42
44
|
});
|
|
43
45
|
}
|
|
44
46
|
function useCollectionQueryHookWithSubscriptionAndSearch(query, searchTerm) {
|
|
45
|
-
return useCollectionQuery({
|
|
47
|
+
return (0, useCollectionQuery_1.useCollectionQuery)({
|
|
46
48
|
query: query,
|
|
47
49
|
queryOptions: {
|
|
48
50
|
variables: {
|
|
@@ -54,7 +56,7 @@ function useCollectionQueryHookWithSubscriptionAndSearch(query, searchTerm) {
|
|
|
54
56
|
return (_a = data === null || data === void 0 ? void 0 : data.conversation) === null || _a === void 0 ? void 0 : _a.smsMessages;
|
|
55
57
|
},
|
|
56
58
|
subscription: {
|
|
57
|
-
document: SUBSCRIPTION_QUERY,
|
|
59
|
+
document: test_utilities_1.SUBSCRIPTION_QUERY,
|
|
58
60
|
getNodeByPath(conversationData) {
|
|
59
61
|
var _a;
|
|
60
62
|
return (_a = conversationData === null || conversationData === void 0 ? void 0 : conversationData.conversationMessage) === null || _a === void 0 ? void 0 : _a.smsMessage;
|
|
@@ -65,77 +67,77 @@ function useCollectionQueryHookWithSubscriptionAndSearch(query, searchTerm) {
|
|
|
65
67
|
describe("useCollectionQuery", () => {
|
|
66
68
|
describe.each `
|
|
67
69
|
testCase | query | responseMock
|
|
68
|
-
${"excludes totalCount"} | ${LIST_QUERY} | ${listQueryResponseMock}
|
|
69
|
-
${"includes totalCount"} | ${LIST_QUERY_WITH_TOTAL_COUNT} | ${listQueryWithTotalCountResponseMock}
|
|
70
|
+
${"excludes totalCount"} | ${test_utilities_1.LIST_QUERY} | ${test_utilities_1.listQueryResponseMock}
|
|
71
|
+
${"includes totalCount"} | ${test_utilities_1.LIST_QUERY_WITH_TOTAL_COUNT} | ${test_utilities_1.listQueryWithTotalCountResponseMock}
|
|
70
72
|
`("when the query run $testCase", ({ query, responseMock }) => {
|
|
71
73
|
describe("when useCollectionQuery is first called", () => {
|
|
72
74
|
describe("when nextPage is called while it's still loading initial content", () => {
|
|
73
75
|
it("should not trigger a the next page to be fetched", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
74
|
-
const { result } = renderHook(() => useCollectionQueryHook(query), {
|
|
75
|
-
wrapper: wrapper([
|
|
76
|
-
buildListRequestMock(query, responseMock),
|
|
77
|
-
buildListRequestMockForNextPage(query, responseMock),
|
|
76
|
+
const { result } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHook(query), {
|
|
77
|
+
wrapper: (0, test_utilities_1.wrapper)([
|
|
78
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock),
|
|
79
|
+
(0, test_utilities_1.buildListRequestMockForNextPage)(query, responseMock),
|
|
78
80
|
]),
|
|
79
81
|
});
|
|
80
|
-
act(() => {
|
|
82
|
+
(0, react_hooks_1.act)(() => {
|
|
81
83
|
result.current.nextPage();
|
|
82
84
|
});
|
|
83
|
-
yield act(wait);
|
|
85
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
84
86
|
expect(responseMock).toHaveBeenCalledTimes(1);
|
|
85
87
|
}));
|
|
86
88
|
});
|
|
87
89
|
describe("when refresh is called while it's still loading initial content", () => {
|
|
88
90
|
it("should not trigger a refresh", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
-
const { result } = renderHook(() => useCollectionQueryHook(query), {
|
|
90
|
-
wrapper: wrapper([
|
|
91
|
-
buildListRequestMock(query, responseMock),
|
|
92
|
-
buildListRequestMock(query, responseMock),
|
|
91
|
+
const { result } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHook(query), {
|
|
92
|
+
wrapper: (0, test_utilities_1.wrapper)([
|
|
93
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock),
|
|
94
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock),
|
|
93
95
|
]),
|
|
94
96
|
});
|
|
95
|
-
act(() => {
|
|
97
|
+
(0, react_hooks_1.act)(() => {
|
|
96
98
|
result.current.refresh();
|
|
97
99
|
});
|
|
98
|
-
yield act(wait);
|
|
100
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
99
101
|
expect(responseMock).toHaveBeenCalledTimes(1);
|
|
100
102
|
}));
|
|
101
103
|
});
|
|
102
104
|
describe("when there is no error", () => {
|
|
103
105
|
it("should update data", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
104
106
|
var _a, _b, _c, _d;
|
|
105
|
-
const { result } = renderHook(() => useCollectionQueryHook(query), {
|
|
106
|
-
wrapper: wrapper([buildListRequestMock(query, responseMock)]),
|
|
107
|
+
const { result } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHook(query), {
|
|
108
|
+
wrapper: (0, test_utilities_1.wrapper)([(0, test_utilities_1.buildListRequestMock)(query, responseMock)]),
|
|
107
109
|
});
|
|
108
|
-
yield act(wait);
|
|
110
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
109
111
|
expect((_d = (_c = (_b = (_a = result.current.data) === null || _a === void 0 ? void 0 : _a.conversation) === null || _b === void 0 ? void 0 : _b.smsMessages) === null || _c === void 0 ? void 0 : _c.edges) === null || _d === void 0 ? void 0 : _d.length).toBe(1);
|
|
110
112
|
}));
|
|
111
113
|
it("should set initialLoading while loading data", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
112
|
-
const { result } = renderHook(() => useCollectionQueryHook(query), {
|
|
113
|
-
wrapper: wrapper([buildListRequestMock(query, responseMock)]),
|
|
114
|
+
const { result } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHook(query), {
|
|
115
|
+
wrapper: (0, test_utilities_1.wrapper)([(0, test_utilities_1.buildListRequestMock)(query, responseMock)]),
|
|
114
116
|
});
|
|
115
117
|
expect(result.current.loadingInitialContent).toBe(true);
|
|
116
|
-
yield act(wait);
|
|
118
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
117
119
|
}));
|
|
118
120
|
});
|
|
119
121
|
});
|
|
120
122
|
describe("#nextPage", () => {
|
|
121
123
|
describe("when nextPage is called while it's still loadingNextPage", () => {
|
|
122
124
|
it("should not trigger a nextPage", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
123
|
-
const { result } = renderHook(() => useCollectionQueryHook(query), {
|
|
124
|
-
wrapper: wrapper([
|
|
125
|
-
buildListRequestMock(query, responseMock),
|
|
126
|
-
buildListRequestMockForNextPage(query, responseMock),
|
|
127
|
-
buildListRequestMockForNextPage(query, responseMock),
|
|
125
|
+
const { result } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHook(query), {
|
|
126
|
+
wrapper: (0, test_utilities_1.wrapper)([
|
|
127
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock),
|
|
128
|
+
(0, test_utilities_1.buildListRequestMockForNextPage)(query, responseMock),
|
|
129
|
+
(0, test_utilities_1.buildListRequestMockForNextPage)(query, responseMock),
|
|
128
130
|
]),
|
|
129
131
|
});
|
|
130
|
-
yield act(wait);
|
|
131
|
-
act(() => {
|
|
132
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
133
|
+
(0, react_hooks_1.act)(() => {
|
|
132
134
|
result.current.nextPage();
|
|
133
135
|
});
|
|
134
|
-
act(() => {
|
|
136
|
+
(0, react_hooks_1.act)(() => {
|
|
135
137
|
result.current.nextPage();
|
|
136
138
|
});
|
|
137
|
-
yield act(wait);
|
|
138
|
-
yield waitFor(() => {
|
|
139
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
140
|
+
yield (0, react_1.waitFor)(() => {
|
|
139
141
|
var _a, _b, _c;
|
|
140
142
|
expect((_c = (_b = (_a = result.current.data) === null || _a === void 0 ? void 0 : _a.conversation) === null || _b === void 0 ? void 0 : _b.smsMessages) === null || _c === void 0 ? void 0 : _c.edges).toHaveLength(2);
|
|
141
143
|
});
|
|
@@ -143,80 +145,80 @@ describe("useCollectionQuery", () => {
|
|
|
143
145
|
});
|
|
144
146
|
describe("when refresh is called while it's still loadingNextPage", () => {
|
|
145
147
|
it("should trigger a refresh", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
146
|
-
const { result } = renderHook(() => useCollectionQueryHook(query), {
|
|
147
|
-
wrapper: wrapper([
|
|
148
|
-
buildListRequestMock(query, responseMock),
|
|
149
|
-
buildListRequestMock(query, responseMock),
|
|
150
|
-
buildListRequestMockForNextPage(query, responseMock),
|
|
148
|
+
const { result } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHook(query), {
|
|
149
|
+
wrapper: (0, test_utilities_1.wrapper)([
|
|
150
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock),
|
|
151
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock),
|
|
152
|
+
(0, test_utilities_1.buildListRequestMockForNextPage)(query, responseMock),
|
|
151
153
|
]),
|
|
152
154
|
});
|
|
153
|
-
yield act(wait);
|
|
154
|
-
act(() => {
|
|
155
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
156
|
+
(0, react_hooks_1.act)(() => {
|
|
155
157
|
result.current.nextPage();
|
|
156
158
|
});
|
|
157
|
-
act(() => {
|
|
159
|
+
(0, react_hooks_1.act)(() => {
|
|
158
160
|
result.current.refresh();
|
|
159
161
|
});
|
|
160
162
|
expect(result.current.loadingRefresh).toBe(true);
|
|
161
|
-
yield act(wait);
|
|
163
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
162
164
|
}));
|
|
163
165
|
});
|
|
164
166
|
describe("when there is no more data to fetch", () => {
|
|
165
167
|
it("should not fetch more data", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
166
|
-
setListQueryMockHasNextPage(false);
|
|
167
|
-
const { result } = renderHook(() => useCollectionQueryHook(query), {
|
|
168
|
-
wrapper: wrapper([
|
|
169
|
-
buildListRequestMock(query, responseMock),
|
|
170
|
-
buildListRequestMockForNextPage(query, responseMock),
|
|
168
|
+
(0, test_utilities_1.setListQueryMockHasNextPage)(false);
|
|
169
|
+
const { result } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHook(query), {
|
|
170
|
+
wrapper: (0, test_utilities_1.wrapper)([
|
|
171
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock),
|
|
172
|
+
(0, test_utilities_1.buildListRequestMockForNextPage)(query, responseMock),
|
|
171
173
|
]),
|
|
172
174
|
});
|
|
173
|
-
yield act(wait);
|
|
174
|
-
act(() => {
|
|
175
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
176
|
+
(0, react_hooks_1.act)(() => {
|
|
175
177
|
result.current.nextPage();
|
|
176
178
|
});
|
|
177
|
-
yield act(wait);
|
|
179
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
178
180
|
expect(responseMock).toHaveBeenCalledTimes(1);
|
|
179
181
|
}));
|
|
180
182
|
});
|
|
181
183
|
describe("when there is no error", () => {
|
|
182
184
|
it("should update data", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
183
|
-
const { result } = renderHook(() => useCollectionQueryHook(query), {
|
|
184
|
-
wrapper: wrapper([
|
|
185
|
-
buildListRequestMock(query, responseMock),
|
|
186
|
-
buildListRequestMockForNextPage(query, responseMock),
|
|
185
|
+
const { result } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHook(query), {
|
|
186
|
+
wrapper: (0, test_utilities_1.wrapper)([
|
|
187
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock),
|
|
188
|
+
(0, test_utilities_1.buildListRequestMockForNextPage)(query, responseMock),
|
|
187
189
|
]),
|
|
188
190
|
});
|
|
189
|
-
yield act(wait);
|
|
190
|
-
act(() => {
|
|
191
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
192
|
+
(0, react_hooks_1.act)(() => {
|
|
191
193
|
result.current.nextPage();
|
|
192
194
|
});
|
|
193
|
-
yield act(wait);
|
|
194
|
-
yield waitFor(() => {
|
|
195
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
196
|
+
yield (0, react_1.waitFor)(() => {
|
|
195
197
|
var _a, _b, _c;
|
|
196
198
|
expect((_c = (_b = (_a = result.current.data) === null || _a === void 0 ? void 0 : _a.conversation) === null || _b === void 0 ? void 0 : _b.smsMessages) === null || _c === void 0 ? void 0 : _c.edges).toHaveLength(2);
|
|
197
199
|
});
|
|
198
200
|
}));
|
|
199
201
|
it("should set loadingNextPage while loading data", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
200
|
-
const { result } = renderHook(() => useCollectionQueryHook(query), {
|
|
201
|
-
wrapper: wrapper([
|
|
202
|
-
buildListRequestMock(query, responseMock),
|
|
203
|
-
buildListRequestMockForNextPage(query, responseMock),
|
|
202
|
+
const { result } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHook(query), {
|
|
203
|
+
wrapper: (0, test_utilities_1.wrapper)([
|
|
204
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock),
|
|
205
|
+
(0, test_utilities_1.buildListRequestMockForNextPage)(query, responseMock),
|
|
204
206
|
]),
|
|
205
207
|
});
|
|
206
|
-
yield act(wait);
|
|
207
|
-
act(() => {
|
|
208
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
209
|
+
(0, react_hooks_1.act)(() => {
|
|
208
210
|
result.current.nextPage();
|
|
209
211
|
});
|
|
210
212
|
expect(result.current.loadingNextPage).toBe(true);
|
|
211
|
-
yield act(wait);
|
|
213
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
212
214
|
}));
|
|
213
215
|
});
|
|
214
216
|
describe("when there is an error", () => {
|
|
215
217
|
it("should update the error state", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
216
218
|
const mockError = new Error("Failed to fetch more items");
|
|
217
|
-
const { result } = renderHook(() => useCollectionQueryHook(query), {
|
|
218
|
-
wrapper: wrapper([
|
|
219
|
-
buildListRequestMock(query, responseMock),
|
|
219
|
+
const { result } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHook(query), {
|
|
220
|
+
wrapper: (0, test_utilities_1.wrapper)([
|
|
221
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock),
|
|
220
222
|
{
|
|
221
223
|
request: {
|
|
222
224
|
query: query,
|
|
@@ -224,20 +226,20 @@ describe("useCollectionQuery", () => {
|
|
|
224
226
|
},
|
|
225
227
|
error: mockError,
|
|
226
228
|
},
|
|
227
|
-
buildListRequestMockForNextPage(query, responseMock),
|
|
229
|
+
(0, test_utilities_1.buildListRequestMockForNextPage)(query, responseMock),
|
|
228
230
|
]),
|
|
229
231
|
});
|
|
230
|
-
yield act(wait);
|
|
231
|
-
act(() => {
|
|
232
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
233
|
+
(0, react_hooks_1.act)(() => {
|
|
232
234
|
result.current.nextPage();
|
|
233
235
|
});
|
|
234
|
-
yield act(wait);
|
|
236
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
235
237
|
expect(result.current.error).toEqual(mockError);
|
|
236
238
|
// should clear the error after a successful fetch
|
|
237
|
-
act(() => {
|
|
239
|
+
(0, react_hooks_1.act)(() => {
|
|
238
240
|
result.current.nextPage();
|
|
239
241
|
});
|
|
240
|
-
yield act(wait);
|
|
242
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
241
243
|
expect(result.current.error).toBeUndefined();
|
|
242
244
|
}));
|
|
243
245
|
});
|
|
@@ -245,58 +247,58 @@ describe("useCollectionQuery", () => {
|
|
|
245
247
|
describe("#refresh", () => {
|
|
246
248
|
describe("when refresh is called while it's still loadingRefresh", () => {
|
|
247
249
|
it("should not trigger a refresh", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
248
|
-
const { result } = renderHook(() => useCollectionQueryHook(query), {
|
|
249
|
-
wrapper: wrapper([
|
|
250
|
-
buildListRequestMock(query, responseMock),
|
|
251
|
-
buildListRequestMock(query, responseMock),
|
|
252
|
-
buildListRequestMock(query, responseMock),
|
|
250
|
+
const { result } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHook(query), {
|
|
251
|
+
wrapper: (0, test_utilities_1.wrapper)([
|
|
252
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock),
|
|
253
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock),
|
|
254
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock),
|
|
253
255
|
]),
|
|
254
256
|
});
|
|
255
|
-
yield act(wait);
|
|
256
|
-
act(() => {
|
|
257
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
258
|
+
(0, react_hooks_1.act)(() => {
|
|
257
259
|
result.current.refresh();
|
|
258
260
|
});
|
|
259
|
-
act(() => {
|
|
261
|
+
(0, react_hooks_1.act)(() => {
|
|
260
262
|
result.current.refresh();
|
|
261
263
|
});
|
|
262
|
-
yield act(wait);
|
|
264
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
263
265
|
expect(responseMock).toHaveBeenCalledTimes(2);
|
|
264
266
|
}));
|
|
265
267
|
});
|
|
266
268
|
describe("when nextPage is called while it's still loadingRefresh", () => {
|
|
267
269
|
it("should not trigger a nextPage", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
268
|
-
const { result } = renderHook(() => useCollectionQueryHook(query), {
|
|
269
|
-
wrapper: wrapper([
|
|
270
|
-
buildListRequestMock(query, responseMock),
|
|
271
|
-
buildListRequestMock(query, responseMock),
|
|
272
|
-
buildListRequestMockForNextPage(query, responseMock),
|
|
270
|
+
const { result } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHook(query), {
|
|
271
|
+
wrapper: (0, test_utilities_1.wrapper)([
|
|
272
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock),
|
|
273
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock),
|
|
274
|
+
(0, test_utilities_1.buildListRequestMockForNextPage)(query, responseMock),
|
|
273
275
|
]),
|
|
274
276
|
});
|
|
275
|
-
yield act(wait);
|
|
276
|
-
act(() => {
|
|
277
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
278
|
+
(0, react_hooks_1.act)(() => {
|
|
277
279
|
result.current.refresh();
|
|
278
280
|
});
|
|
279
|
-
act(() => {
|
|
281
|
+
(0, react_hooks_1.act)(() => {
|
|
280
282
|
result.current.nextPage();
|
|
281
283
|
});
|
|
282
284
|
expect(result.current.loadingNextPage).toBe(false);
|
|
283
|
-
yield act(wait);
|
|
285
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
284
286
|
}));
|
|
285
287
|
});
|
|
286
288
|
describe("when there is no error", () => {
|
|
287
289
|
it("should set loadingRefresh while loading data", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
288
|
-
const { result } = renderHook(() => useCollectionQueryHook(query), {
|
|
289
|
-
wrapper: wrapper([
|
|
290
|
-
buildListRequestMock(query, responseMock),
|
|
291
|
-
buildListRequestMock(query, responseMock),
|
|
290
|
+
const { result } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHook(query), {
|
|
291
|
+
wrapper: (0, test_utilities_1.wrapper)([
|
|
292
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock),
|
|
293
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock),
|
|
292
294
|
]),
|
|
293
295
|
});
|
|
294
|
-
yield act(wait);
|
|
295
|
-
act(() => {
|
|
296
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
297
|
+
(0, react_hooks_1.act)(() => {
|
|
296
298
|
result.current.refresh();
|
|
297
299
|
});
|
|
298
300
|
expect(result.current.loadingRefresh).toBe(true);
|
|
299
|
-
yield act(wait);
|
|
301
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
300
302
|
}));
|
|
301
303
|
});
|
|
302
304
|
});
|
|
@@ -304,32 +306,32 @@ describe("useCollectionQuery", () => {
|
|
|
304
306
|
describe("when hook receives update from item not in collection", () => {
|
|
305
307
|
it("should add new item to collection", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
306
308
|
var _a, _b, _c, _d, _e;
|
|
307
|
-
const { result, waitForNextUpdate } = renderHook(() => useCollectionQueryHookWithSubscription(query), {
|
|
308
|
-
wrapper: wrapper([
|
|
309
|
-
buildListRequestMock(query, responseMock, "1"),
|
|
310
|
-
buildSubscriptionRequestMock("2"),
|
|
309
|
+
const { result, waitForNextUpdate } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHookWithSubscription(query), {
|
|
310
|
+
wrapper: (0, test_utilities_1.wrapper)([
|
|
311
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock, "1"),
|
|
312
|
+
(0, test_utilities_1.buildSubscriptionRequestMock)("2"),
|
|
311
313
|
]),
|
|
312
314
|
});
|
|
313
315
|
// Wait for initial load
|
|
314
|
-
yield act(waitForNextUpdate);
|
|
316
|
+
yield (0, react_hooks_1.act)(waitForNextUpdate);
|
|
315
317
|
// Wait for subscription
|
|
316
|
-
yield act(waitForNextUpdate);
|
|
318
|
+
yield (0, react_hooks_1.act)(waitForNextUpdate);
|
|
317
319
|
expect((_e = (_d = (_c = (_b = (_a = result === null || result === void 0 ? void 0 : result.current) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.conversation) === null || _c === void 0 ? void 0 : _c.smsMessages) === null || _d === void 0 ? void 0 : _d.edges) === null || _e === void 0 ? void 0 : _e.length).toBe(2);
|
|
318
320
|
}));
|
|
319
321
|
});
|
|
320
322
|
describe("when hook receives update from item already in collection", () => {
|
|
321
323
|
it("should return the existing collection", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
322
324
|
var _a, _b, _c, _d, _e;
|
|
323
|
-
const { result, waitForNextUpdate } = renderHook(() => useCollectionQueryHookWithSubscription(query), {
|
|
324
|
-
wrapper: wrapper([
|
|
325
|
-
buildListRequestMock(query, responseMock, "1"),
|
|
326
|
-
buildSubscriptionRequestMock("1"),
|
|
325
|
+
const { result, waitForNextUpdate } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHookWithSubscription(query), {
|
|
326
|
+
wrapper: (0, test_utilities_1.wrapper)([
|
|
327
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock, "1"),
|
|
328
|
+
(0, test_utilities_1.buildSubscriptionRequestMock)("1"),
|
|
327
329
|
]),
|
|
328
330
|
});
|
|
329
331
|
// Wait for initial load
|
|
330
|
-
yield act(waitForNextUpdate);
|
|
332
|
+
yield (0, react_hooks_1.act)(waitForNextUpdate);
|
|
331
333
|
// Wait for subscription
|
|
332
|
-
yield act(() => wait(200));
|
|
334
|
+
yield (0, react_hooks_1.act)(() => (0, test_utilities_1.wait)(200));
|
|
333
335
|
expect((_e = (_d = (_c = (_b = (_a = result === null || result === void 0 ? void 0 : result.current) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.conversation) === null || _c === void 0 ? void 0 : _c.smsMessages) === null || _d === void 0 ? void 0 : _d.edges) === null || _e === void 0 ? void 0 : _e.length).toBe(1);
|
|
334
336
|
}));
|
|
335
337
|
});
|
|
@@ -337,16 +339,16 @@ describe("useCollectionQuery", () => {
|
|
|
337
339
|
it("should return the existing collection without adding the subscribed content", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
338
340
|
var _a, _b, _c, _d, _e;
|
|
339
341
|
const searchTerm = "FooBar";
|
|
340
|
-
const { result, waitForNextUpdate } = renderHook(() => useCollectionQueryHookWithSubscriptionAndSearch(query, searchTerm), {
|
|
341
|
-
wrapper: wrapper([
|
|
342
|
-
buildListRequestMock(query, responseMock, "1", searchTerm),
|
|
343
|
-
buildSubscriptionRequestMock("1"),
|
|
342
|
+
const { result, waitForNextUpdate } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHookWithSubscriptionAndSearch(query, searchTerm), {
|
|
343
|
+
wrapper: (0, test_utilities_1.wrapper)([
|
|
344
|
+
(0, test_utilities_1.buildListRequestMock)(query, responseMock, "1", searchTerm),
|
|
345
|
+
(0, test_utilities_1.buildSubscriptionRequestMock)("1"),
|
|
344
346
|
]),
|
|
345
347
|
});
|
|
346
348
|
// Wait for initial load
|
|
347
|
-
yield act(waitForNextUpdate);
|
|
349
|
+
yield (0, react_hooks_1.act)(waitForNextUpdate);
|
|
348
350
|
// Wait for subscription
|
|
349
|
-
yield act(() => wait(200));
|
|
351
|
+
yield (0, react_hooks_1.act)(() => (0, test_utilities_1.wait)(200));
|
|
350
352
|
expect((_e = (_d = (_c = (_b = (_a = result === null || result === void 0 ? void 0 : result.current) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.conversation) === null || _c === void 0 ? void 0 : _c.smsMessages) === null || _d === void 0 ? void 0 : _d.edges) === null || _e === void 0 ? void 0 : _e.length).toBe(1);
|
|
351
353
|
}));
|
|
352
354
|
});
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDebounce = void 0;
|
|
4
|
+
var useDebounce_1 = require("./useDebounce");
|
|
5
|
+
Object.defineProperty(exports, "useDebounce", { enumerable: true, get: function () { return useDebounce_1.useDebounce; } });
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDebounce = useDebounce;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const es_toolkit_1 = require("es-toolkit");
|
|
6
|
+
const useCallbackRef_1 = require("../useCallbackRef");
|
|
4
7
|
/**
|
|
5
8
|
* A hook to easily manage debounced functions, including their cleanup.
|
|
6
9
|
* @param func The function to debounce.
|
|
@@ -8,17 +11,17 @@ import { useCallbackRef } from "../useCallbackRef";
|
|
|
8
11
|
* @param options Optional debounce settings.
|
|
9
12
|
* @returns The debounced function.
|
|
10
13
|
*/
|
|
11
|
-
|
|
12
|
-
const funcRef = useCallbackRef(func);
|
|
14
|
+
function useDebounce(func, wait, options) {
|
|
15
|
+
const funcRef = (0, useCallbackRef_1.useCallbackRef)(func);
|
|
13
16
|
// Note: do not add additional dependencies! There is currently no use case where we would change
|
|
14
17
|
// the wait delay or options between renders. By not tracking as dependencies, this allows
|
|
15
18
|
// consumers of useDebounce to provide a raw object for options rather than forcing them to
|
|
16
19
|
// memoize that param. Same with the func they provide, we're using a ref to keep that up
|
|
17
20
|
// to date and to avoid forcing the consumer to memoize it.
|
|
18
|
-
const debounced = useMemo(() => {
|
|
19
|
-
return debounce((...args) => funcRef(...args), wait, options);
|
|
21
|
+
const debounced = (0, react_1.useMemo)(() => {
|
|
22
|
+
return (0, es_toolkit_1.debounce)((...args) => funcRef(...args), wait, options);
|
|
20
23
|
}, [funcRef]);
|
|
21
|
-
useEffect(() => {
|
|
24
|
+
(0, react_1.useEffect)(() => {
|
|
22
25
|
// If the debounced function is recreated (or unmounted), cancel the last call.
|
|
23
26
|
return () => debounced.cancel();
|
|
24
27
|
}, [debounced]);
|