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