@jobber/hooks 2.9.0 → 2.9.2-CJS-to-ESM.14

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 (52) hide show
  1. package/dist/index.js +15 -31
  2. package/dist/useAssert/index.js +1 -5
  3. package/dist/useAssert/useAssert.js +3 -10
  4. package/dist/useBool/index.js +1 -5
  5. package/dist/useBool/useBool.js +6 -10
  6. package/dist/useBool/useBool.test.js +9 -11
  7. package/dist/useBreakpoints/index.js +2 -20
  8. package/dist/useBreakpoints/mockViewportWidth/index.js +1 -17
  9. package/dist/useBreakpoints/mockViewportWidth/mockViewportWidth.js +2 -7
  10. package/dist/useBreakpoints/mockViewportWidth/mockViewportWidth.test.js +4 -6
  11. package/dist/useBreakpoints/useBreakpoints.js +9 -13
  12. package/dist/useBreakpoints/useBreakpoints.test.js +28 -30
  13. package/dist/useBreakpoints/useMediaQuery.js +4 -8
  14. package/dist/useCollectionQuery/index.js +1 -5
  15. package/dist/useCollectionQuery/mdxUtils.js +8 -12
  16. package/dist/useCollectionQuery/test-utilities/index.js +3 -19
  17. package/dist/useCollectionQuery/test-utilities/mocks.js +19 -30
  18. package/dist/useCollectionQuery/test-utilities/queries.js +4 -7
  19. package/dist/useCollectionQuery/test-utilities/utils.js +1 -5
  20. package/dist/useCollectionQuery/uniqueEdges.js +2 -7
  21. package/dist/useCollectionQuery/uniqueNodes.js +1 -5
  22. package/dist/useCollectionQuery/useCollectionQuery.js +27 -35
  23. package/dist/useCollectionQuery/useCollectionQuery.test.js +126 -128
  24. package/dist/useFocusTrap/index.js +1 -5
  25. package/dist/useFocusTrap/useFocusTrap.js +4 -8
  26. package/dist/useFocusTrap/useFocusTrap.test.js +26 -31
  27. package/dist/useFormState/index.js +1 -5
  28. package/dist/useFormState/useFormState.js +3 -7
  29. package/dist/useInView/index.js +1 -17
  30. package/dist/useInView/useInView.js +6 -10
  31. package/dist/useInView/useInView.test.js +12 -17
  32. package/dist/useIsMounted/index.js +1 -5
  33. package/dist/useIsMounted/useIsMounted.js +5 -9
  34. package/dist/useIsMounted/useIsMounted.test.js +4 -6
  35. package/dist/useLiveAnnounce/index.js +1 -5
  36. package/dist/useLiveAnnounce/useLiveAnnounce.js +4 -8
  37. package/dist/useLiveAnnounce/useLiveAnnounce.test.js +19 -24
  38. package/dist/useOnKeyDown/index.js +1 -5
  39. package/dist/useOnKeyDown/useOnKeyDown.js +3 -7
  40. package/dist/useOnKeyDown/useOnKeyDown.test.js +7 -12
  41. package/dist/usePasswordStrength/index.js +1 -5
  42. package/dist/usePasswordStrength/usePasswordStrength.js +4 -11
  43. package/dist/useRefocusOnActivator/index.js +1 -5
  44. package/dist/useRefocusOnActivator/useRefocusOnActivator.js +3 -7
  45. package/dist/useResizeObserver/index.js +1 -17
  46. package/dist/useResizeObserver/useResizeObserver.js +8 -15
  47. package/dist/useSafeLayoutEffect/index.js +1 -5
  48. package/dist/useSafeLayoutEffect/useSafeLayoutEffect.js +4 -7
  49. package/dist/useShowClear/index.js +1 -5
  50. package/dist/useShowClear/useShowClear.js +1 -5
  51. package/dist/useShowClear/useShowClear.test.js +5 -7
  52. package/package.json +4 -3
@@ -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.useFocusTrap = void 0;
4
- var useFocusTrap_1 = require("./useFocusTrap");
5
- Object.defineProperty(exports, "useFocusTrap", { enumerable: true, get: function () { return useFocusTrap_1.useFocusTrap; } });
1
+ export { useFocusTrap } from "./useFocusTrap";
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useFocusTrap = void 0;
4
- const react_1 = require("react");
1
+ import { useEffect, useRef } from "react";
5
2
  /**
6
3
  * Traps the focus within the children of the ref element.
7
4
  *
@@ -10,11 +7,11 @@ const react_1 = require("react");
10
7
  *
11
8
  * @returns ref
12
9
  */
