@jobber/hooks 2.0.3-dar.46 → 2.0.3-es6.48

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 (111) hide show
  1. package/dist/index.js +0 -1
  2. package/dist/useAssert/index.js +0 -1
  3. package/dist/useAssert/useAssert.js +0 -1
  4. package/dist/useCollectionQuery/index.js +0 -1
  5. package/dist/useCollectionQuery/mdxUtils.js +0 -1
  6. package/dist/useCollectionQuery/test-utilities/index.js +0 -1
  7. package/dist/useCollectionQuery/test-utilities/mocks.js +0 -1
  8. package/dist/useCollectionQuery/test-utilities/queries.js +0 -1
  9. package/dist/useCollectionQuery/test-utilities/utils.js +0 -1
  10. package/dist/useCollectionQuery/uniqueEdges.js +0 -1
  11. package/dist/useCollectionQuery/uniqueNodes.js +0 -1
  12. package/dist/useCollectionQuery/useCollectionQuery.js +0 -1
  13. package/dist/useCollectionQuery/useCollectionQuery.test.js +0 -1
  14. package/dist/useFocusTrap/index.js +0 -1
  15. package/dist/useFocusTrap/useFocusTrap.js +0 -1
  16. package/dist/useFocusTrap/useFocusTrap.test.js +0 -1
  17. package/dist/useFormState/index.js +0 -1
  18. package/dist/useFormState/useFormState.js +0 -1
  19. package/dist/useIsMounted/index.js +0 -1
  20. package/dist/useIsMounted/useIsMounted.js +0 -1
  21. package/dist/useIsMounted/useIsMounted.test.js +0 -1
  22. package/dist/useLiveAnnounce/index.js +0 -1
  23. package/dist/useLiveAnnounce/useLiveAnnounce.js +0 -1
  24. package/dist/useLiveAnnounce/useLiveAnnounce.test.js +0 -1
  25. package/dist/useOnKeyDown/index.js +0 -1
  26. package/dist/useOnKeyDown/useOnKeyDown.js +0 -1
  27. package/dist/useOnKeyDown/useOnKeyDown.test.js +0 -1
  28. package/dist/usePasswordStrength/index.js +0 -1
  29. package/dist/usePasswordStrength/usePasswordStrength.d.ts +4 -5
  30. package/dist/usePasswordStrength/usePasswordStrength.js +4 -3
  31. package/dist/useRefocusOnActivator/index.js +0 -1
  32. package/dist/useRefocusOnActivator/useRefocusOnActivator.js +0 -1
  33. package/dist/useResizeObserver/index.js +0 -1
  34. package/dist/useResizeObserver/useResizeObserver.js +0 -1
  35. package/package.json +6 -5
  36. package/src/index.ts +10 -0
  37. package/src/useAssert/index.ts +1 -0
  38. package/src/useAssert/useAssert.stories.mdx +32 -0
  39. package/src/useAssert/useAssert.tsx +19 -0
  40. package/src/useCollectionQuery/index.ts +1 -0
  41. package/src/useCollectionQuery/mdxUtils.ts +190 -0
  42. package/src/useCollectionQuery/test-utilities/index.ts +3 -0
  43. package/src/useCollectionQuery/test-utilities/mocks.tsx +147 -0
  44. package/src/useCollectionQuery/test-utilities/queries.ts +95 -0
  45. package/src/useCollectionQuery/test-utilities/utils.ts +3 -0
  46. package/src/useCollectionQuery/uniqueEdges.tsx +26 -0
  47. package/src/useCollectionQuery/uniqueNodes.tsx +12 -0
  48. package/src/useCollectionQuery/useCollectionQuery.stories.mdx +129 -0
  49. package/src/useCollectionQuery/useCollectionQuery.test.tsx +419 -0
  50. package/src/useCollectionQuery/useCollectionQuery.ts +359 -0
  51. package/src/useFocusTrap/index.ts +1 -0
  52. package/src/useFocusTrap/useFocusTrap.stories.mdx +49 -0
  53. package/src/useFocusTrap/useFocusTrap.test.tsx +66 -0
  54. package/src/useFocusTrap/useFocusTrap.ts +64 -0
  55. package/src/useFormState/index.ts +1 -0
  56. package/src/useFormState/useFormState.stories.mdx +70 -0
  57. package/src/useFormState/useFormState.ts +10 -0
  58. package/src/useIsMounted/index.ts +1 -0
  59. package/src/useIsMounted/useIsMounted.stories.mdx +59 -0
  60. package/src/useIsMounted/useIsMounted.test.tsx +18 -0
  61. package/src/useIsMounted/useIsMounted.ts +30 -0
  62. package/src/useLiveAnnounce/index.ts +1 -0
  63. package/src/useLiveAnnounce/useLiveAnnounce.stories.mdx +38 -0
  64. package/src/useLiveAnnounce/useLiveAnnounce.test.tsx +55 -0
  65. package/src/useLiveAnnounce/useLiveAnnounce.tsx +47 -0
  66. package/src/useOnKeyDown/index.ts +1 -0
  67. package/src/useOnKeyDown/useOnKeyDown.stories.mdx +67 -0
  68. package/src/useOnKeyDown/useOnKeyDown.test.tsx +31 -0
  69. package/src/useOnKeyDown/useOnKeyDown.ts +52 -0
  70. package/src/usePasswordStrength/index.ts +1 -0
  71. package/src/usePasswordStrength/usePasswordStrength.stories.mdx +51 -0
  72. package/src/usePasswordStrength/usePasswordStrength.ts +22 -0
  73. package/src/useRefocusOnActivator/index.ts +1 -0
  74. package/src/useRefocusOnActivator/useRefocusOnActivator.stories.mdx +39 -0
  75. package/src/useRefocusOnActivator/useRefocusOnActivator.ts +26 -0
  76. package/src/useResizeObserver/index.ts +1 -0
  77. package/src/useResizeObserver/useResizeObserver.stories.mdx +134 -0
  78. package/src/useResizeObserver/useResizeObserver.ts +78 -0
  79. package/dist/index.js.map +0 -1
  80. package/dist/useAssert/index.js.map +0 -1
  81. package/dist/useAssert/useAssert.js.map +0 -1
  82. package/dist/useCollectionQuery/index.js.map +0 -1
  83. package/dist/useCollectionQuery/mdxUtils.js.map +0 -1
  84. package/dist/useCollectionQuery/test-utilities/index.js.map +0 -1
  85. package/dist/useCollectionQuery/test-utilities/mocks.js.map +0 -1
  86. package/dist/useCollectionQuery/test-utilities/queries.js.map +0 -1
  87. package/dist/useCollectionQuery/test-utilities/utils.js.map +0 -1
  88. package/dist/useCollectionQuery/uniqueEdges.js.map +0 -1
  89. package/dist/useCollectionQuery/uniqueNodes.js.map +0 -1
  90. package/dist/useCollectionQuery/useCollectionQuery.js.map +0 -1
  91. package/dist/useCollectionQuery/useCollectionQuery.test.js.map +0 -1
  92. package/dist/useFocusTrap/index.js.map +0 -1
  93. package/dist/useFocusTrap/useFocusTrap.js.map +0 -1
  94. package/dist/useFocusTrap/useFocusTrap.test.js.map +0 -1
  95. package/dist/useFormState/index.js.map +0 -1
  96. package/dist/useFormState/useFormState.js.map +0 -1
  97. package/dist/useIsMounted/index.js.map +0 -1
  98. package/dist/useIsMounted/useIsMounted.js.map +0 -1
  99. package/dist/useIsMounted/useIsMounted.test.js.map +0 -1
  100. package/dist/useLiveAnnounce/index.js.map +0 -1
  101. package/dist/useLiveAnnounce/useLiveAnnounce.js.map +0 -1
  102. package/dist/useLiveAnnounce/useLiveAnnounce.test.js.map +0 -1
  103. package/dist/useOnKeyDown/index.js.map +0 -1
  104. package/dist/useOnKeyDown/useOnKeyDown.js.map +0 -1
  105. package/dist/useOnKeyDown/useOnKeyDown.test.js.map +0 -1
  106. package/dist/usePasswordStrength/index.js.map +0 -1
  107. package/dist/usePasswordStrength/usePasswordStrength.js.map +0 -1
  108. package/dist/useRefocusOnActivator/index.js.map +0 -1
  109. package/dist/useRefocusOnActivator/useRefocusOnActivator.js.map +0 -1
  110. package/dist/useResizeObserver/index.js.map +0 -1
  111. package/dist/useResizeObserver/useResizeObserver.js.map +0 -1
