@jobber/hooks 1.13.3 → 2.0.1

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.
Files changed (40) hide show
  1. package/dist/index.js +24 -13
  2. package/dist/useAssert/index.js +2 -1
  3. package/dist/useAssert/useAssert.js +2 -1
  4. package/dist/useCollectionQuery/index.js +2 -1
  5. package/dist/useCollectionQuery/mdxUtils.js +19 -7
  6. package/dist/useCollectionQuery/test-utilities/index.js +17 -6
  7. package/dist/useCollectionQuery/test-utilities/mocks.d.ts +3 -3
  8. package/dist/useCollectionQuery/test-utilities/mocks.js +17 -17
  9. package/dist/useCollectionQuery/test-utilities/queries.js +57 -9
  10. package/dist/useCollectionQuery/test-utilities/utils.js +4 -38
  11. package/dist/useCollectionQuery/uniqueEdges.js +5 -4
  12. package/dist/useCollectionQuery/uniqueNodes.js +4 -3
  13. package/dist/useCollectionQuery/useCollectionQuery.d.ts +2 -2
  14. package/dist/useCollectionQuery/useCollectionQuery.js +60 -101
  15. package/dist/useCollectionQuery/useCollectionQuery.test.js +240 -429
  16. package/dist/useFocusTrap/index.js +2 -1
  17. package/dist/useFocusTrap/useFocusTrap.d.ts +0 -1
  18. package/dist/useFocusTrap/useFocusTrap.js +11 -10
  19. package/dist/useFocusTrap/useFocusTrap.test.js +19 -20
  20. package/dist/useFormState/index.js +2 -1
  21. package/dist/useFormState/useFormState.d.ts +0 -1
  22. package/dist/useFormState/useFormState.js +5 -20
  23. package/dist/useIsMounted/index.js +2 -1
  24. package/dist/useIsMounted/useIsMounted.js +5 -4
  25. package/dist/useIsMounted/useIsMounted.test.js +8 -8
  26. package/dist/useLiveAnnounce/index.js +2 -1
  27. package/dist/useLiveAnnounce/useLiveAnnounce.js +9 -24
  28. package/dist/useLiveAnnounce/useLiveAnnounce.test.js +36 -97
  29. package/dist/useOnKeyDown/index.js +2 -1
  30. package/dist/useOnKeyDown/useOnKeyDown.d.ts +2 -2
  31. package/dist/useOnKeyDown/useOnKeyDown.js +7 -6
  32. package/dist/useOnKeyDown/useOnKeyDown.test.js +9 -10
  33. package/dist/usePasswordStrength/index.js +2 -1
  34. package/dist/usePasswordStrength/usePasswordStrength.js +9 -8
  35. package/dist/useRefocusOnActivator/index.js +2 -1
  36. package/dist/useRefocusOnActivator/useRefocusOnActivator.js +5 -4
  37. package/dist/useResizeObserver/index.js +15 -4
  38. package/dist/useResizeObserver/useResizeObserver.d.ts +0 -1
  39. package/dist/useResizeObserver/useResizeObserver.js +20 -36
  40. package/package.json +6 -8
@@ -1,8 +1,4 @@
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
- };
6
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -12,61 +8,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
12
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
13
9
  });
14
10
  };
