@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.
- package/dist/index.js +0 -1
- package/dist/useAssert/index.js +0 -1
- package/dist/useAssert/useAssert.js +0 -1
- package/dist/useCollectionQuery/index.js +0 -1
- package/dist/useCollectionQuery/mdxUtils.js +0 -1
- package/dist/useCollectionQuery/test-utilities/index.js +0 -1
- package/dist/useCollectionQuery/test-utilities/mocks.js +0 -1
- package/dist/useCollectionQuery/test-utilities/queries.js +0 -1
- package/dist/useCollectionQuery/test-utilities/utils.js +0 -1
- package/dist/useCollectionQuery/uniqueEdges.js +0 -1
- package/dist/useCollectionQuery/uniqueNodes.js +0 -1
- package/dist/useCollectionQuery/useCollectionQuery.js +0 -1
- package/dist/useCollectionQuery/useCollectionQuery.test.js +0 -1
- package/dist/useFocusTrap/index.js +0 -1
- package/dist/useFocusTrap/useFocusTrap.js +0 -1
- package/dist/useFocusTrap/useFocusTrap.test.js +0 -1
- package/dist/useFormState/index.js +0 -1
- package/dist/useFormState/useFormState.js +0 -1
- package/dist/useIsMounted/index.js +0 -1
- package/dist/useIsMounted/useIsMounted.js +0 -1
- package/dist/useIsMounted/useIsMounted.test.js +0 -1
- package/dist/useLiveAnnounce/index.js +0 -1
- package/dist/useLiveAnnounce/useLiveAnnounce.js +0 -1
- package/dist/useLiveAnnounce/useLiveAnnounce.test.js +0 -1
- package/dist/useOnKeyDown/index.js +0 -1
- package/dist/useOnKeyDown/useOnKeyDown.js +0 -1
- package/dist/useOnKeyDown/useOnKeyDown.test.js +0 -1
- package/dist/usePasswordStrength/index.js +0 -1
- package/dist/usePasswordStrength/usePasswordStrength.d.ts +4 -5
- package/dist/usePasswordStrength/usePasswordStrength.js +4 -3
- package/dist/useRefocusOnActivator/index.js +0 -1
- package/dist/useRefocusOnActivator/useRefocusOnActivator.js +0 -1
- package/dist/useResizeObserver/index.js +0 -1
- package/dist/useResizeObserver/useResizeObserver.js +0 -1
- package/package.json +6 -5
- package/src/index.ts +10 -0
- package/src/useAssert/index.ts +1 -0
- package/src/useAssert/useAssert.stories.mdx +32 -0
- package/src/useAssert/useAssert.tsx +19 -0
- package/src/useCollectionQuery/index.ts +1 -0
- package/src/useCollectionQuery/mdxUtils.ts +190 -0
- package/src/useCollectionQuery/test-utilities/index.ts +3 -0
- package/src/useCollectionQuery/test-utilities/mocks.tsx +147 -0
- package/src/useCollectionQuery/test-utilities/queries.ts +95 -0
- package/src/useCollectionQuery/test-utilities/utils.ts +3 -0
- package/src/useCollectionQuery/uniqueEdges.tsx +26 -0
- package/src/useCollectionQuery/uniqueNodes.tsx +12 -0
- package/src/useCollectionQuery/useCollectionQuery.stories.mdx +129 -0
- package/src/useCollectionQuery/useCollectionQuery.test.tsx +419 -0
- package/src/useCollectionQuery/useCollectionQuery.ts +359 -0
- package/src/useFocusTrap/index.ts +1 -0
- package/src/useFocusTrap/useFocusTrap.stories.mdx +49 -0
- package/src/useFocusTrap/useFocusTrap.test.tsx +66 -0
- package/src/useFocusTrap/useFocusTrap.ts +64 -0
- package/src/useFormState/index.ts +1 -0
- package/src/useFormState/useFormState.stories.mdx +70 -0
- package/src/useFormState/useFormState.ts +10 -0
- package/src/useIsMounted/index.ts +1 -0
- package/src/useIsMounted/useIsMounted.stories.mdx +59 -0
- package/src/useIsMounted/useIsMounted.test.tsx +18 -0
- package/src/useIsMounted/useIsMounted.ts +30 -0
- package/src/useLiveAnnounce/index.ts +1 -0
- package/src/useLiveAnnounce/useLiveAnnounce.stories.mdx +38 -0
- package/src/useLiveAnnounce/useLiveAnnounce.test.tsx +55 -0
- package/src/useLiveAnnounce/useLiveAnnounce.tsx +47 -0
- package/src/useOnKeyDown/index.ts +1 -0
- package/src/useOnKeyDown/useOnKeyDown.stories.mdx +67 -0
- package/src/useOnKeyDown/useOnKeyDown.test.tsx +31 -0
- package/src/useOnKeyDown/useOnKeyDown.ts +52 -0
- package/src/usePasswordStrength/index.ts +1 -0
- package/src/usePasswordStrength/usePasswordStrength.stories.mdx +51 -0
- package/src/usePasswordStrength/usePasswordStrength.ts +22 -0
- package/src/useRefocusOnActivator/index.ts +1 -0
- package/src/useRefocusOnActivator/useRefocusOnActivator.stories.mdx +39 -0
- package/src/useRefocusOnActivator/useRefocusOnActivator.ts +26 -0
- package/src/useResizeObserver/index.ts +1 -0
- package/src/useResizeObserver/useResizeObserver.stories.mdx +134 -0
- package/src/useResizeObserver/useResizeObserver.ts +78 -0
- package/dist/index.js.map +0 -1
- package/dist/useAssert/index.js.map +0 -1
- package/dist/useAssert/useAssert.js.map +0 -1
- package/dist/useCollectionQuery/index.js.map +0 -1
- package/dist/useCollectionQuery/mdxUtils.js.map +0 -1
- package/dist/useCollectionQuery/test-utilities/index.js.map +0 -1
- package/dist/useCollectionQuery/test-utilities/mocks.js.map +0 -1
- package/dist/useCollectionQuery/test-utilities/queries.js.map +0 -1
- package/dist/useCollectionQuery/test-utilities/utils.js.map +0 -1
- package/dist/useCollectionQuery/uniqueEdges.js.map +0 -1
- package/dist/useCollectionQuery/uniqueNodes.js.map +0 -1
- package/dist/useCollectionQuery/useCollectionQuery.js.map +0 -1
- package/dist/useCollectionQuery/useCollectionQuery.test.js.map +0 -1
- package/dist/useFocusTrap/index.js.map +0 -1
- package/dist/useFocusTrap/useFocusTrap.js.map +0 -1
- package/dist/useFocusTrap/useFocusTrap.test.js.map +0 -1
- package/dist/useFormState/index.js.map +0 -1
- package/dist/useFormState/useFormState.js.map +0 -1
- package/dist/useIsMounted/index.js.map +0 -1
- package/dist/useIsMounted/useIsMounted.js.map +0 -1
- package/dist/useIsMounted/useIsMounted.test.js.map +0 -1
- package/dist/useLiveAnnounce/index.js.map +0 -1
- package/dist/useLiveAnnounce/useLiveAnnounce.js.map +0 -1
- package/dist/useLiveAnnounce/useLiveAnnounce.test.js.map +0 -1
- package/dist/useOnKeyDown/index.js.map +0 -1
- package/dist/useOnKeyDown/useOnKeyDown.js.map +0 -1
- package/dist/useOnKeyDown/useOnKeyDown.test.js.map +0 -1
- package/dist/usePasswordStrength/index.js.map +0 -1
- package/dist/usePasswordStrength/usePasswordStrength.js.map +0 -1
- package/dist/useRefocusOnActivator/index.js.map +0 -1
- package/dist/useRefocusOnActivator/useRefocusOnActivator.js.map +0 -1
- package/dist/useResizeObserver/index.js.map +0 -1
- package/dist/useResizeObserver/useResizeObserver.js.map +0 -1
package/dist/index.js
CHANGED
package/dist/useAssert/index.js
CHANGED
|
@@ -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:
|
|
5
|
-
warning:
|
|
6
|
-
suggestions:
|
|
7
|
-
timeToCrack:
|
|
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,
|
|
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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/hooks",
|
|
3
|
-
"version": "2.0.3-
|
|
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": "
|
|
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,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
|
+
}
|