package/dist/index.js CHANGED
@@ -8,4 +8,3 @@ export * from "./useOnKeyDown";
8
8
  export * from "./usePasswordStrength";
9
9
  export * from "./useRefocusOnActivator";
10
10
  export * from "./useResizeObserver";
11
- //# sourceMappingURL=index.js.map
@@ -1,2 +1 @@
1
1
  export { useAssert } from "./useAssert";
2
- //# sourceMappingURL=index.js.map
@@ -9,4 +9,3 @@ export function useAssert(shouldShow, message, options) {
9
9
  }
10
10
  }
11
11
  }
12
- //# sourceMappingURL=useAssert.js.map
@@ -1,2 +1 @@
1
1
  export { useCollectionQuery } from "./useCollectionQuery";
2
- //# sourceMappingURL=index.js.map
@@ -146,4 +146,3 @@ export const returnValues = [
146
146
  value: "boolean",
147
147
  },
148
148
  ];
149
- //# sourceMappingURL=mdxUtils.js.map
@@ -1,4 +1,3 @@
1
1
  export * from "./queries";
2
2
  export * from "./utils";
3
3
  export * from "./mocks";
4
- //# sourceMappingURL=index.js.map
@@ -118,4 +118,3 @@ export function buildListRequestMockForNextPage(query, responseMock, id) {
118
118
  export function setListQueryMockHasNextPage(hasNextPage) {
119
119
  listQueryHasNextPage = hasNextPage;
120
120
  }
121
- //# sourceMappingURL=mocks.js.map
@@ -54,4 +54,3 @@ export const SUBSCRIPTION_QUERY = gql `
54
54
  }
55
55
  }
56
56
  `;
57
- //# sourceMappingURL=queries.js.map
@@ -12,4 +12,3 @@ export function wait(milliseconds = 0) {
12
12
  yield new Promise(resolve => setTimeout(resolve, milliseconds));
13
13
  });