15
- var __generator = (this && this.__generator) || function (thisArg, body) {
16
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
17
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
18
- function verb(n) { return function (v) { return step([n, v]); }; }
19
- function step(op) {
20
- if (f) throw new TypeError("Generator is already executing.");
21
- while (_) try {
22
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
23
- if (y = 0, t) op = [op[0] & 2, t.value];
24
- switch (op[0]) {
25
- case 0: case 1: t = op; break;
26
- case 4: _.label++; return { value: op[1], done: false };
27
- case 5: _.label++; y = op[1]; op = [0]; continue;
28
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
29
- default:
30
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
31
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
32
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
33
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
34
- if (t[2]) _.ops.pop();
35
- _.trys.pop(); continue;
36
- }
37
- op = body.call(thisArg, _);
38
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
39
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
40
- }
41
- };
42
11
  Object.defineProperty(exports, "__esModule", { value: true });
43
- var react_hooks_1 = require("@testing-library/react-hooks");
44
- var useCollectionQuery_1 = require("./useCollectionQuery");
45
- var test_utilities_1 = require("./test-utilities");
46
- beforeEach(function () {
47
- test_utilities_1.setListQueryMockHasNextPage(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");
16
+ beforeEach(() => {
17
+ (0, test_utilities_1.setListQueryMockHasNextPage)(true);
48
18
  test_utilities_1.listQueryResponseMock.mockClear();
49
19
  test_utilities_1.subscriptionQueryMock.mockClear();
50
20
  });
51
21
  function useCollectionQueryHook(query) {
52
- return useCollectionQuery_1.useCollectionQuery({
22
+ return (0, useCollectionQuery_1.useCollectionQuery)({
53
23
  query: query,
54
- getCollectionByPath: function (data) {
24
+ getCollectionByPath(data) {
55
25
  var _a;
56
26
  return (_a = data === null || data === void 0 ? void 0 : data.conversation) === null || _a === void 0 ? void 0 : _a.smsMessages;
57
27
  },
58
28
  });
59
29
  }
60
30
  function useCollectionQueryHookWithSubscription(query) {
61
- return useCollectionQuery_1.useCollectionQuery({
31
+ return (0, useCollectionQuery_1.useCollectionQuery)({
62
32
  query: query,
63
- getCollectionByPath: function (data) {
33
+ getCollectionByPath(data) {
64
34
  var _a;
65
35
  return (_a = data === null || data === void 0 ? void 0 : data.conversation) === null || _a === void 0 ? void 0 : _a.smsMessages;
66
36
  },
67
37
  subscription: {
68
38
  document: test_utilities_1.SUBSCRIPTION_QUERY,
69
- getNodeByPath: function (conversationData) {
39
+ getNodeByPath(conversationData) {
70
40
  var _a;
71
41
  return (_a = conversationData === null || conversationData === void 0 ? void 0 : conversationData.conversationMessage) === null || _a === void 0 ? void 0 : _a.smsMessage;
72
42
  },
@@ -74,443 +44,284 @@ function useCollectionQueryHookWithSubscription(query) {
74
44
  });
75
45
  }
76
46
  function useCollectionQueryHookWithSubscriptionAndSearch(query, searchTerm) {
77
- return useCollectionQuery_1.useCollectionQuery({
47
+ return (0, useCollectionQuery_1.useCollectionQuery)({
78
48
  query: query,
79
49
  queryOptions: {
80
50
  variables: {
81
51
  searchTerm: searchTerm,
82
52
  },
83
53
  },
84
- getCollectionByPath: function (data) {
54
+ getCollectionByPath(data) {
85
55
  var _a;
86
56
  return (_a = data === null || data === void 0 ? void 0 : data.conversation) === null || _a === void 0 ? void 0 : _a.smsMessages;
87
57
  },
88
58
  subscription: {
89
59
  document: test_utilities_1.SUBSCRIPTION_QUERY,
90
- getNodeByPath: function (conversationData) {
60
+ getNodeByPath(conversationData) {
91
61
  var _a;
92
62
  return (_a = conversationData === null || conversationData === void 0 ? void 0 : conversationData.conversationMessage) === null || _a === void 0 ? void 0 : _a.smsMessage;
93
63
  },
94
64
  },
95
65
  });
96
66
  }
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
- }
67
+ describe("useCollectionQuery", () => {
68
+ describe.each `
69
+ testCase | query | responseMock
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}
72
+ `("when the query run $testCase", ({ query, responseMock }) => {
73
+ describe("when useCollectionQuery is first called", () => {
74
+ describe("when nextPage is called while it's still loading initial content", () => {
75
+ it("should not trigger a the next page to be fetched", () => __awaiter(void 0, void 0, void 0, function* () {
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),
80
+ ]),
81
+ });
82
+ (0, react_hooks_1.act)(() => {
83
+ result.current.nextPage();
122
84
  });
123
- }); });
85
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
86
+ expect(responseMock).toHaveBeenCalledTimes(1);
87
+ }));
124
88
  });
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
- }
89
+ describe("when refresh is called while it's still loading initial content", () => {
90
+ it("should not trigger a refresh", () => __awaiter(void 0, void 0, void 0, function* () {
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),
95
+ ]),
146
96
  });
147
- }); });
97
+ (0, react_hooks_1.act)(() => {
98
+ result.current.refresh();
99
+ });
100
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
101
+ expect(responseMock).toHaveBeenCalledTimes(1);
102
+ }));
148
103
  });
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;
104
+ describe("when there is no error", () => {
105
+ it("should update data", () => __awaiter(void 0, void 0, void 0, function* () {
152
106
  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
- }
107
+ const { result } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHook(query), {
108
+ wrapper: (0, test_utilities_1.wrapper)([(0, test_utilities_1.buildListRequestMock)(query, responseMock)]),
165
109
  });
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
- }
110
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
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);
112
+ }));
113
+ it("should set initialLoading while loading data", () => __awaiter(void 0, void 0, void 0, function* () {
114
+ const { result } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHook(query), {
115
+ wrapper: (0, test_utilities_1.wrapper)([(0, test_utilities_1.buildListRequestMock)(query, responseMock)]),
181
116
  });
182
- }); });
117
+ expect(result.current.loadingInitialContent).toBe(true);
118
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
119
+ }));
183
120
  });
