@jobber/hooks 2.17.1 → 2.17.2

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