14
14
  }
15
- //# sourceMappingURL=utils.js.map
@@ -12,4 +12,3 @@ export function uniqueEdges(edges) {
12
12
  });
13
13
  return Array.from(result.values());
14
14
  }
15
- //# sourceMappingURL=uniqueEdges.js.map
@@ -5,4 +5,3 @@ export function uniqueNodes(nodes) {
5
5
  });
6
6
  return Array.from(result.values());
7
7
  }
8
- //# sourceMappingURL=uniqueNodes.js.map
@@ -174,4 +174,3 @@ function getUpdatedNodes(prevNodes, nextNodes, appendToEnd = true) {
174
174
  : [...nextNodes, ...prevNodes];
175
175
  return uniqueNodes(newNodes);
176
176
  }
177
- //# sourceMappingURL=useCollectionQuery.js.map
@@ -323,4 +323,3 @@ describe("useCollectionQuery", () => {
323
323
  });
324
324
  });
325
325
  });
326
- //# sourceMappingURL=useCollectionQuery.test.js.map
@@ -1,2 +1 @@
1
1
  export { useFocusTrap } from "./useFocusTrap";
2
- //# sourceMappingURL=index.js.map
@@ -57,4 +57,3 @@ function getElements(ref) {
57
57
  const lastElement = elements[elements.length - 1];
58
58
  return { firstElement, lastElement };
59
59
  }