184
121
  });
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
- }
122
+ describe("#nextPage", () => {
123
+ describe("when nextPage is called while it's still loadingNextPage", () => {
124
+ it("should not trigger a nextPage", () => __awaiter(void 0, void 0, void 0, function* () {
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),
130
+ ]),
215
131
  });
216
- }); });
132
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
133
+ (0, react_hooks_1.act)(() => {
134
+ result.current.nextPage();
135
+ });
136
+ (0, react_hooks_1.act)(() => {
137
+ result.current.nextPage();
138
+ });
139
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
140
+ yield (0, react_1.waitFor)(() => {
141
+ var _a, _b, _c;
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);
143
+ });
144
+ }));
217
145
  });
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
- }
146
+ describe("when refresh is called while it's still loadingNextPage", () => {
147
+ it("should trigger a refresh", () => __awaiter(void 0, void 0, void 0, function* () {
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),
153
+ ]),
154
+ });
155
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
156
+ (0, react_hooks_1.act)(() => {
157
+ result.current.nextPage();
158
+ });
159
+ (0, react_hooks_1.act)(() => {
160
+ result.current.refresh();
246
161
  });
247
- }); });
162
+ expect(result.current.loadingRefresh).toBe(true);
163
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
164
+ }));
248
165
  });
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
- }
166
+ describe("when there is no more data to fetch", () => {
167
+ it("should not fetch more data", () => __awaiter(void 0, void 0, void 0, function* () {
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),
173
+ ]),
274
174
  });
275
- }); });
175
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
176
+ (0, react_hooks_1.act)(() => {
177
+ result.current.nextPage();
178
+ });
179
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
180
+ expect(responseMock).toHaveBeenCalledTimes(1);
181
+ }));
276
182
  });
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
- }
183
+ describe("when there is no error", () => {
184
+ it("should update data", () => __awaiter(void 0, void 0, void 0, function* () {
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),
189
+ ]),
190
+ });
191
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
192
+ (0, react_hooks_1.act)(() => {
193
+ result.current.nextPage();
194
+ });
195
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
196
+ yield (0, react_1.waitFor)(() => {
197
+ var _a, _b, _c;
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);
199
+ });
200
+ }));
201
+ it("should set loadingNextPage while loading data", () => __awaiter(void 0, void 0, void 0, function* () {
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),
206
+ ]),
302
207
  });
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
- }
208
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
209
+ (0, react_hooks_1.act)(() => {
210
+ result.current.nextPage();
327
211
  });
328
- }); });
212
+ expect(result.current.loadingNextPage).toBe(true);
213
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
214
+ }));
329
215
  });
330
216
  });
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
- }
217
+ describe("#refresh", () => {
218
+ describe("when refresh is called while it's still loadingRefresh", () => {
219
+ it("should not trigger a refresh", () => __awaiter(void 0, void 0, void 0, function* () {
220
+ const { result } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHook(query), {
221
+ wrapper: (0, test_utilities_1.wrapper)([
222
+ (0, test_utilities_1.buildListRequestMock)(query, responseMock),
223
+ (0, test_utilities_1.buildListRequestMock)(query, responseMock),
224
+ (0, test_utilities_1.buildListRequestMock)(query, responseMock),
225
+ ]),
360
226
  });
361
- }); });
227
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
228
+ (0, react_hooks_1.act)(() => {
229
+ result.current.refresh();
230
+ });
231
+ (0, react_hooks_1.act)(() => {
232
+ result.current.refresh();
233
+ });
234
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
235
+ expect(responseMock).toHaveBeenCalledTimes(2);
236
+ }));
362
237
  });
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
- }
238
+ describe("when nextPage is called while it's still loadingRefresh", () => {
239
+ it("should not trigger a nextPage", () => __awaiter(void 0, void 0, void 0, function* () {
240
+ const { result } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHook(query), {
241
+ wrapper: (0, test_utilities_1.wrapper)([
242
+ (0, test_utilities_1.buildListRequestMock)(query, responseMock),
243
+ (0, test_utilities_1.buildListRequestMock)(query, responseMock),
244
+ (0, test_utilities_1.buildListRequestMockForNextPage)(query, responseMock),
245
+ ]),
246
+ });
247
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
248
+ (0, react_hooks_1.act)(() => {
249
+ result.current.refresh();
391
250
  });
392
- }); });
251
+ (0, react_hooks_1.act)(() => {
252
+ result.current.nextPage();
253
+ });
254
+ expect(result.current.loadingNextPage).toBe(false);
255
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
256
+ }));
393
257
  });
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
- }
258
+ describe("when there is no error", () => {
259
+ it("should set loadingRefresh while loading data", () => __awaiter(void 0, void 0, void 0, function* () {
260
+ const { result } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHook(query), {
261
+ wrapper: (0, test_utilities_1.wrapper)([
262
+ (0, test_utilities_1.buildListRequestMock)(query, responseMock),
263
+ (0, test_utilities_1.buildListRequestMock)(query, responseMock),
264
+ ]),
265
+ });
266
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
267
+ (0, react_hooks_1.act)(() => {
268
+ result.current.refresh();
418
269
  });
419
- }); });
270
+ expect(result.current.loadingRefresh).toBe(true);
271
+ yield (0, react_hooks_1.act)(test_utilities_1.wait);
272
+ }));
420
273
  });
