@jobber/hooks 1.10.0 → 1.12.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 +22 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/useCollectionQuery/mdxUtils.d.ts +1 -1
- package/dist/useCollectionQuery/mdxUtils.js +1 -1
- package/dist/useCollectionQuery/test-utilities/mocks.d.ts +34 -59
- package/dist/useCollectionQuery/test-utilities/mocks.js +38 -6
- package/dist/useCollectionQuery/test-utilities/queries.d.ts +2 -1
- package/dist/useCollectionQuery/test-utilities/queries.js +4 -3
- package/dist/useCollectionQuery/useCollectionQuery.d.ts +1 -1
- package/dist/useCollectionQuery/useCollectionQuery.js +8 -8
- package/dist/useCollectionQuery/useCollectionQuery.test.js +415 -397
- package/dist/useLiveAnnounce/index.d.ts +1 -0
- package/dist/useLiveAnnounce/index.js +4 -0
- package/dist/useLiveAnnounce/useLiveAnnounce.d.ts +8 -0
- package/dist/useLiveAnnounce/useLiveAnnounce.js +57 -0
- package/dist/useLiveAnnounce/useLiveAnnounce.test.d.ts +1 -0
- package/dist/useLiveAnnounce/useLiveAnnounce.test.js +121 -0
- package/package.json +2 -3
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
+
return cooked;
|
|
5
|
+
};
|
|
2
6
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
7
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
8
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -44,18 +48,18 @@ beforeEach(function () {
|
|
|
44
48
|
test_utilities_1.listQueryResponseMock.mockClear();
|
|
45
49
|
test_utilities_1.subscriptionQueryMock.mockClear();
|
|
46
50
|
});
|
|
47
|
-
function useCollectionQueryHook() {
|
|
51
|
+
function useCollectionQueryHook(query) {
|
|
48
52
|
return useCollectionQuery_1.useCollectionQuery({
|
|
49
|
-
query:
|
|
53
|
+
query: query,
|
|
50
54
|
getCollectionByPath: function (data) {
|
|
51
55
|
var _a;
|
|
52
56
|
return (_a = data === null || data === void 0 ? void 0 : data.conversation) === null || _a === void 0 ? void 0 : _a.smsMessages;
|
|
53
57
|
},
|
|
54
58
|
});
|
|
55
59
|
}
|
|
56
|
-
function useCollectionQueryHookWithSubscription() {
|
|
60
|
+
function useCollectionQueryHookWithSubscription(query) {
|
|
57
61
|
return useCollectionQuery_1.useCollectionQuery({
|
|
58
|
-
query:
|
|
62
|
+
query: query,
|
|
59
63
|
getCollectionByPath: function (data) {
|
|
60
64
|
var _a;
|
|
61
65
|
return (_a = data === null || data === void 0 ? void 0 : data.conversation) === null || _a === void 0 ? void 0 : _a.smsMessages;
|
|
@@ -69,9 +73,9 @@ function useCollectionQueryHookWithSubscription() {
|
|
|
69
73
|
},
|
|
70
74
|
});
|
|
71
75
|
}
|
|
72
|
-
function useCollectionQueryHookWithSubscriptionAndSearch(searchTerm) {
|
|
76
|
+
function useCollectionQueryHookWithSubscriptionAndSearch(query, searchTerm) {
|
|
73
77
|
return useCollectionQuery_1.useCollectionQuery({
|
|
74
|
-
query:
|
|
78
|
+
query: query,
|
|
75
79
|
queryOptions: {
|
|
76
80
|
variables: {
|
|
77
81
|
searchTerm: searchTerm,
|
|
@@ -90,409 +94,423 @@ function useCollectionQueryHookWithSubscriptionAndSearch(searchTerm) {
|
|
|
90
94
|
},
|
|
91
95
|
});
|
|
92
96
|
}
|
|
93
|
-
describe("
|
|
94
|
-
describe("
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
97
|
+
describe("useCollectionQuery", function () {
|
|
98
|
+
describe.each(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n testCase | query | responseMock\n ", " | ", " | ", "\n ", " | ", " | ", "\n "], ["\n testCase | query | responseMock\n ", " | ", " | ", "\n ", " | ", " | ", "\n "])), "excludes totalCount", test_utilities_1.LIST_QUERY, test_utilities_1.listQueryResponseMock, "includes totalCount", test_utilities_1.LIST_QUERY_WITH_TOTAL_COUNT, test_utilities_1.listQueryWithTotalCountResponseMock)("when the query run $testCase", function (_a) {
|
|
99
|
+
var query = _a.query, responseMock = _a.responseMock;
|
|
100
|
+
describe("when useCollectionQuery is first called", function () {
|
|
101
|
+
describe("when nextPage is called while it's still loading initial content", function () {
|
|
102
|
+
it("should not trigger a the next page to be fetched", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
103
|
+
var result;
|
|
104
|
+
return __generator(this, function (_a) {
|
|
105
|
+
switch (_a.label) {
|
|
106
|
+
case 0:
|
|
107
|
+
result = react_hooks_1.renderHook(function () { return useCollectionQueryHook(query); }, {
|
|
108
|
+
wrapper: test_utilities_1.wrapper([
|
|
109
|
+
test_utilities_1.buildListRequestMock(query, responseMock),
|
|
110
|
+
test_utilities_1.buildListRequestMockForNextPage(query, responseMock),
|
|
111
|
+
]),
|
|
112
|
+
}).result;
|
|
113
|
+
react_hooks_1.act(function () {
|
|
114
|
+
result.current.nextPage();
|
|
115
|
+
});
|
|
116
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
117
|
+
case 1:
|
|
118
|
+
_a.sent();
|
|
119
|
+
expect(responseMock).toHaveBeenCalledTimes(1);
|
|
120
|
+
return [2 /*return*/];
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}); });
|
|
115
124
|
});
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
125
|
+
describe("when refresh is called while it's still loading initial content", function () {
|
|
126
|
+
it("should not trigger a refresh", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
127
|
+
var result;
|
|
128
|
+
return __generator(this, function (_a) {
|
|
129
|
+
switch (_a.label) {
|
|
130
|
+
case 0:
|
|
131
|
+
result = react_hooks_1.renderHook(function () { return useCollectionQueryHook(query); }, {
|
|
132
|
+
wrapper: test_utilities_1.wrapper([
|
|
133
|
+
test_utilities_1.buildListRequestMock(query, responseMock),
|
|
134
|
+
test_utilities_1.buildListRequestMock(query, responseMock),
|
|
135
|
+
]),
|
|
136
|
+
}).result;
|
|
137
|
+
react_hooks_1.act(function () {
|
|
138
|
+
result.current.refresh();
|
|
139
|
+
});
|
|
140
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
141
|
+
case 1:
|
|
142
|
+
_a.sent();
|
|
143
|
+
expect(responseMock).toHaveBeenCalledTimes(1);
|
|
144
|
+
return [2 /*return*/];
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}); });
|
|
136
148
|
});
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
149
|
+
describe("when there is no error", function () {
|
|
150
|
+
it("should update data", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
151
|
+
var result;
|
|
152
|
+
var _a, _b, _c, _d;
|
|
153
|
+
return __generator(this, function (_e) {
|
|
154
|
+
switch (_e.label) {
|
|
155
|
+
case 0:
|
|
156
|
+
result = react_hooks_1.renderHook(function () { return useCollectionQueryHook(query); }, {
|
|
157
|
+
wrapper: test_utilities_1.wrapper([test_utilities_1.buildListRequestMock(query, responseMock)]),
|
|
158
|
+
}).result;
|
|
159
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
160
|
+
case 1:
|
|
161
|
+
_e.sent();
|
|
162
|
+
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);
|
|
163
|
+
return [2 /*return*/];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}); });
|
|
167
|
+
it("should set initialLoading while loading data", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
168
|
+
var result;
|
|
169
|
+
return __generator(this, function (_a) {
|
|
170
|
+
switch (_a.label) {
|
|
171
|
+
case 0:
|
|
172
|
+
result = react_hooks_1.renderHook(function () { return useCollectionQueryHook(query); }, {
|
|
173
|
+
wrapper: test_utilities_1.wrapper([test_utilities_1.buildListRequestMock(query, responseMock)]),
|
|
174
|
+
}).result;
|
|
175
|
+
expect(result.current.loadingInitialContent).toBe(true);
|
|
176
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
177
|
+
case 1:
|
|
178
|
+
_a.sent();
|
|
179
|
+
return [2 /*return*/];
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}); });
|
|
155
183
|
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
184
|
+
});
|
|
185
|
+
describe("#nextPage", function () {
|
|
186
|
+
describe("when nextPage is called while it's still loadingNextPage", function () {
|
|
187
|
+
it("should not trigger a nextPage", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
188
|
+
var result;
|
|
189
|
+
var _a, _b, _c, _d;
|
|
190
|
+
return __generator(this, function (_e) {
|
|
191
|
+
switch (_e.label) {
|
|
192
|
+
case 0:
|
|
193
|
+
result = react_hooks_1.renderHook(function () { return useCollectionQueryHook(query); }, {
|
|
194
|
+
wrapper: test_utilities_1.wrapper([
|
|
195
|
+
test_utilities_1.buildListRequestMock(query, responseMock),
|
|
196
|
+
test_utilities_1.buildListRequestMockForNextPage(query, responseMock),
|
|
197
|
+
test_utilities_1.buildListRequestMockForNextPage(query, responseMock),
|
|
198
|
+
]),
|
|
199
|
+
}).result;
|
|
200
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
201
|
+
case 1:
|
|
202
|
+
_e.sent();
|
|
203
|
+
react_hooks_1.act(function () {
|
|
204
|
+
result.current.nextPage();
|
|
205
|
+
});
|
|
206
|
+
react_hooks_1.act(function () {
|
|
207
|
+
result.current.nextPage();
|
|
208
|
+
});
|
|
209
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
210
|
+
case 2:
|
|
211
|
+
_e.sent();
|
|
212
|
+
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(2);
|
|
213
|
+
return [2 /*return*/];
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}); });
|
|
171
217
|
});
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
test_utilities_1.
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
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(2);
|
|
203
|
-
return [2 /*return*/];
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
}); });
|
|
207
|
-
});
|
|
208
|
-
describe("when refresh is called while it's still loadingNextPage", function () {
|
|
209
|
-
it("should trigger a refresh", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
210
|
-
var result;
|
|
211
|
-
return __generator(this, function (_a) {
|
|
212
|
-
switch (_a.label) {
|
|
213
|
-
case 0:
|
|
214
|
-
result = react_hooks_1.renderHook(function () { return useCollectionQueryHook(); }, {
|
|
215
|
-
wrapper: test_utilities_1.wrapper([
|
|
216
|
-
test_utilities_1.buildListRequestMock(),
|
|
217
|
-
test_utilities_1.buildListRequestMock(),
|
|
218
|
-
test_utilities_1.buildListRequestMockForNextPage(),
|
|
219
|
-
]),
|
|
220
|
-
}).result;
|
|
221
|
-
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
222
|
-
case 1:
|
|
223
|
-
_a.sent();
|
|
224
|
-
react_hooks_1.act(function () {
|
|
225
|
-
result.current.nextPage();
|
|
226
|
-
});
|
|
227
|
-
react_hooks_1.act(function () {
|
|
228
|
-
result.current.refresh();
|
|
229
|
-
});
|
|
230
|
-
expect(result.current.loadingRefresh).toBe(true);
|
|
231
|
-
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
232
|
-
case 2:
|
|
233
|
-
_a.sent();
|
|
234
|
-
return [2 /*return*/];
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
}); });
|
|
238
|
-
});
|
|
239
|
-
describe("when there is no more data to fetch", function () {
|
|
240
|
-
it("should not fetch more data", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
241
|
-
var result;
|
|
242
|
-
return __generator(this, function (_a) {
|
|
243
|
-
switch (_a.label) {
|
|
244
|
-
case 0:
|
|
245
|
-
test_utilities_1.setListQueryMockHasNextPage(false);
|
|
246
|
-
result = react_hooks_1.renderHook(function () { return useCollectionQueryHook(); }, {
|
|
247
|
-
wrapper: test_utilities_1.wrapper([
|
|
248
|
-
test_utilities_1.buildListRequestMock(),
|
|
249
|
-
test_utilities_1.buildListRequestMockForNextPage(),
|
|
250
|
-
]),
|
|
251
|
-
}).result;
|
|
252
|
-
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
253
|
-
case 1:
|
|
254
|
-
_a.sent();
|
|
255
|
-
react_hooks_1.act(function () {
|
|
256
|
-
result.current.nextPage();
|
|
257
|
-
});
|
|
258
|
-
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
259
|
-
case 2:
|
|
260
|
-
_a.sent();
|
|
261
|
-
expect(test_utilities_1.listQueryResponseMock).toHaveBeenCalledTimes(1);
|
|
262
|
-
return [2 /*return*/];
|
|
263
|
-
}
|
|
218
|
+
describe("when refresh is called while it's still loadingNextPage", function () {
|
|
219
|
+
it("should trigger a refresh", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
220
|
+
var result;
|
|
221
|
+
return __generator(this, function (_a) {
|
|
222
|
+
switch (_a.label) {
|
|
223
|
+
case 0:
|
|
224
|
+
result = react_hooks_1.renderHook(function () { return useCollectionQueryHook(query); }, {
|
|
225
|
+
wrapper: test_utilities_1.wrapper([
|
|
226
|
+
test_utilities_1.buildListRequestMock(query, responseMock),
|
|
227
|
+
test_utilities_1.buildListRequestMock(query, responseMock),
|
|
228
|
+
test_utilities_1.buildListRequestMockForNextPage(query, responseMock),
|
|
229
|
+
]),
|
|
230
|
+
}).result;
|
|
231
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
232
|
+
case 1:
|
|
233
|
+
_a.sent();
|
|
234
|
+
react_hooks_1.act(function () {
|
|
235
|
+
result.current.nextPage();
|
|
236
|
+
});
|
|
237
|
+
react_hooks_1.act(function () {
|
|
238
|
+
result.current.refresh();
|
|
239
|
+
});
|
|
240
|
+
expect(result.current.loadingRefresh).toBe(true);
|
|
241
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
242
|
+
case 2:
|
|
243
|
+
_a.sent();
|
|
244
|
+
return [2 /*return*/];
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}); });
|
|
264
248
|
});
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
249
|
+
describe("when there is no more data to fetch", function () {
|
|
250
|
+
it("should not fetch more data", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
251
|
+
var result;
|
|
252
|
+
return __generator(this, function (_a) {
|
|
253
|
+
switch (_a.label) {
|
|
254
|
+
case 0:
|
|
255
|
+
test_utilities_1.setListQueryMockHasNextPage(false);
|
|
256
|
+
result = react_hooks_1.renderHook(function () { return useCollectionQueryHook(query); }, {
|
|
257
|
+
wrapper: test_utilities_1.wrapper([
|
|
258
|
+
test_utilities_1.buildListRequestMock(query, responseMock),
|
|
259
|
+
test_utilities_1.buildListRequestMockForNextPage(query, responseMock),
|
|
260
|
+
]),
|
|
261
|
+
}).result;
|
|
262
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
263
|
+
case 1:
|
|
264
|
+
_a.sent();
|
|
265
|
+
react_hooks_1.act(function () {
|
|
266
|
+
result.current.nextPage();
|
|
267
|
+
});
|
|
268
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
269
|
+
case 2:
|
|
270
|
+
_a.sent();
|
|
271
|
+
expect(responseMock).toHaveBeenCalledTimes(1);
|
|
272
|
+
return [2 /*return*/];
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}); });
|
|
292
276
|
});
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
277
|
+
describe("when there is no error", function () {
|
|
278
|
+
it("should update data", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
279
|
+
var result;
|
|
280
|
+
var _a, _b, _c, _d;
|
|
281
|
+
return __generator(this, function (_e) {
|
|
282
|
+
switch (_e.label) {
|
|
283
|
+
case 0:
|
|
284
|
+
result = react_hooks_1.renderHook(function () { return useCollectionQueryHook(query); }, {
|
|
285
|
+
wrapper: test_utilities_1.wrapper([
|
|
286
|
+
test_utilities_1.buildListRequestMock(query, responseMock),
|
|
287
|
+
test_utilities_1.buildListRequestMockForNextPage(query, responseMock),
|
|
288
|
+
]),
|
|
289
|
+
}).result;
|
|
290
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
291
|
+
case 1:
|
|
292
|
+
_e.sent();
|
|
293
|
+
react_hooks_1.act(function () {
|
|
294
|
+
result.current.nextPage();
|
|
295
|
+
});
|
|
296
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
297
|
+
case 2:
|
|
298
|
+
_e.sent();
|
|
299
|
+
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(2);
|
|
300
|
+
return [2 /*return*/];
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}); });
|
|
304
|
+
it("should set loadingNextPage while loading data", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
305
|
+
var result;
|
|
306
|
+
return __generator(this, function (_a) {
|
|
307
|
+
switch (_a.label) {
|
|
308
|
+
case 0:
|
|
309
|
+
result = react_hooks_1.renderHook(function () { return useCollectionQueryHook(query); }, {
|
|
310
|
+
wrapper: test_utilities_1.wrapper([
|
|
311
|
+
test_utilities_1.buildListRequestMock(query, responseMock),
|
|
312
|
+
test_utilities_1.buildListRequestMockForNextPage(query, responseMock),
|
|
313
|
+
]),
|
|
314
|
+
}).result;
|
|
315
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
316
|
+
case 1:
|
|
317
|
+
_a.sent();
|
|
318
|
+
react_hooks_1.act(function () {
|
|
319
|
+
result.current.nextPage();
|
|
320
|
+
});
|
|
321
|
+
expect(result.current.loadingNextPage).toBe(true);
|
|
322
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
323
|
+
case 2:
|
|
324
|
+
_a.sent();
|
|
325
|
+
return [2 /*return*/];
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
}); });
|
|
317
329
|
});
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}
|
|
330
|
+
});
|
|
331
|
+
describe("#refresh", function () {
|
|
332
|
+
describe("when refresh is called while it's still loadingRefresh", function () {
|
|
333
|
+
it("should not trigger a refresh", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
334
|
+
var result;
|
|
335
|
+
return __generator(this, function (_a) {
|
|
336
|
+
switch (_a.label) {
|
|
337
|
+
case 0:
|
|
338
|
+
result = react_hooks_1.renderHook(function () { return useCollectionQueryHook(query); }, {
|
|
339
|
+
wrapper: test_utilities_1.wrapper([
|
|
340
|
+
test_utilities_1.buildListRequestMock(query, responseMock),
|
|
341
|
+
test_utilities_1.buildListRequestMock(query, responseMock),
|
|
342
|
+
test_utilities_1.buildListRequestMock(query, responseMock),
|
|
343
|
+
]),
|
|
344
|
+
}).result;
|
|
345
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
346
|
+
case 1:
|
|
347
|
+
_a.sent();
|
|
348
|
+
react_hooks_1.act(function () {
|
|
349
|
+
result.current.refresh();
|
|
350
|
+
});
|
|
351
|
+
react_hooks_1.act(function () {
|
|
352
|
+
result.current.refresh();
|
|
353
|
+
});
|
|
354
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
355
|
+
case 2:
|
|
356
|
+
_a.sent();
|
|
357
|
+
expect(responseMock).toHaveBeenCalledTimes(2);
|
|
358
|
+
return [2 /*return*/];
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
}); });
|
|
350
362
|
});
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
}
|
|
363
|
+
describe("when nextPage is called while it's still loadingRefresh", function () {
|
|
364
|
+
it("should not trigger a nextPage", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
365
|
+
var result;
|
|
366
|
+
return __generator(this, function (_a) {
|
|
367
|
+
switch (_a.label) {
|
|
368
|
+
case 0:
|
|
369
|
+
result = react_hooks_1.renderHook(function () { return useCollectionQueryHook(query); }, {
|
|
370
|
+
wrapper: test_utilities_1.wrapper([
|
|
371
|
+
test_utilities_1.buildListRequestMock(query, responseMock),
|
|
372
|
+
test_utilities_1.buildListRequestMock(query, responseMock),
|
|
373
|
+
test_utilities_1.buildListRequestMockForNextPage(query, responseMock),
|
|
374
|
+
]),
|
|
375
|
+
}).result;
|
|
376
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
377
|
+
case 1:
|
|
378
|
+
_a.sent();
|
|
379
|
+
react_hooks_1.act(function () {
|
|
380
|
+
result.current.refresh();
|
|
381
|
+
});
|
|
382
|
+
react_hooks_1.act(function () {
|
|
383
|
+
result.current.nextPage();
|
|
384
|
+
});
|
|
385
|
+
expect(result.current.loadingNextPage).toBe(false);
|
|
386
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
387
|
+
case 2:
|
|
388
|
+
_a.sent();
|
|
389
|
+
return [2 /*return*/];
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
}); });
|
|
381
393
|
});
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
394
|
+
describe("when there is no error", function () {
|
|
395
|
+
it("should set loadingRefresh while loading data", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
396
|
+
var result;
|
|
397
|
+
return __generator(this, function (_a) {
|
|
398
|
+
switch (_a.label) {
|
|
399
|
+
case 0:
|
|
400
|
+
result = react_hooks_1.renderHook(function () { return useCollectionQueryHook(query); }, {
|
|
401
|
+
wrapper: test_utilities_1.wrapper([
|
|
402
|
+
test_utilities_1.buildListRequestMock(query, responseMock),
|
|
403
|
+
test_utilities_1.buildListRequestMock(query, responseMock),
|
|
404
|
+
]),
|
|
405
|
+
}).result;
|
|
406
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
407
|
+
case 1:
|
|
408
|
+
_a.sent();
|
|
409
|
+
react_hooks_1.act(function () {
|
|
410
|
+
result.current.refresh();
|
|
411
|
+
});
|
|
412
|
+
expect(result.current.loadingRefresh).toBe(true);
|
|
413
|
+
return [4 /*yield*/, react_hooks_1.act(test_utilities_1.wait)];
|
|
414
|
+
case 2:
|
|
415
|
+
_a.sent();
|
|
416
|
+
return [2 /*return*/];
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
}); });
|
|
405
420
|
});
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
}
|
|
421
|
+
});
|
|
422
|
+
describe("#subscribeToMore", function () {
|
|
423
|
+
describe("when hook receives update from item not in collection", function () {
|
|
424
|
+
it("it should add new item to collection", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
425
|
+
var _a, result, waitForNextUpdate;
|
|
426
|
+
var _b, _c, _d, _e, _f;
|
|
427
|
+
return __generator(this, function (_g) {
|
|
428
|
+
switch (_g.label) {
|
|
429
|
+
case 0:
|
|
430
|
+
_a = react_hooks_1.renderHook(function () { return useCollectionQueryHookWithSubscription(query); }, {
|
|
431
|
+
wrapper: test_utilities_1.wrapper([
|
|
432
|
+
test_utilities_1.buildListRequestMock(query, responseMock, "1"),
|
|
433
|
+
test_utilities_1.buildSubscriptionRequestMock("2"),
|
|
434
|
+
]),
|
|
435
|
+
}), result = _a.result, waitForNextUpdate = _a.waitForNextUpdate;
|
|
436
|
+
// Wait for initial load
|
|
437
|
+
return [4 /*yield*/, react_hooks_1.act(waitForNextUpdate)];
|
|
438
|
+
case 1:
|
|
439
|
+
// Wait for initial load
|
|
440
|
+
_g.sent();
|
|
441
|
+
// Wait for subscription
|
|
442
|
+
return [4 /*yield*/, react_hooks_1.act(waitForNextUpdate)];
|
|
443
|
+
case 2:
|
|
444
|
+
// Wait for subscription
|
|
445
|
+
_g.sent();
|
|
446
|
+
expect((_f = (_e = (_d = (_c = (_b = result === null || result === void 0 ? void 0 : result.current) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.conversation) === null || _d === void 0 ? void 0 : _d.smsMessages) === null || _e === void 0 ? void 0 : _e.edges) === null || _f === void 0 ? void 0 : _f.length).toBe(2);
|
|
447
|
+
return [2 /*return*/];
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
}); });
|
|
436
451
|
});
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
}
|
|
452
|
+
describe("when hook receives update from item already in collection", function () {
|
|
453
|
+
it("it should return the existing collection", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
454
|
+
var _a, result, waitForNextUpdate;
|
|
455
|
+
var _b, _c, _d, _e, _f;
|
|
456
|
+
return __generator(this, function (_g) {
|
|
457
|
+
switch (_g.label) {
|
|
458
|
+
case 0:
|
|
459
|
+
_a = react_hooks_1.renderHook(function () { return useCollectionQueryHookWithSubscription(query); }, {
|
|
460
|
+
wrapper: test_utilities_1.wrapper([
|
|
461
|
+
test_utilities_1.buildListRequestMock(query, responseMock, "1"),
|
|
462
|
+
test_utilities_1.buildSubscriptionRequestMock("1"),
|
|
463
|
+
]),
|
|
464
|
+
}), result = _a.result, waitForNextUpdate = _a.waitForNextUpdate;
|
|
465
|
+
// Wait for initial load
|
|
466
|
+
return [4 /*yield*/, react_hooks_1.act(waitForNextUpdate)];
|
|
467
|
+
case 1:
|
|
468
|
+
// Wait for initial load
|
|
469
|
+
_g.sent();
|
|
470
|
+
// Wait for subscription
|
|
471
|
+
return [4 /*yield*/, react_hooks_1.act(function () { return test_utilities_1.wait(200); })];
|
|
472
|
+
case 2:
|
|
473
|
+
// Wait for subscription
|
|
474
|
+
_g.sent();
|
|
475
|
+
expect((_f = (_e = (_d = (_c = (_b = result === null || result === void 0 ? void 0 : result.current) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.conversation) === null || _d === void 0 ? void 0 : _d.smsMessages) === null || _e === void 0 ? void 0 : _e.edges) === null || _f === void 0 ? void 0 : _f.length).toBe(1);
|
|
476
|
+
return [2 /*return*/];
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
}); });
|
|
465
480
|
});
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
481
|
+
describe("when hook receives `update` but is currently searching a collection", function () {
|
|
482
|
+
it("should return the existing collection without adding the subscribed content", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
483
|
+
var searchTerm, _a, result, waitForNextUpdate;
|
|
484
|
+
var _b, _c, _d, _e, _f;
|
|
485
|
+
return __generator(this, function (_g) {
|
|
486
|
+
switch (_g.label) {
|
|
487
|
+
case 0:
|
|
488
|
+
searchTerm = "FooBar";
|
|
489
|
+
_a = react_hooks_1.renderHook(function () {
|
|
490
|
+
return useCollectionQueryHookWithSubscriptionAndSearch(query, searchTerm);
|
|
491
|
+
}, {
|
|
492
|
+
wrapper: test_utilities_1.wrapper([
|
|
493
|
+
test_utilities_1.buildListRequestMock(query, responseMock, "1", searchTerm),
|
|
494
|
+
test_utilities_1.buildSubscriptionRequestMock("1"),
|
|
495
|
+
]),
|
|
496
|
+
}), result = _a.result, waitForNextUpdate = _a.waitForNextUpdate;
|
|
497
|
+
// Wait for initial load
|
|
498
|
+
return [4 /*yield*/, react_hooks_1.act(waitForNextUpdate)];
|
|
499
|
+
case 1:
|
|
500
|
+
// Wait for initial load
|
|
501
|
+
_g.sent();
|
|
502
|
+
// Wait for subscription
|
|
503
|
+
return [4 /*yield*/, react_hooks_1.act(function () { return test_utilities_1.wait(200); })];
|
|
504
|
+
case 2:
|
|
505
|
+
// Wait for subscription
|
|
506
|
+
_g.sent();
|
|
507
|
+
expect((_f = (_e = (_d = (_c = (_b = result === null || result === void 0 ? void 0 : result.current) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.conversation) === null || _d === void 0 ? void 0 : _d.smsMessages) === null || _e === void 0 ? void 0 : _e.edges) === null || _f === void 0 ? void 0 : _f.length).toBe(1);
|
|
508
|
+
return [2 /*return*/];
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
}); });
|
|
495
512
|
});
|
|
496
|
-
});
|
|
513
|
+
});
|
|
497
514
|
});
|
|
498
515
|
});
|
|
516
|
+
var templateObject_1;
|