13
- function useFocusTrap(active) {
10
+ export function useFocusTrap(active) {
14
11
  // There's an ongoing issue with useRef return type clashing with an element's
15
12
  // ref prop type. TLDR: Use null because useRef doesn't expect undefined.
16
13
  // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/35572
17
- const ref = (0, react_1.useRef)(null);
14
+ const ref = useRef(null);
18
15
  function handleKeyDown(event) {
19
16
  if (!(active && ref.current) || event.key !== "Tab") {
20
17
  return;
@@ -33,7 +30,7 @@ function useFocusTrap(active) {
33
30
  }
34
31
  }
35
32
  }
36
- (0, react_1.useEffect)(() => {
33
+ useEffect(() => {
37
34
  if (active && ref.current) {
38
35
  const { firstElement } = getElements(ref.current);
39
36
  firstElement.focus();
@@ -46,7 +43,6 @@ function useFocusTrap(active) {
46
43
  }, [active]);
47
44
  return ref;
48
45
  }
49
- exports.useFocusTrap = useFocusTrap;
50
46
  function getElements(ref) {
51
47
  const focusables = [
52
48
  "button",
@@ -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,54 +7,50 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const react_1 = __importDefault(require("react"));
16
- const react_2 = require("@testing-library/react");
17
- const user_event_1 = __importDefault(require("@testing-library/user-event"));
18
- const useFocusTrap_1 = require("./useFocusTrap");
10
+ import React from "react";
11
+ import { render } from "@testing-library/react";
12
+ import userEvent from "@testing-library/user-event";
13
+ import { useFocusTrap } from "./useFocusTrap";
19
14
  const targetId = "target";
20
15
  const firstFocusableChild = "first-element";
21
16
  const lastFocusableChild = "last-element";
22
17
  it("should focus on the ref target on mount", () => {
23
- const { getByTestId } = (0, react_2.render)(react_1.default.createElement(TestComponent, null));
18
+ const { getByTestId } = render(React.createElement(TestComponent, null));
24
19
  expect(getByTestId(targetId)).toHaveFocus();
25
20
  });
26
21
  it("should focus on the ref target when tabbing out of the last focusable element and ignore the tabindex'=-1'", () => __awaiter(void 0, void 0, void 0, function* () {
27
- const { getByTestId } = (0, react_2.render)(react_1.default.createElement(TestComponent, null));
22
+ const { getByTestId } = render(React.createElement(TestComponent, null));
28
23
  getByTestId(lastFocusableChild).focus();
29
- yield user_event_1.default.tab();
24
+ yield userEvent.tab();
30
25
  expect(getByTestId(targetId)).toHaveFocus();
31
26
  }));
32
27
  it("should focus on the first focusable element", () => __awaiter(void 0, void 0, void 0, function* () {
33
- const { getByTestId } = (0, react_2.render)(react_1.default.createElement(TestComponent, null));
34
- yield user_event_1.default.tab();
28
+ const { getByTestId } = render(React.createElement(TestComponent, null));
29
+ yield userEvent.tab();
35
30
  expect(getByTestId(firstFocusableChild)).toHaveFocus();
36
31
  }));
37
32
  it("should focus on the last focusable element", () => __awaiter(void 0, void 0, void 0, function* () {
38
- const { getByTestId } = (0, react_2.render)(react_1.default.createElement(TestComponent, null));
39
- yield user_event_1.default.tab({ shift: true });
33
+ const { getByTestId } = render(React.createElement(TestComponent, null));
34
+ yield userEvent.tab({ shift: true });
40
35
  expect(getByTestId(lastFocusableChild)).toHaveFocus();
41
36
  }));
42
37
  it("should not trap the tabbing and focus on the first child node", () => __awaiter(void 0, void 0, void 0, function* () {
43
- const { getByTestId } = (0, react_2.render)(react_1.default.createElement(TestComponent, { trap: false }));
44
- yield user_event_1.default.tab();
38
+ const { getByTestId } = render(React.createElement(TestComponent, { trap: false }));
39
+ yield userEvent.tab();
45
40
  expect(getByTestId(targetId).previousElementSibling).toHaveFocus();
46
41
  }));
47
42
  function TestComponent({ trap = true }) {
48
- const testRef = (0, useFocusTrap_1.useFocusTrap)(trap);
49
- return (react_1.default.createElement(react_1.default.Fragment, null,
50
- react_1.default.createElement("input", { type: "number" }),
51
- react_1.default.createElement("div", { ref: testRef, "data-testid": targetId, tabIndex: 0 },
52
- react_1.default.createElement("button", { "data-testid": firstFocusableChild }, "Click me"),
53
- react_1.default.createElement("a", { href: "#" }),
54
- react_1.default.createElement("input", { type: "text" }),
55
- react_1.default.createElement("select", null,
56
- react_1.default.createElement("option", { value: "A" })),
57
- react_1.default.createElement("textarea", null),
58
- react_1.default.createElement("span", { tabIndex: 0, "data-testId": lastFocusableChild }),
59
- react_1.default.createElement("span", { tabIndex: -1 })),
60
- react_1.default.createElement("input", { type: "calendar" })));
43
+ const testRef = useFocusTrap(trap);
44
+ return (React.createElement(React.Fragment, null,
45
+ React.createElement("input", { type: "number" }),
46
+ React.createElement("div", { ref: testRef, "data-testid": targetId, tabIndex: 0 },
47
+ React.createElement("button", { "data-testid": firstFocusableChild }, "Click me"),
48
+ React.createElement("a", { href: "#" }),
49
+ React.createElement("input", { type: "text" }),
50
+ React.createElement("select", null,
51
+ React.createElement("option", { value: "A" })),
52
+ React.createElement("textarea", null),
53
+ React.createElement("span", { tabIndex: 0, "data-testId": lastFocusableChild }),
54
+ React.createElement("span", { tabIndex: -1 })),
55
+ React.createElement("input", { type: "calendar" })));
61
56
  }
@@ -1,5 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useFormState = void 0;
4
- var useFormState_1 = require("./useFormState");
5
- Object.defineProperty(exports, "useFormState", { enumerable: true, get: function () { return useFormState_1.useFormState; } });
1
+ export { useFormState } from "./useFormState";
@@ -1,12 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useFormState = void 0;
4
- const react_1 = require("react");
5
- function useFormState() {
6
- const [formState, setFormState] = (0, react_1.useState)({
1
+ import { useState } from "react";
2
+ export function useFormState() {
3
+ const [formState, setFormState] = useState({
7
4
  isDirty: false,
8
5
  isValid: false,
9
6
  });
10
7
  return [formState, setFormState];
11
8
  }
12
- exports.useFormState = useFormState;