60
- //# sourceMappingURL=useFocusTrap.js.map
@@ -45,4 +45,3 @@ function TestComponent({ trap = true }) {
45
45
  React.createElement("span", { tabIndex: -1 })),
46
46
  React.createElement("input", { type: "calendar" })));
47
47
  }
48
- //# sourceMappingURL=useFocusTrap.test.js.map
@@ -1,2 +1 @@
1
1
  export { useFormState } from "./useFormState";
2
- //# sourceMappingURL=index.js.map
@@ -6,4 +6,3 @@ export function useFormState() {
6
6
  });
7
7
  return [formState, setFormState];
8
8
  }
9
- //# sourceMappingURL=useFormState.js.map
@@ -1,2 +1 @@
1
1
  export { useIsMounted } from "./useIsMounted";
2
- //# sourceMappingURL=index.js.map
@@ -25,4 +25,3 @@ export function useIsMounted() {
25
25
  }, []);
26
26
  return isMounted;
27
27
  }
28
- //# sourceMappingURL=useIsMounted.js.map
@@ -11,4 +11,3 @@ it("should return false when the component is unmounted", () => {
11
11
  unmount();
12
12
  expect(isMounted.current).toBe(false);
13
13
  });
14
- //# sourceMappingURL=useIsMounted.test.js.map
@@ -1,2 +1 @@
1
1
  export { useLiveAnnounce } from "./useLiveAnnounce";
2
- //# sourceMappingURL=index.js.map
@@ -36,4 +36,3 @@ function createAnnouncedElement() {
36
36
  document.body.appendChild(el);
37
37
  return el;
38
38
  }
39
- //# sourceMappingURL=useLiveAnnounce.js.map
@@ -53,4 +53,3 @@ it("should only have 1 div to announce a message on a single instance of the hoo
53
53
  expect(screen.getByRole("status").textContent).toBe(secondMessage);
54
54
  });
55
55
  }));
56
- //# sourceMappingURL=useLiveAnnounce.test.js.map
@@ -1,2 +1 @@
1
1
  export { useOnKeyDown } from "./useOnKeyDown";
2
- //# sourceMappingURL=index.js.map
@@ -24,4 +24,3 @@ export function useOnKeyDown(callback, keys) {
24
24
  }
25
25
  }
26
26
  }
27
- //# sourceMappingURL=useOnKeyDown.js.map
@@ -16,4 +16,3 @@ function TestComponent({ callback }) {
16
16
  useOnKeyDown(callback, "Enter");
17
17
  return React.createElement(React.Fragment, null, "Look at me!");
18
18
  }
19
- //# sourceMappingURL=useOnKeyDown.test.js.map
@@ -1,2 +1 @@
1
1
  export { usePasswordStrength } from "./usePasswordStrength";
2
- //# sourceMappingURL=index.js.map
@@ -1,8 +1,7 @@
1
- import calculateStrength from "zxcvbn";
2
1
  export declare function usePasswordStrength(password: string, dictionary?: string[]): {
3
2
  guesses: number;
4
- score: calculateStrength.ZXCVBNScore;
5
- warning: calculateStrength.ZXCVBNFeedbackWarning;
6
- suggestions: string[];
7
- timeToCrack: string | number;
3
+ score: number;
4
+ warning: any;
5
+ suggestions: any;
6
+ timeToCrack: any;
8
7
  };
@@ -1,7 +1,9 @@
1
1
  import { useMemo } from "react";