421
274
  });
422
- describe("#subscribeToMore", function () {
423
- describe("when hook receives update from item not in collection", function () {
424
- 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
- }
275
+ describe("#subscribeToMore", () => {
276
+ describe("when hook receives update from item not in collection", () => {
277
+ it("should add new item to collection", () => __awaiter(void 0, void 0, void 0, function* () {
278
+ var _a, _b, _c, _d, _e;
279
+ const { result, waitForNextUpdate } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHookWithSubscription(query), {
280
+ wrapper: (0, test_utilities_1.wrapper)([
281
+ (0, test_utilities_1.buildListRequestMock)(query, responseMock, "1"),
282
+ (0, test_utilities_1.buildSubscriptionRequestMock)("2"),
283
+ ]),
449
284
  });
450
- }); });
285
+ // Wait for initial load
286
+ yield (0, react_hooks_1.act)(waitForNextUpdate);
287
+ // Wait for subscription
288
+ yield (0, react_hooks_1.act)(waitForNextUpdate);
289
+ 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);
290
+ }));
451
291
  });
452
- describe("when hook receives update from item already in collection", function () {
453
- 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
- }
292
+ describe("when hook receives update from item already in collection", () => {
293
+ it("should return the existing collection", () => __awaiter(void 0, void 0, void 0, function* () {
294
+ var _a, _b, _c, _d, _e;
295
+ const { result, waitForNextUpdate } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHookWithSubscription(query), {
296
+ wrapper: (0, test_utilities_1.wrapper)([
297
+ (0, test_utilities_1.buildListRequestMock)(query, responseMock, "1"),
298
+ (0, test_utilities_1.buildSubscriptionRequestMock)("1"),
299
+ ]),
478
300
  });
479
- }); });
301
+ // Wait for initial load
302
+ yield (0, react_hooks_1.act)(waitForNextUpdate);
303
+ // Wait for subscription
304
+ yield (0, react_hooks_1.act)(() => (0, test_utilities_1.wait)(200));
305
+ 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);
306
+ }));
480
307
  });
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
- }
308
+ describe("when hook receives `update` but is currently searching a collection", () => {
309
+ it("should return the existing collection without adding the subscribed content", () => __awaiter(void 0, void 0, void 0, function* () {
310
+ var _a, _b, _c, _d, _e;
311
+ const searchTerm = "FooBar";
312
+ const { result, waitForNextUpdate } = (0, react_hooks_1.renderHook)(() => useCollectionQueryHookWithSubscriptionAndSearch(query, searchTerm), {
313
+ wrapper: (0, test_utilities_1.wrapper)([
314
+ (0, test_utilities_1.buildListRequestMock)(query, responseMock, "1", searchTerm),
315
+ (0, test_utilities_1.buildSubscriptionRequestMock)("1"),
316
+ ]),
510
317
  });
511
- }); });
318
+ // Wait for initial load
319
+ yield (0, react_hooks_1.act)(waitForNextUpdate);
320
+ // Wait for subscription
321
+ yield (0, react_hooks_1.act)(() => (0, test_utilities_1.wait)(200));
322
+ 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);
323
+ }));
512
324
  });
513
325
  });
514
326
  });
515
327
  });
516
- var templateObject_1;