@jobber/hooks 2.17.4 → 2.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +49 -0
- package/dist/index.mjs +23 -0
- package/dist/isObjectLike-cjs.js +228 -0
- package/dist/isObjectLike-es.js +219 -0
- package/dist/useBool/index.cjs +8 -0
- package/dist/useBool/index.mjs +2 -0
- package/dist/useBool-cjs.js +13 -0
- package/dist/useBool-es.js +11 -0
- package/dist/useBreakpoints/index.cjs +11 -0
- package/dist/useBreakpoints/index.mjs +3 -0
- package/dist/useBreakpoints/mockViewportWidth/{mockViewportWidth.js → index.cjs} +5 -4
- package/dist/useBreakpoints/mockViewportWidth/index.mjs +66 -0
- package/dist/useBreakpoints-cjs.js +48 -0
- package/dist/useBreakpoints-es.js +45 -0
- package/dist/useCallbackRef/index.cjs +8 -0
- package/dist/useCallbackRef/index.mjs +2 -0
- package/dist/useCallbackRef-cjs.js +17 -0
- package/dist/useCallbackRef-es.js +15 -0
- package/dist/useCollectionQuery/index.cjs +13 -0
- package/dist/useCollectionQuery/index.mjs +7 -0
- package/dist/useCollectionQuery/useCollectionQuery.d.ts +1 -1
- package/dist/useCollectionQuery-cjs.js +2842 -0
- package/dist/useCollectionQuery-es.js +2821 -0
- package/dist/useDebounce/index.cjs +9 -0
- package/dist/useDebounce/index.mjs +3 -0
- package/dist/useDebounce-cjs.js +92 -0
- package/dist/useDebounce-es.js +90 -0
- package/dist/useFocusTrap/index.cjs +8 -0
- package/dist/useFocusTrap/index.mjs +2 -0
- package/dist/{useFocusTrap/useFocusTrap.js → useFocusTrap-cjs.js} +8 -6
- package/dist/useFocusTrap-es.js +68 -0
- package/dist/useFormState/index.cjs +8 -0
- package/dist/useFormState/index.mjs +2 -0
- package/dist/useFormState-cjs.js +13 -0
- package/dist/useFormState-es.js +11 -0
- package/dist/useInView/index.cjs +8 -0
- package/dist/useInView/index.mjs +2 -0
- package/dist/{useInView/useInView.js → useInView-cjs.js} +10 -8
- package/dist/useInView-es.js +19 -0
- package/dist/useIsMounted/index.cjs +9 -0
- package/dist/useIsMounted/index.mjs +3 -0
- package/dist/{useIsMounted/useIsMounted.js → useIsMounted-cjs.js} +9 -7
- package/dist/useIsMounted-es.js +34 -0
- package/dist/useLiveAnnounce/index.cjs +8 -0
- package/dist/useLiveAnnounce/index.mjs +2 -0
- package/dist/{useLiveAnnounce/useLiveAnnounce.js → useLiveAnnounce-cjs.js} +8 -6
- package/dist/useLiveAnnounce-es.js +41 -0
- package/dist/useOnKeyDown/index.cjs +8 -0
- package/dist/useOnKeyDown/index.mjs +2 -0
- package/dist/{useOnKeyDown/useOnKeyDown.js → useOnKeyDown-cjs.js} +7 -5
- package/dist/useOnKeyDown-es.js +34 -0
- package/dist/useOnMount/index.cjs +9 -0
- package/dist/useOnMount/index.mjs +3 -0
- package/dist/{useOnMount/useOnMount.js → useOnMount-cjs.js} +9 -8
- package/dist/useOnMount-es.js +19 -0
- package/dist/useRefocusOnActivator/index.cjs +8 -0
- package/dist/useRefocusOnActivator/index.mjs +2 -0
- package/dist/{useRefocusOnActivator/useRefocusOnActivator.js → useRefocusOnActivator-cjs.js} +7 -5
- package/dist/useRefocusOnActivator-es.js +26 -0
- package/dist/useResizeObserver/index.cjs +10 -0
- package/dist/useResizeObserver/index.mjs +3 -0
- package/dist/useResizeObserver-cjs.js +1519 -0
- package/dist/useResizeObserver-es.js +1516 -0
- package/dist/useSafeLayoutEffect/index.cjs +8 -0
- package/dist/useSafeLayoutEffect/index.mjs +2 -0
- package/dist/useSafeLayoutEffect-cjs.js +9 -0
- package/dist/useSafeLayoutEffect-es.js +7 -0
- package/dist/useShowClear/{useShowClear.js → index.cjs} +4 -3
- package/dist/useShowClear/index.mjs +17 -0
- package/dist/useStepper/index.cjs +8 -0
- package/dist/useStepper/index.mjs +2 -0
- package/dist/{useStepper/useStepper.js → useStepper-cjs.js} +26 -14
- package/dist/useStepper-es.js +51 -0
- package/dist/useWindowDimensions/index.cjs +8 -0
- package/dist/useWindowDimensions/index.mjs +2 -0
- package/dist/{useWindowDimensions/useWindowDimensions.js → useWindowDimensions-cjs.js} +8 -6
- package/dist/useWindowDimensions-es.js +28 -0
- package/package.json +109 -7
- package/dist/index.js +0 -34
- package/dist/useBool/index.js +0 -5
- package/dist/useBool/useBool.js +0 -11
- package/dist/useBool/useBool.test.d.ts +0 -1
- package/dist/useBool/useBool.test.js +0 -28
- package/dist/useBreakpoints/index.js +0 -20
- package/dist/useBreakpoints/mockViewportWidth/index.js +0 -17
- package/dist/useBreakpoints/mockViewportWidth/mockViewportWidth.test.d.ts +0 -1
- package/dist/useBreakpoints/mockViewportWidth/mockViewportWidth.test.js +0 -17
- package/dist/useBreakpoints/useBreakpoints.js +0 -28
- package/dist/useBreakpoints/useBreakpoints.test.d.ts +0 -1
- package/dist/useBreakpoints/useBreakpoints.test.js +0 -142
- package/dist/useBreakpoints/useMediaQuery.js +0 -22
- package/dist/useCallbackRef/index.js +0 -5
- package/dist/useCallbackRef/useCallbackRef.js +0 -15
- package/dist/useCallbackRef/useCallbackRef.test.d.ts +0 -1
- package/dist/useCallbackRef/useCallbackRef.test.js +0 -29
- package/dist/useCollectionQuery/index.js +0 -5
- package/dist/useCollectionQuery/mdxUtils.js +0 -152
- package/dist/useCollectionQuery/test-utilities/index.d.ts +0 -3
- package/dist/useCollectionQuery/test-utilities/index.js +0 -19
- package/dist/useCollectionQuery/test-utilities/mocks.d.ts +0 -106
- package/dist/useCollectionQuery/test-utilities/mocks.js +0 -131
- package/dist/useCollectionQuery/test-utilities/queries.d.ts +0 -37
- package/dist/useCollectionQuery/test-utilities/queries.js +0 -59
- package/dist/useCollectionQuery/test-utilities/utils.d.ts +0 -1
- package/dist/useCollectionQuery/test-utilities/utils.js +0 -17
- package/dist/useCollectionQuery/uniqueEdges.js +0 -18
- package/dist/useCollectionQuery/uniqueNodes.js +0 -10
- package/dist/useCollectionQuery/useCollectionQuery.js +0 -194
- package/dist/useCollectionQuery/useCollectionQuery.test.d.ts +0 -1
- package/dist/useCollectionQuery/useCollectionQuery.test.js +0 -357
- package/dist/useDebounce/index.js +0 -5
- package/dist/useDebounce/useDebounce.js +0 -29
- package/dist/useDebounce/useDebounce.test.d.ts +0 -1
- package/dist/useDebounce/useDebounce.test.js +0 -190
- package/dist/useFocusTrap/index.js +0 -5
- package/dist/useFocusTrap/useFocusTrap.test.d.ts +0 -1
- package/dist/useFocusTrap/useFocusTrap.test.js +0 -61
- package/dist/useFormState/index.js +0 -5
- package/dist/useFormState/useFormState.js +0 -11
- package/dist/useInView/index.js +0 -17
- package/dist/useInView/useInView.test.d.ts +0 -1
- package/dist/useInView/useInView.test.js +0 -29
- package/dist/useIsMounted/index.js +0 -5
- package/dist/useIsMounted/useIsMounted.test.d.ts +0 -1
- package/dist/useIsMounted/useIsMounted.test.js +0 -15
- package/dist/useLiveAnnounce/index.js +0 -5
- package/dist/useLiveAnnounce/useLiveAnnounce.test.d.ts +0 -1
- package/dist/useLiveAnnounce/useLiveAnnounce.test.js +0 -60
- package/dist/useOnKeyDown/index.js +0 -5
- package/dist/useOnKeyDown/useOnKeyDown.test.d.ts +0 -1
- package/dist/useOnKeyDown/useOnKeyDown.test.js +0 -23
- package/dist/useOnMount/index.js +0 -5
- package/dist/useOnMount/useOnMount.test.d.ts +0 -1
- package/dist/useOnMount/useOnMount.test.js +0 -18
- package/dist/useRefocusOnActivator/index.js +0 -5
- package/dist/useResizeObserver/index.js +0 -17
- package/dist/useResizeObserver/useResizeObserver.js +0 -68
- package/dist/useSafeLayoutEffect/index.js +0 -5
- package/dist/useSafeLayoutEffect/useSafeLayoutEffect.js +0 -7
- package/dist/useShowClear/index.js +0 -5
- package/dist/useShowClear/useShowClear.test.d.ts +0 -1
- package/dist/useShowClear/useShowClear.test.js +0 -210
- package/dist/useStepper/index.js +0 -5
- package/dist/useStepper/useStepper.test.d.ts +0 -1
- package/dist/useStepper/useStepper.test.js +0 -79
- package/dist/useWindowDimensions/index.js +0 -5
- package/dist/useWindowDimensions/useWIndowDimensions.test.d.ts +0 -1
- package/dist/useWindowDimensions/useWIndowDimensions.test.js +0 -23
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const react_1 = require("@testing-library/react");
|
|
7
|
-
const random_1 = __importDefault(require("lodash/random"));
|
|
8
|
-
const mockViewportWidth_1 = require("./mockViewportWidth");
|
|
9
|
-
const useBreakpoints_1 = require("./useBreakpoints");
|
|
10
|
-
const { cleanup, setViewportWidth } = (0, mockViewportWidth_1.mockViewportWidth)();
|
|
11
|
-
afterEach(cleanup);
|
|
12
|
-
describe("useBreakpoints", () => {
|
|
13
|
-
describe("and up", () => {
|
|
14
|
-
it("should have the correct breakpoint values on xl size screens", () => {
|
|
15
|
-
setViewportWidth(useBreakpoints_1.BREAKPOINT_SIZES.xl);
|
|
16
|
-
const { result } = (0, react_1.renderHook)(useBreakpoints_1.useBreakpoints);
|
|
17
|
-
expect(result.current).toMatchObject({
|
|
18
|
-
smallAndUp: true,
|
|
19
|
-
mediumAndUp: true,
|
|
20
|
-
largeAndUp: true,
|
|
21
|
-
extraLargeAndUp: true,
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
it("should have the correct breakpoint values on lg size screens", () => {
|
|
25
|
-
setViewportWidth(useBreakpoints_1.BREAKPOINT_SIZES.lg);
|
|
26
|
-
const { result } = (0, react_1.renderHook)(useBreakpoints_1.useBreakpoints);
|
|
27
|
-
expect(result.current).toMatchObject({
|
|
28
|
-
smallAndUp: true,
|
|
29
|
-
mediumAndUp: true,
|
|
30
|
-
largeAndUp: true,
|
|
31
|
-
extraLargeAndUp: false,
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
it("should have the correct breakpoint values on md size screens", () => {
|
|
35
|
-
setViewportWidth(useBreakpoints_1.BREAKPOINT_SIZES.md);
|
|
36
|
-
const { result } = (0, react_1.renderHook)(useBreakpoints_1.useBreakpoints);
|
|
37
|
-
expect(result.current).toMatchObject({
|
|
38
|
-
smallAndUp: true,
|
|
39
|
-
mediumAndUp: true,
|
|
40
|
-
largeAndUp: false,
|
|
41
|
-
extraLargeAndUp: false,
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
it("should have the correct breakpoint values on sm size screens", () => {
|
|
45
|
-
setViewportWidth(useBreakpoints_1.BREAKPOINT_SIZES.sm);
|
|
46
|
-
const { result } = (0, react_1.renderHook)(useBreakpoints_1.useBreakpoints);
|
|
47
|
-
expect(result.current).toMatchObject({
|
|
48
|
-
smallAndUp: true,
|
|
49
|
-
mediumAndUp: false,
|
|
50
|
-
largeAndUp: false,
|
|
51
|
-
extraLargeAndUp: false,
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
describe("only", () => {
|
|
56
|
-
it("should only set the extraSmallOnly to true on smaller than sm", () => {
|
|
57
|
-
setViewportWidth(useBreakpoints_1.BREAKPOINT_SIZES.sm - 1);
|
|
58
|
-
const { result } = (0, react_1.renderHook)(useBreakpoints_1.useBreakpoints);
|
|
59
|
-
expect(result.current).toMatchObject({
|
|
60
|
-
extraSmallOnly: true,
|
|
61
|
-
smallOnly: false,
|
|
62
|
-
mediumOnly: false,
|
|
63
|
-
largeOnly: false,
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
it("should only set the smallOnly to true on sm", () => {
|
|
67
|
-
setViewportWidth(useBreakpoints_1.BREAKPOINT_SIZES.sm);
|
|
68
|
-
const { result } = (0, react_1.renderHook)(useBreakpoints_1.useBreakpoints);
|
|
69
|
-
expect(result.current).toMatchObject({
|
|
70
|
-
extraSmallOnly: false,
|
|
71
|
-
smallOnly: true,
|
|
72
|
-
mediumOnly: false,
|
|
73
|
-
largeOnly: false,
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
it("should only set the mediumOnly to true on md", () => {
|
|
77
|
-
setViewportWidth(useBreakpoints_1.BREAKPOINT_SIZES.md);
|
|
78
|
-
const { result } = (0, react_1.renderHook)(useBreakpoints_1.useBreakpoints);
|
|
79
|
-
expect(result.current).toMatchObject({
|
|
80
|
-
extraSmallOnly: false,
|
|
81
|
-
smallOnly: false,
|
|
82
|
-
mediumOnly: true,
|
|
83
|
-
largeOnly: false,
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
it("should only set the largeOnly to true on lg", () => {
|
|
87
|
-
setViewportWidth(useBreakpoints_1.BREAKPOINT_SIZES.lg);
|
|
88
|
-
const { result } = (0, react_1.renderHook)(useBreakpoints_1.useBreakpoints);
|
|
89
|
-
expect(result.current).toMatchObject({
|
|
90
|
-
extraSmallOnly: false,
|
|
91
|
-
smallOnly: false,
|
|
92
|
-
mediumOnly: false,
|
|
93
|
-
largeOnly: true,
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
describe("in between values", () => {
|
|
98
|
-
function randomBreakpoint(min, max) {
|
|
99
|
-
return (0, random_1.default)(min, max - 1);
|
|
100
|
-
}
|
|
101
|
-
it("should have the correct breakpoint values on higher than xl size screens", () => {
|
|
102
|
-
setViewportWidth(randomBreakpoint(useBreakpoints_1.BREAKPOINT_SIZES.xl, 10000));
|
|
103
|
-
const { result } = (0, react_1.renderHook)(useBreakpoints_1.useBreakpoints);
|
|
104
|
-
expect(result.current).toMatchObject({
|
|
105
|
-
smallAndUp: true,
|
|
106
|
-
mediumAndUp: true,
|
|
107
|
-
largeAndUp: true,
|
|
108
|
-
extraLargeAndUp: true,
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
it("should have the correct breakpoint values on lg size screens", () => {
|
|
112
|
-
setViewportWidth(randomBreakpoint(useBreakpoints_1.BREAKPOINT_SIZES.lg, useBreakpoints_1.BREAKPOINT_SIZES.xl));
|
|
113
|
-
const { result } = (0, react_1.renderHook)(useBreakpoints_1.useBreakpoints);
|
|
114
|
-
expect(result.current).toMatchObject({
|
|
115
|
-
smallAndUp: true,
|
|
116
|
-
mediumAndUp: true,
|
|
117
|
-
largeAndUp: true,
|
|
118
|
-
extraLargeAndUp: false,
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
it("should have the correct breakpoint values on md size screens", () => {
|
|
122
|
-
setViewportWidth(randomBreakpoint(useBreakpoints_1.BREAKPOINT_SIZES.md, useBreakpoints_1.BREAKPOINT_SIZES.lg));
|
|
123
|
-
const { result } = (0, react_1.renderHook)(useBreakpoints_1.useBreakpoints);
|
|
124
|
-
expect(result.current).toMatchObject({
|
|
125
|
-
smallAndUp: true,
|
|
126
|
-
mediumAndUp: true,
|
|
127
|
-
largeAndUp: false,
|
|
128
|
-
extraLargeAndUp: false,
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
it("should have the correct breakpoint values on sm size screens", () => {
|
|
132
|
-
setViewportWidth(randomBreakpoint(useBreakpoints_1.BREAKPOINT_SIZES.sm, useBreakpoints_1.BREAKPOINT_SIZES.md));
|
|
133
|
-
const { result } = (0, react_1.renderHook)(useBreakpoints_1.useBreakpoints);
|
|
134
|
-
expect(result.current).toMatchObject({
|
|
135
|
-
smallAndUp: true,
|
|
136
|
-
mediumAndUp: false,
|
|
137
|
-
largeAndUp: false,
|
|
138
|
-
extraLargeAndUp: false,
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mediaQueryStore = void 0;
|
|
4
|
-
exports.useMediaQuery = useMediaQuery;
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
exports.mediaQueryStore = {
|
|
7
|
-
subscribe(onChange, query) {
|
|
8
|
-
const matchMedia = window.matchMedia(query);
|
|
9
|
-
matchMedia.addEventListener("change", onChange);
|
|
10
|
-
return () => {
|
|
11
|
-
matchMedia.removeEventListener("change", onChange);
|
|
12
|
-
};
|
|
13
|
-
},
|
|
14
|
-
getSnapshot(query) {
|
|
15
|
-
return () => window.matchMedia(query).matches;
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
function useMediaQuery(query) {
|
|
19
|
-
const subscribeMediaQuery = (0, react_1.useCallback)((onChange) => exports.mediaQueryStore.subscribe(onChange, query), [query]);
|
|
20
|
-
const matches = (0, react_1.useSyncExternalStore)(subscribeMediaQuery, exports.mediaQueryStore.getSnapshot(query), () => true);
|
|
21
|
-
return matches;
|
|
22
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useCallbackRef = void 0;
|
|
4
|
-
var useCallbackRef_1 = require("./useCallbackRef");
|
|
5
|
-
Object.defineProperty(exports, "useCallbackRef", { enumerable: true, get: function () { return useCallbackRef_1.useCallbackRef; } });
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useCallbackRef = useCallbackRef;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
/**
|
|
6
|
-
* A custom hook that converts a callback to a ref to avoid triggering re-renders when passed as a
|
|
7
|
-
* prop or avoid re-executing effects when passed as a dependency
|
|
8
|
-
*/
|
|
9
|
-
function useCallbackRef(callback) {
|
|
10
|
-
const callbackRef = (0, react_1.useRef)(callback);
|
|
11
|
-
(0, react_1.useEffect)(() => {
|
|
12
|
-
callbackRef.current = callback;
|
|
13
|
-
});
|
|
14
|
-
return (0, react_1.useMemo)(() => ((...args) => { var _a; return (_a = callbackRef.current) === null || _a === void 0 ? void 0 : _a.call(callbackRef, ...args); }), []);
|
|
15
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const react_1 = require("@testing-library/react");
|
|
4
|
-
const _1 = require(".");
|
|
5
|
-
describe("useCallbackRef", () => {
|
|
6
|
-
it("should replace function when a new one is provided", () => {
|
|
7
|
-
const callbackInitial = jest.fn();
|
|
8
|
-
const callbackReplaced = jest.fn();
|
|
9
|
-
const { rerender, result } = (0, react_1.renderHook)(_1.useCallbackRef, {
|
|
10
|
-
initialProps: callbackInitial,
|
|
11
|
-
});
|
|
12
|
-
result.current("my args");
|
|
13
|
-
expect(callbackInitial).toHaveBeenCalledWith("my args");
|
|
14
|
-
rerender(callbackReplaced);
|
|
15
|
-
result.current("my updated args");
|
|
16
|
-
expect(callbackReplaced).toHaveBeenCalledWith("my updated args");
|
|
17
|
-
});
|
|
18
|
-
it("should not run function when it's undefined", () => {
|
|
19
|
-
const callbackInitial = jest.fn();
|
|
20
|
-
const { rerender, result } = (0, react_1.renderHook)(_1.useCallbackRef, {
|
|
21
|
-
initialProps: callbackInitial,
|
|
22
|
-
});
|
|
23
|
-
result.current("my args");
|
|
24
|
-
expect(callbackInitial).toHaveBeenCalledWith("my args");
|
|
25
|
-
rerender(undefined);
|
|
26
|
-
result.current("my updated args");
|
|
27
|
-
expect(callbackInitial).toHaveBeenCalledTimes(1);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useCollectionQuery = void 0;
|
|
4
|
-
var useCollectionQuery_1 = require("./useCollectionQuery");
|
|
5
|
-
Object.defineProperty(exports, "useCollectionQuery", { enumerable: true, get: function () { return useCollectionQuery_1.useCollectionQuery; } });
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.returnValues = exports.subscriptionPropsList = exports.propsList = exports.apolloClient = exports.LIST_QUERY = void 0;
|
|
4
|
-
exports.getLoadingState = getLoadingState;
|
|
5
|
-
const client_1 = require("@apollo/client");
|
|
6
|
-
exports.LIST_QUERY = (0, client_1.gql) `
|
|
7
|
-
query ListQuery($cursor: String) {
|
|
8
|
-
allPlanets(first: 4, after: $cursor) {
|
|
9
|
-
pageInfo {
|
|
10
|
-
hasNextPage
|
|
11
|
-
endCursor
|
|
12
|
-
}
|
|
13
|
-
edges {
|
|
14
|
-
node {
|
|
15
|
-
name
|
|
16
|
-
id
|
|
17
|
-
}
|
|
18
|
-
cursor
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
`;
|
|
23
|
-
exports.apolloClient = new client_1.ApolloClient({
|
|
24
|
-
uri: "https://swapi-graphql.netlify.app/graphql",
|
|
25
|
-
cache: new client_1.InMemoryCache(),
|
|
26
|
-
});
|
|
27
|
-
function getLoadingState(loadingInitialContent, loadingRefresh, loadingNextPage) {
|
|
28
|
-
if (loadingInitialContent) {
|
|
29
|
-
return {
|
|
30
|
-
loading: true,
|
|
31
|
-
loadingStatus: "Initial Loading",
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
if (loadingRefresh) {
|
|
35
|
-
return {
|
|
36
|
-
loading: true,
|
|
37
|
-
loadingStatus: "Refreshing",
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
if (loadingNextPage) {
|
|
41
|
-
return {
|
|
42
|
-
loading: true,
|
|
43
|
-
loadingStatus: "Fetching More",
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
loading: false,
|
|
48
|
-
loadingStatus: "Loaded",
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
exports.propsList = [
|
|
52
|
-
{
|
|
53
|
-
id: 0,
|
|
54
|
-
title: "query",
|
|
55
|
-
caption: "The graphQL query that fetches the collection",
|
|
56
|
-
value: "DocumentNode",
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
id: 1,
|
|
60
|
-
title: "queryOptions",
|
|
61
|
-
caption: "A list of options for us to pass into the apollo `useQuery` hook. \
|
|
62
|
-
Click to see more query options!",
|
|
63
|
-
url: "https://www.apollographql.com/docs/react/data/queries/#options",
|
|
64
|
-
value: "QueryHookOptions",
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
id: 2,
|
|
68
|
-
title: "getCollectionByPath",
|
|
69
|
-
caption: "A function that returns the location where the \
|
|
70
|
-
{@link Collection} is located. The collection is the part of the \
|
|
71
|
-
result that needs to be paginated.",
|
|
72
|
-
value: "GetCollectionByPathFunction<TQuery>",
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
id: 3,
|
|
76
|
-
title: "subscription (optional)",
|
|
77
|
-
caption: "A list of subscription options if \
|
|
78
|
-
you want to create a GraphQL subscription to listen for more content.",
|
|
79
|
-
value: "SubscriptionProps",
|
|
80
|
-
},
|
|
81
|
-
];
|
|
82
|
-
exports.subscriptionPropsList = [
|
|
83
|
-
{
|
|
84
|
-
id: 0,
|
|
85
|
-
title: "document",
|
|
86
|
-
caption: "The graphQL subscription that listens for more data. This query \
|
|
87
|
-
should return a single Node that matches the data structure in \
|
|
88
|
-
getCollectionByPath<TQuery>(...).edges.node and \
|
|
89
|
-
getCollectionByPath<TQuery>(...).nodes",
|
|
90
|
-
value: "DocumentNode",
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
id: 1,
|
|
94
|
-
title: "options",
|
|
95
|
-
caption: " A list of variables to pass into the apollo `subscribeToMore` function.",
|
|
96
|
-
value: "SubscribeToMoreOptions<TSubscription>",
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
id: 2,
|
|
100
|
-
title: "getNodeByPath",
|
|
101
|
-
caption: " A function that returns the location where the `Node` is \
|
|
102
|
-
located on the TSubscription object. It should return a single Node \
|
|
103
|
-
that matches the data structure in \
|
|
104
|
-
getCollectionByPath<TQuery>(...).edges.node and \
|
|
105
|
-
getCollectionByPath<TQuery>(...).nodes",
|
|
106
|
-
value: "GetNodeByPath<TSubscription>",
|
|
107
|
-
},
|
|
108
|
-
];
|
|
109
|
-
exports.returnValues = [
|
|
110
|
-
{
|
|
111
|
-
id: 0,
|
|
112
|
-
title: "data",
|
|
113
|
-
caption: "The payload returned from the query",
|
|
114
|
-
value: "ListQueryType | undefined",
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
id: 1,
|
|
118
|
-
title: "error",
|
|
119
|
-
caption: "Any errors returned from the query",
|
|
120
|
-
value: "ApolloError | undefined",
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
id: 2,
|
|
124
|
-
title: "refresh",
|
|
125
|
-
caption: "A funtion that enables you to re-execute the query",
|
|
126
|
-
value: "() => void",
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
id: 3,
|
|
130
|
-
title: "nextPage",
|
|
131
|
-
caption: "A funtion that helps you fetch the next set of results for a paginated list",
|
|
132
|
-
value: "() => void",
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
id: 4,
|
|
136
|
-
title: "loadingRefresh",
|
|
137
|
-
caption: "An indicator that a refresh is in progress",
|
|
138
|
-
value: "boolean",
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
id: 5,
|
|
142
|
-
title: "loadingNextPage",
|
|
143
|
-
caption: "An indicator that a fetch more is in progress",
|
|
144
|
-
value: "boolean",
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
id: 6,
|
|
148
|
-
title: "loadingInitialContent",
|
|
149
|
-
caption: "An indicator that the initial content is being fetched",
|
|
150
|
-
value: "boolean",
|
|
151
|
-
},
|
|
152
|
-
];
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./queries"), exports);
|
|
18
|
-
__exportStar(require("./utils"), exports);
|
|
19
|
-
__exportStar(require("./mocks"), exports);
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { DocumentNode } from "@apollo/client";
|
|
2
|
-
import { MockedResponse } from "@apollo/react-testing";
|
|
3
|
-
import React from "react";
|
|
4
|
-
export declare function wrapper(mocks: MockedResponse[]): React.FunctionComponent;
|
|
5
|
-
export declare const listQueryResponseMock: jest.Mock<{
|
|
6
|
-
data: {
|
|
7
|
-
conversation: {
|
|
8
|
-
__typename: string;
|
|
9
|
-
smsMessages: {
|
|
10
|
-
__typename: string;
|
|
11
|
-
edges: {
|
|
12
|
-
__typename: string;
|
|
13
|
-
node: {
|
|
14
|
-
__typename: string;
|
|
15
|
-
id: any;
|
|
16
|
-
};
|
|
17
|
-
}[];
|
|
18
|
-
nodes: {
|
|
19
|
-
__typename: string;
|
|
20
|
-
id: any;
|
|
21
|
-
}[];
|
|
22
|
-
pageInfo: {
|
|
23
|
-
__typename: string;
|
|
24
|
-
endCursor: string;
|
|
25
|
-
hasNextPage: boolean;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
}, [id: any], any>;
|
|
31
|
-
export declare const listQueryWithTotalCountResponseMock: jest.Mock<{
|
|
32
|
-
data: {
|
|
33
|
-
conversation: {
|
|
34
|
-
__typename: string;
|
|
35
|
-
smsMessages: {
|
|
36
|
-
__typename: string;
|
|
37
|
-
edges: {
|
|
38
|
-
__typename: string;
|
|
39
|
-
node: {
|
|
40
|
-
__typename: string;
|
|
41
|
-
id: any;
|
|
42
|
-
};
|
|
43
|
-
}[];
|
|
44
|
-
nodes: {
|
|
45
|
-
__typename: string;
|
|
46
|
-
id: any;
|
|
47
|
-
}[];
|
|
48
|
-
pageInfo: {
|
|
49
|
-
__typename: string;
|
|
50
|
-
endCursor: string;
|
|
51
|
-
hasNextPage: boolean;
|
|
52
|
-
};
|
|
53
|
-
totalCount: number;
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
}, [id: any], any>;
|
|
58
|
-
export declare const subscriptionQueryMock: jest.Mock<{
|
|
59
|
-
data: {
|
|
60
|
-
conversationMessage: {
|
|
61
|
-
__typename: string;
|
|
62
|
-
id: string;
|
|
63
|
-
smsMessage: {
|
|
64
|
-
__typename: string;
|
|
65
|
-
id: any;
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
}, [id: any], any>;
|
|
70
|
-
export declare function buildListRequestMock(query: DocumentNode, responseMock: jest.Mock, id?: string | undefined, searchTerm?: string | undefined): {
|
|
71
|
-
request: {
|
|
72
|
-
query: DocumentNode;
|
|
73
|
-
variables: {
|
|
74
|
-
searchTerm: string | undefined;
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
result: () => any;
|
|
78
|
-
};
|
|
79
|
-
export declare function buildSubscriptionRequestMock(id?: string | undefined): {
|
|
80
|
-
request: {
|
|
81
|
-
query: DocumentNode;
|
|
82
|
-
};
|
|
83
|
-
result: () => {
|
|
84
|
-
data: {
|
|
85
|
-
conversationMessage: {
|
|
86
|
-
__typename: string;
|
|
87
|
-
id: string;
|
|
88
|
-
smsMessage: {
|
|
89
|
-
__typename: string;
|
|
90
|
-
id: any;
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
delay: number;
|
|
96
|
-
};
|
|
97
|
-
export declare function buildListRequestMockForNextPage(query: DocumentNode, responseMock: jest.Mock, id?: string | undefined): {
|
|
98
|
-
request: {
|
|
99
|
-
query: DocumentNode;
|
|
100
|
-
variables: {
|
|
101
|
-
cursor: string;
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
result: () => any;
|
|
105
|
-
};
|
|
106
|
-
export declare function setListQueryMockHasNextPage(hasNextPage: boolean): void;
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.subscriptionQueryMock = exports.listQueryWithTotalCountResponseMock = exports.listQueryResponseMock = void 0;
|
|
7
|
-
exports.wrapper = wrapper;
|
|
8
|
-
exports.buildListRequestMock = buildListRequestMock;
|
|
9
|
-
exports.buildSubscriptionRequestMock = buildSubscriptionRequestMock;
|
|
10
|
-
exports.buildListRequestMockForNextPage = buildListRequestMockForNextPage;
|
|
11
|
-
exports.setListQueryMockHasNextPage = setListQueryMockHasNextPage;
|
|
12
|
-
const react_testing_1 = require("@apollo/react-testing");
|
|
13
|
-
const react_1 = __importDefault(require("react"));
|
|
14
|
-
const uuid_1 = require("uuid");
|
|
15
|
-
const queries_1 = require("./queries");
|
|
16
|
-
function wrapper(mocks) {
|
|
17
|
-
function ApolloMockedProvider({ children, }) {
|
|
18
|
-
return (react_1.default.createElement(react_testing_1.MockedProvider, { addTypename: true, mocks: mocks }, children));
|
|
19
|
-
}
|
|
20
|
-
return ApolloMockedProvider;
|
|
21
|
-
}
|
|
22
|
-
let listQueryHasNextPage = true;
|
|
23
|
-
exports.listQueryResponseMock = jest.fn(id => {
|
|
24
|
-
return {
|
|
25
|
-
data: {
|
|
26
|
-
conversation: {
|
|
27
|
-
__typename: "Conversation",
|
|
28
|
-
smsMessages: {
|
|
29
|
-
__typename: "SMSMessageConnection",
|
|
30
|
-
edges: [
|
|
31
|
-
{
|
|
32
|
-
__typename: "SMSMessageEdge",
|
|
33
|
-
node: {
|
|
34
|
-
__typename: "SMSMessage",
|
|
35
|
-
id: id || (0, uuid_1.v1)(),
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
|
-
nodes: [
|
|
40
|
-
{
|
|
41
|
-
__typename: "SMSMessage",
|
|
42
|
-
id: id || (0, uuid_1.v1)(),
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
pageInfo: {
|
|
46
|
-
__typename: "PageInfo",
|
|
47
|
-
endCursor: "MZ",
|
|
48
|
-
hasNextPage: listQueryHasNextPage,
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
});
|
|
55
|
-
exports.listQueryWithTotalCountResponseMock = jest.fn(id => {
|
|
56
|
-
return {
|
|
57
|
-
data: {
|
|
58
|
-
conversation: {
|
|
59
|
-
__typename: "Conversation",
|
|
60
|
-
smsMessages: {
|
|
61
|
-
__typename: "SMSMessageConnection",
|
|
62
|
-
edges: [
|
|
63
|
-
{
|
|
64
|
-
__typename: "SMSMessageEdge",
|
|
65
|
-
node: {
|
|
66
|
-
__typename: "SMSMessage",
|
|
67
|
-
id: id || (0, uuid_1.v1)(),
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
nodes: [
|
|
72
|
-
{
|
|
73
|
-
__typename: "SMSMessage",
|
|
74
|
-
id: id || (0, uuid_1.v1)(),
|
|
75
|
-
},
|
|
76
|
-
],
|
|
77
|
-
pageInfo: {
|
|
78
|
-
__typename: "PageInfo",
|
|
79
|
-
endCursor: "MZ",
|
|
80
|
-
hasNextPage: listQueryHasNextPage,
|
|
81
|
-
},
|
|
82
|
-
totalCount: 42,
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
});
|
|
88
|
-
exports.subscriptionQueryMock = jest.fn(id => {
|
|
89
|
-
return {
|
|
90
|
-
data: {
|
|
91
|
-
conversationMessage: {
|
|
92
|
-
__typename: "conversationMessage",
|
|
93
|
-
id: "other stuff",
|
|
94
|
-
smsMessage: {
|
|
95
|
-
__typename: "SMSMessageData",
|
|
96
|
-
id: id,
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
});
|
|
102
|
-
function buildListRequestMock(query, responseMock, id, searchTerm) {
|
|
103
|
-
return {
|
|
104
|
-
request: {
|
|
105
|
-
query: query,
|
|
106
|
-
variables: { searchTerm: searchTerm },
|
|
107
|
-
},
|
|
108
|
-
result: () => responseMock(id),
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
function buildSubscriptionRequestMock(id) {
|
|
112
|
-
return {
|
|
113
|
-
request: {
|
|
114
|
-
query: queries_1.SUBSCRIPTION_QUERY,
|
|
115
|
-
},
|
|
116
|
-
result: () => (0, exports.subscriptionQueryMock)(id),
|
|
117
|
-
delay: 100,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
function buildListRequestMockForNextPage(query, responseMock, id) {
|
|
121
|
-
return {
|
|
122
|
-
request: {
|
|
123
|
-
query: query,
|
|
124
|
-
variables: { cursor: "MZ" },
|
|
125
|
-
},
|
|
126
|
-
result: () => responseMock(id),
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
function setListQueryMockHasNextPage(hasNextPage) {
|
|
130
|
-
listQueryHasNextPage = hasNextPage;
|
|
131
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export declare const LIST_QUERY: import("@apollo/client").DocumentNode;
|
|
2
|
-
export declare const LIST_QUERY_WITH_TOTAL_COUNT: import("@apollo/client").DocumentNode;
|
|
3
|
-
export interface ListQueryType {
|
|
4
|
-
__typename?: "Query";
|
|
5
|
-
conversation?: {
|
|
6
|
-
__typename?: "Conversation";
|
|
7
|
-
smsMessages: {
|
|
8
|
-
edges: Array<{
|
|
9
|
-
__typename?: "SMSMessageConnection";
|
|
10
|
-
node: {
|
|
11
|
-
__typename?: "SMSMessage";
|
|
12
|
-
id: string;
|
|
13
|
-
};
|
|
14
|
-
cursor: string;
|
|
15
|
-
}>;
|
|
16
|
-
nodes: Array<{
|
|
17
|
-
__typename?: "SMSMessage";
|
|
18
|
-
id: string;
|
|
19
|
-
}>;
|
|
20
|
-
pageInfo: {
|
|
21
|
-
endCursor: string;
|
|
22
|
-
hasNextPage: boolean;
|
|
23
|
-
};
|
|
24
|
-
totalCount?: number;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
export declare const SUBSCRIPTION_QUERY: import("@apollo/client").DocumentNode;
|
|
29
|
-
export interface SubscriptionQueryType {
|
|
30
|
-
__typename?: "Subscription";
|
|
31
|
-
conversationMessage?: {
|
|
32
|
-
smsMessage: {
|
|
33
|
-
__typename?: "SMSMessage";
|
|
34
|
-
id: string;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
}
|