2
- import calculateStrength from "zxcvbn";
2
+ import calculateStrength from "@caesar-team/zxcvbn-lightweight";
3
3
  export function usePasswordStrength(password, dictionary) {
4
- const { guesses, score, feedback: { warning, suggestions }, crack_times_display: { offline_fast_hashing_1e10_per_second: timeToCrack }, } = useMemo(() => calculateStrength(password, dictionary), [password, dictionary]);
4
+ const { guesses, score,
5
+ // @ts-expect-error - bypass baby!
6
+ feedback: { warning, suggestions }, crackTimesDisplay: { offline_fast_hashing_1e10_per_second: timeToCrack }, } = useMemo(() => calculateStrength(password, dictionary), [password, dictionary]);
5
7
  return {
6
8
  guesses,
7
9
  score,
@@ -10,4 +12,3 @@ export function usePasswordStrength(password, dictionary) {
10
12
  timeToCrack,
11
13
  };
12
14
  }
13
- //# sourceMappingURL=usePasswordStrength.js.map
@@ -1,2 +1 @@
1
1
  export { useRefocusOnActivator } from "./useRefocusOnActivator";
2
- //# sourceMappingURL=index.js.map
@@ -21,4 +21,3 @@ export function useRefocusOnActivator(active) {
21
21
  };
22
22
  }, [active]);
23
23
  }
24
- //# sourceMappingURL=useRefocusOnActivator.js.map
@@ -1,2 +1 @@
1
1
  export * from "./useResizeObserver";
2
- //# sourceMappingURL=index.js.map
@@ -49,4 +49,3 @@ function getSize(sizes, comparable) {
49
49
  return (sortedSizes.find(value => value <= comparable) ||
50
50
  sortedSizes[sortedSizes.length - 1]);
51
51
  }
52
- //# sourceMappingURL=useResizeObserver.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/hooks",
3
- "version": "2.0.3-dar.46+0c5dadd0",
3
+ "version": "2.0.3-es6.48+fca738f5",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.js",
@@ -10,7 +10,8 @@
10
10
  "bootstrap": "npm run clean; npm run build"
11
11
  },
12
12
  "files": [
13
- "dist/*"
13
+ "dist/*",
14
+ "src/*"
14
15
  ],
15
16
  "devDependencies": {
16
17
  "@apollo/react-testing": "^4.0.0",
@@ -27,16 +28,16 @@
27
28
  "uuid": "^8.3.2"
28
29
  },
29
30
  "dependencies": {
31
+ "@caesar-team/zxcvbn-lightweight": "^4.5.2",
30
32
  "@use-it/event-listener": "^0.1.6",
31
33
  "lodash": "^4.17.20",
32
34
  "resize-observer-polyfill": "^1.5.1",
33
35
  "ts-xor": "^1.0.8",
34
- "use-resize-observer": "^6.1.0",
35
- "zxcvbn": "^4.4.2"
36
+ "use-resize-observer": "^6.1.0"
36
37
  },
37
38
  "peerDependencies": {
38
39
  "@apollo/client": "^3.7.10",
39
40
  "react": "^18"
40
41
  },
41
- "gitHead": "0c5dadd0305cfbb22fed038f99ab0e4239407380"
42
+ "gitHead": "fca738f5c76b58d95b9e89bf849f38fec161661f"
42
43
  }
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ export * from "./useAssert";
2
+ export * from "./useCollectionQuery";
3
+ export * from "./useFocusTrap";
4
+ export * from "./useFormState";
5
+ export * from "./useIsMounted";
6
+ export * from "./useLiveAnnounce";
7
+ export * from "./useOnKeyDown";
8
+ export * from "./usePasswordStrength";
9
+ export * from "./useRefocusOnActivator";
10
+ export * from "./useResizeObserver";
@@ -0,0 +1 @@
1
+ export { useAssert } from "./useAssert";
@@ -0,0 +1,32 @@
1
+ import { Meta } from "@storybook/addon-docs";
2
+
3
+ <Meta title="Hooks/useAssert" />
4
+
5
+ # useAssert
6
+
7
+ During development, disrupt the render of a component when a conditional is met.
8
+ This is helpful when you want to limit something that Typescript can't do...
9
+ yet.
10
+
11
+ ```ts
12
+ import { useAssert } from "@jobber/hooks";
13
+ ```
14
+
15
+ ```ts
16
+ const child: ReactElement = <Avatar initials="JBR" />;
17
+ // Make sure the child can only be an <Icon /> component
18
+ useAssert(child.type !== Icon, "You can only pass in an <Icon /> child");
19
+ ```
20
+
21
+ ## Warn
22
+
23
+ If you still want to assert but doesn't want to disrupt the render, you can pass
24
+ in a `warn: true` param. This will throw a warning on your browser console.
25
+
26
+ ```ts
27
+ const url: string = "http://getjobber.com";
28
+ // Make sure the url always starts with https://
29
+ useAssert(url.startsWith("http://"), "Please pass in an `https://` url", {
30
+ warn: true,
31
+ });
32
+ ```
@@ -0,0 +1,19 @@
1
+ import process from "process";
2
+
3
+ interface Options {
4
+ readonly warn: boolean;
5
+ }
6
+
7
+ export function useAssert(
8
+ shouldShow: boolean,
9
+ message: string,
10
+ options?: Options,
11
+ ) {
12
+ if (process.env.NODE_ENV !== "production" && shouldShow) {
13
+ if (options?.warn) {
14
+ console.warn(message);
15
+ } else {
16
+ throw new Error(message);
17
+ }
18
+ }
19
+ }
@@ -0,0 +1 @@
1
+ export { useCollectionQuery } from "./useCollectionQuery";
@@ -0,0 +1,190 @@
1
+ import { ApolloClient, InMemoryCache, gql } from "@apollo/client";
2
+
3
+ export interface ListQueryType {
4
+ allPlanets: {
5
+ __typename?: "PlanetsConnection";
6
+ pageInfo: {
7
+ hasNextPage: boolean;
8
+ endCursor: string;
9
+ };
10
+ edges: Array<{
11
+ __typename?: "PlanetsEdge";
12
+ node: {
13
+ __typename?: "Planet";
14
+ name: "string";
15
+ id: "string";
16
+ };
17
+ cursor: string;
18
+ }>;
19
+ totalCount?: number;
20
+ };
21
+ }
22
+
23
+ export const LIST_QUERY = gql`
24
+ query ListQuery($cursor: String) {
25
+ allPlanets(first: 4, after: $cursor) {
26
+ pageInfo {
27
+ hasNextPage
28
+ endCursor
29
+ }
30
+ edges {
31
+ node {
32
+ name
33
+ id
34
+ }
35
+ cursor
36
+ }
37
+ }
38
+ }
39
+ `;
40
+
41
+ export const apolloClient = new ApolloClient({
42
+ uri: "https://swapi-graphql.netlify.app/.netlify/functions/index",
43
+ cache: new InMemoryCache(),
44
+ });
45
+
46
+ interface LoadingState {
47
+ loadingStatus: string;
48
+ loading: boolean;
49
+ }
50
+
51
+ export function getLoadingState(
52
+ loadingInitialContent: boolean,
53
+ loadingRefresh: boolean,
54
+ loadingNextPage: boolean,
55
+ ): LoadingState {
56
+ if (loadingInitialContent) {
57
+ return {
58
+ loading: true,
59
+ loadingStatus: "Initial Loading",
60
+ };
61
+ }
62
+ if (loadingRefresh) {
63
+ return {
64
+ loading: true,
65
+ loadingStatus: "Refreshing",
66
+ };
67
+ }
68
+ if (loadingNextPage) {
69
+ return {
70
+ loading: true,
71
+ loadingStatus: "Fetching More",
72
+ };
73
+ }
74
+ return {
75
+ loading: false,
76
+ loadingStatus: "Loaded",
77
+ };
78
+ }
79
+
80
+ export const propsList = [
81
+ {
82
+ id: 0,
83
+ title: "query",
84
+ caption: "The graphQL query that fetches the collection",
85
+ value: "DocumentNode",
86
+ },
87
+ {
88
+ id: 1,
89
+ title: "queryOptions",
90
+ caption:
91
+ "A list of options for us to pass into the apollo `useQuery` hook. \
92
+ Click to see more query options!",
93
+ url: "https://www.apollographql.com/docs/react/data/queries/#options",
94
+ value: "QueryHookOptions",
95
+ },
96
+ {
97
+ id: 2,
98
+ title: "getCollectionByPath",
99
+ caption:
100
+ "A function that returns the location where the \
101
+ {@link Collection} is located. The collection is the part of the \
102
+ result that needs to be paginated.",
103
+ value: "GetCollectionByPathFunction<TQuery>",
104
+ },
105
+ {
106
+ id: 3,
107
+ title: "subscription (optional)",
108
+ caption:
109
+ "A list of subscription options if \
110
+ you want to create a GraphQL subscription to listen for more content.",
111
+ value: "SubscriptionProps",
112
+ },
113
+ ];
114
+
115
+ export const subscriptionPropsList = [
116
+ {
117
+ id: 0,
118
+ title: "document",
119
+ caption:
120
+ "The graphQL subscription that listens for more data. This query \
121
+ should return a single Node that matches the data structure in \
122
+ getCollectionByPath<TQuery>(...).edges.node and \
123
+ getCollectionByPath<TQuery>(...).nodes",
124
+ value: "DocumentNode",
125
+ },
126
+ {
127
+ id: 1,
128
+ title: "options",
129
+ caption:
130
+ " A list of variables to pass into the apollo `subscribeToMore` function.",
131
+ value: "SubscribeToMoreOptions<TSubscription>",
132
+ },
133
+ {
134
+ id: 2,
135
+ title: "getNodeByPath",
136
+ caption:
137
+ " A function that returns the location where the `Node` is \
138
+ located on the TSubscription object. It should return a single Node \
139
+ that matches the data structure in \
140
+ getCollectionByPath<TQuery>(...).edges.node and \
141
+ getCollectionByPath<TQuery>(...).nodes",
142
+ value: "GetNodeByPath<TSubscription>",
143
+ },
144
+ ];
145
+
146
+ export const returnValues = [
147
+ {
148
+ id: 0,
149
+ title: "data",
150
+ caption: "The payload returned from the query",
151
+ value: "ListQueryType | undefined",
152
+ },
153
+ {
154
+ id: 1,
155
+ title: "error",
156
+ caption: "Any errors returned from the query",
157
+ value: "ApolloError | undefined",
158
+ },
159
+ {
160
+ id: 2,
161
+ title: "refresh",
162
+ caption: "A funtion that enables you to re-execute the query",
163
+ value: "() => void",
164
+ },
165
+ {
166
+ id: 3,
167
+ title: "nextPage",
168
+ caption:
169
+ "A funtion that helps you fetch the next set of results for a paginated list",
170
+ value: "() => void",
171
+ },
172
+ {
173
+ id: 4,
174
+ title: "loadingRefresh",
175
+ caption: "An indicator that a refresh is in progress",
176
+ value: "boolean",
177
+ },
178
+ {
179
+ id: 5,
180
+ title: "loadingNextPage",
181
+ caption: "An indicator that a fetch more is in progress",
182
+ value: "boolean",
183
+ },
184
+ {
185
+ id: 6,
186
+ title: "loadingInitialContent",
187
+ caption: "An indicator that the initial content is being fetched",
188
+ value: "boolean",
189
+ },
190
+ ];
@@ -0,0 +1,3 @@
1
+ export * from "./queries";
2
+ export * from "./utils";
3
+ export * from "./mocks";
@@ -0,0 +1,147 @@
1
+ import { DocumentNode } from "@apollo/client";
2
+ import { MockedProvider, MockedResponse } from "@apollo/react-testing";
3
+ import React from "react";
4
+ import { v1 as uuidv1 } from "uuid";
5
+ import { SUBSCRIPTION_QUERY } from "./queries";
6
+
7
+ export function wrapper(mocks: MockedResponse[]) {
8
+ function ApolloMockedProvider({
9
+ children,
10
+ }: {
11
+ children: React.ReactElement;
12
+ }) {
13
+ return (
14
+ <MockedProvider addTypename={true} mocks={mocks}>
15
+ {children}
16
+ </MockedProvider>
17
+ );
18
+ }
19
+
20
+ return ApolloMockedProvider as React.FunctionComponent;
21
+ }
22
+
23
+ let listQueryHasNextPage = true;
24
+ export const listQueryResponseMock = jest.fn(id => {
25
+ return {
26
+ data: {
27
+ conversation: {
28
+ __typename: "Conversation",
29
+ smsMessages: {
30
+ __typename: "SMSMessageConnection",
31
+ edges: [
32
+ {
33
+ __typename: "SMSMessageEdge",
34
+ node: {
35
+ __typename: "SMSMessage",
36
+ id: id || uuidv1(),
37
+ },
38
+ },
39
+ ],
40
+ nodes: [
41
+ {
42
+ __typename: "SMSMessage",
43
+ id: id || uuidv1(),
44
+ },
45
+ ],
46
+ pageInfo: {
47
+ __typename: "PageInfo",
48
+ endCursor: "MZ",
49
+ hasNextPage: listQueryHasNextPage,
50
+ },
51
+ },
52
+ },
53
+ },
54
+ };
55
+ });
56
+
57
+ export const listQueryWithTotalCountResponseMock = jest.fn(id => {
58
+ return {
59
+ data: {
60
+ conversation: {
61
+ __typename: "Conversation",
62
+ smsMessages: {
63
+ __typename: "SMSMessageConnection",
64
+ edges: [
65
+ {
66
+ __typename: "SMSMessageEdge",
67
+ node: {
68
+ __typename: "SMSMessage",
69
+ id: id || uuidv1(),
70
+ },
71
+ },
72
+ ],
73
+ nodes: [
74
+ {
75
+ __typename: "SMSMessage",
76
+ id: id || uuidv1(),
77
+ },
78
+ ],
79
+ pageInfo: {
80
+ __typename: "PageInfo",
81
+ endCursor: "MZ",
82
+ hasNextPage: listQueryHasNextPage,
83
+ },
84
+ totalCount: 42,
85
+ },
86
+ },
87
+ },
88
+ };
89
+ });
90
+
91
+ export const subscriptionQueryMock = jest.fn(id => {
92
+ return {
93
+ data: {
94
+ conversationMessage: {
95
+ __typename: "conversationMessage",
96
+ id: "other stuff",
97
+ smsMessage: {
98
+ __typename: "SMSMessageData",
99
+ id: id,
100
+ },
101
+ },
102
+ },
103
+ };
104
+ });
105
+
106
+ export function buildListRequestMock(
107
+ query: DocumentNode,
108
+ responseMock: jest.Mock,
109
+ id?: string | undefined,
110
+ searchTerm?: string | undefined,
111
+ ) {
112
+ return {
113
+ request: {
114
+ query: query,
115
+ variables: { searchTerm: searchTerm },
116
+ },
117
+ result: () => responseMock(id),
118
+ };
119
+ }
120
+
121
+ export function buildSubscriptionRequestMock(id?: string | undefined) {
122
+ return {
123
+ request: {
124
+ query: SUBSCRIPTION_QUERY,
125
+ },
126
+ result: () => subscriptionQueryMock(id),
127
+ delay: 100,
128
+ };
129
+ }
130
+
131
+ export function buildListRequestMockForNextPage(
132
+ query: DocumentNode,
133
+ responseMock: jest.Mock,
134
+ id?: string | undefined,
135
+ ) {
136
+ return {
137
+ request: {
138
+ query: query,
139
+ variables: { cursor: "MZ" },
140
+ },
141
+ result: () => responseMock(id),
142
+ };
143
+ }
144
+
145
+ export function setListQueryMockHasNextPage(hasNextPage: boolean) {
146
+ listQueryHasNextPage = hasNextPage;
147
+ }