@availity/hooks 3.0.0 → 3.0.4
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/CHANGELOG.md +35 -0
- package/index.d.ts +9 -9
- package/package.json +10 -13
- package/src/useMount.js +3 -2
- package/src/useOrganizations.js +2 -7
- package/src/usePermissions.js +2 -7
- package/src/useProviders.js +1 -2
- package/src/useTimeout.js +2 -2
- package/src/useToggle.js +1 -1
- package/{typings → types}/aries.d.ts +0 -0
- package/{typings → types}/useCurrentRegion.d.ts +0 -0
- package/{typings → types}/useCurrentUser.d.ts +0 -0
- package/{typings → types}/useEffectAsync.d.ts +0 -0
- package/{typings → types}/useMount.d.ts +0 -0
- package/{typings → types}/useOrganizations.d.ts +0 -0
- package/{typings → types}/usePermissions.d.ts +0 -0
- package/{typings → types}/useProviders.d.ts +0 -0
- package/{typings → types}/useTimeout.d.ts +0 -0
- package/{typings → types}/useToggle.d.ts +0 -0
- package/tests/useCurrentRegion.test.js +0 -102
- package/tests/useCurrentUser.test.js +0 -100
- package/tests/useEffectAsync.test.js +0 -36
- package/tests/useMount.test.js +0 -24
- package/tests/useOrganizations.test.js +0 -120
- package/tests/usePermissions.test.js +0 -96
- package/tests/useProviders.test.js +0 -112
- package/tests/useTimeout.test.js +0 -28
- package/tests/useToggle.test.js +0 -42
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,41 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.0.4](https://github.com/Availity/availity-react/compare/@availity/hooks@3.0.3...@availity/hooks@3.0.4) (2021-10-01)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @availity/hooks
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## 3.0.3 (2021-09-28)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @availity/hooks
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## 3.0.2 (2021-06-01)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @availity/hooks
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## 3.0.1 (2021-01-06)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Bug Fixes
|
|
34
|
+
|
|
35
|
+
* **hooks:** remove effect from dependency array in useMount ([a096fa4](https://github.com/Availity/availity-react/commit/a096fa45af7aaa40a09c87254aef0de864fa8ab6))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
6
41
|
# 3.0.0 (2020-12-23)
|
|
7
42
|
|
|
8
43
|
|
package/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { default as useEffectAsync } from './
|
|
2
|
-
export { default as useMount } from './
|
|
3
|
-
export { default as useTimeout } from './
|
|
4
|
-
export { default as useToggle } from './
|
|
5
|
-
export { default as useCurrentRegion } from './
|
|
6
|
-
export { default as useCurrentUser } from './
|
|
7
|
-
export { default as useProviders } from './
|
|
8
|
-
export { default as usePermissions } from './
|
|
9
|
-
export { default as useOrganizations } from './
|
|
1
|
+
export { default as useEffectAsync } from './types/useEffectAsync';
|
|
2
|
+
export { default as useMount } from './types/useMount';
|
|
3
|
+
export { default as useTimeout } from './types/useTimeout';
|
|
4
|
+
export { default as useToggle } from './types/useToggle';
|
|
5
|
+
export { default as useCurrentRegion } from './types/useCurrentRegion';
|
|
6
|
+
export { default as useCurrentUser } from './types/useCurrentUser';
|
|
7
|
+
export { default as useProviders } from './types/useProviders';
|
|
8
|
+
export { default as usePermissions } from './types/usePermissions';
|
|
9
|
+
export { default as useOrganizations } from './types/useOrganizations';
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/hooks",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"author": "Kyle Gray <kyle.gray@availity.com>",
|
|
5
5
|
"description": "A group of pre-built hooks that are common in most apps",
|
|
6
6
|
"main": "index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
7
8
|
"keywords": [
|
|
8
9
|
"react",
|
|
9
10
|
"availity"
|
|
@@ -20,23 +21,19 @@
|
|
|
20
21
|
"access": "public"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"prop-types": "^15.
|
|
24
|
+
"prop-types": "^15.7.2",
|
|
24
25
|
"react-query": "^3.0.0"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
|
-
"@availity/api-axios": "^
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"react": "^17.0.1",
|
|
32
|
-
"react-dom": "^17.0.1"
|
|
28
|
+
"@availity/api-axios": "^6.0.0",
|
|
29
|
+
"axios": "^0.21.1",
|
|
30
|
+
"react": "^17.0.2",
|
|
31
|
+
"react-dom": "^17.0.2"
|
|
33
32
|
},
|
|
34
33
|
"peerDependencies": {
|
|
35
|
-
"@availity/api-axios": "^
|
|
36
|
-
"
|
|
37
|
-
"@availity/localstorage-core": "^2.6.1",
|
|
38
|
-
"axios": "^0.16.0 || ^0.17.0 || ^0.18.0 || ^0.19.0",
|
|
34
|
+
"@availity/api-axios": "^6.0.0",
|
|
35
|
+
"axios": "^0.21.1",
|
|
39
36
|
"react": ">=16.8.0"
|
|
40
37
|
},
|
|
41
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "cf142eeb3780dfdc5a3b0130e09c4bb6ea0edf07"
|
|
42
39
|
}
|
package/src/useMount.js
CHANGED
package/src/useOrganizations.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { useQuery } from 'react-query';
|
|
2
2
|
import { avOrganizationsApi } from '@availity/api-axios';
|
|
3
3
|
|
|
4
|
-
const fetchOrganization = async (config) =>
|
|
5
|
-
avOrganizationsApi.getOrganizations(config);
|
|
4
|
+
const fetchOrganization = async (config) => avOrganizationsApi.getOrganizations(config);
|
|
6
5
|
|
|
7
6
|
export default function useOrganization(config, options) {
|
|
8
|
-
return useQuery(
|
|
9
|
-
['organizations', config],
|
|
10
|
-
() => fetchOrganization(config),
|
|
11
|
-
options
|
|
12
|
-
);
|
|
7
|
+
return useQuery(['organizations', config], () => fetchOrganization(config), options);
|
|
13
8
|
}
|
package/src/usePermissions.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { useQuery } from 'react-query';
|
|
2
2
|
import { avPermissionsApi } from '@availity/api-axios';
|
|
3
3
|
|
|
4
|
-
const fetchPermissions = async (config) =>
|
|
5
|
-
avPermissionsApi.getPermissions(config);
|
|
4
|
+
const fetchPermissions = async (config) => avPermissionsApi.getPermissions(config);
|
|
6
5
|
|
|
7
6
|
export default function usePermissions(config, options) {
|
|
8
|
-
return useQuery(
|
|
9
|
-
['permissions', config],
|
|
10
|
-
() => fetchPermissions(config),
|
|
11
|
-
options
|
|
12
|
-
);
|
|
7
|
+
return useQuery(['permissions', config], () => fetchPermissions(config), options);
|
|
13
8
|
}
|
package/src/useProviders.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { useQuery } from 'react-query';
|
|
2
2
|
import { avProvidersApi } from '@availity/api-axios';
|
|
3
3
|
|
|
4
|
-
const fetchProviders = async (config) =>
|
|
5
|
-
avProvidersApi.getProviders(config.customerId, config);
|
|
4
|
+
const fetchProviders = async (config) => avProvidersApi.getProviders(config.customerId, config);
|
|
6
5
|
|
|
7
6
|
export default function useProviders(config, options) {
|
|
8
7
|
return useQuery(['providers', config], () => fetchProviders(config), options);
|
package/src/useTimeout.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
|
|
3
|
-
export default (ms = 0)
|
|
3
|
+
export default function useTimeout(ms = 0) {
|
|
4
4
|
const [ready, setReady] = useState(false);
|
|
5
5
|
|
|
6
6
|
useEffect(() => {
|
|
@@ -18,4 +18,4 @@ export default (ms = 0) => {
|
|
|
18
18
|
}, [ms]);
|
|
19
19
|
|
|
20
20
|
return ready;
|
|
21
|
-
}
|
|
21
|
+
}
|
package/src/useToggle.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
|
|
3
|
-
export default function (initialState = false) {
|
|
3
|
+
export default function useToggle(initialState = false) {
|
|
4
4
|
const [state, setState] = useState(initialState);
|
|
5
5
|
const toggle = (newState) => {
|
|
6
6
|
if (newState !== undefined && newState !== state) {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { waitFor, cleanup } from '@testing-library/react';
|
|
4
|
-
import { avRegionsApi } from '@availity/api-axios';
|
|
5
|
-
import { QueryClient } from 'react-query';
|
|
6
|
-
import { useCurrentRegion } from '..';
|
|
7
|
-
import renderWithClient from './util';
|
|
8
|
-
|
|
9
|
-
jest.mock('@availity/api-axios');
|
|
10
|
-
|
|
11
|
-
let queryStates = [];
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
queryStates = [];
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const queryClient = new QueryClient();
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
jest.clearAllMocks();
|
|
20
|
-
cleanup();
|
|
21
|
-
queryClient.clear();
|
|
22
|
-
queryStates = [];
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const pushState = (state) => {
|
|
26
|
-
queryStates.push(state);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const Component = ({ log }) => {
|
|
30
|
-
// Mirror testing methods from react-query instead of relying on timing or booleans
|
|
31
|
-
// https://github.com/tannerlinsley/react-query/blob/master/src/react/tests/useQuery.test.tsx
|
|
32
|
-
const state = useCurrentRegion({ cacheTime: 0, retry: false });
|
|
33
|
-
|
|
34
|
-
// not directly used in assertions here, but useful for debugging purposes
|
|
35
|
-
if (log) log(state);
|
|
36
|
-
|
|
37
|
-
const { data, error, status } = state;
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<div>
|
|
41
|
-
<h1>Status: {status}</h1>
|
|
42
|
-
<h1>Data: {JSON.stringify(data)}</h1>
|
|
43
|
-
<h1>Error: {error}</h1>
|
|
44
|
-
</div>
|
|
45
|
-
);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
Component.propTypes = {
|
|
49
|
-
log: PropTypes.func,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
describe('useCurrentRegion', () => {
|
|
53
|
-
test('handle error', async () => {
|
|
54
|
-
avRegionsApi.getCurrentRegion.mockRejectedValueOnce('An error occurred');
|
|
55
|
-
const { getByText } = renderWithClient(
|
|
56
|
-
queryClient,
|
|
57
|
-
<Component log={pushState} />
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
getByText('Status: loading');
|
|
61
|
-
await waitFor(() => {
|
|
62
|
-
const el = getByText('Status: error');
|
|
63
|
-
expect(el).toBeDefined();
|
|
64
|
-
});
|
|
65
|
-
await waitFor(() => {
|
|
66
|
-
const el = getByText('Error: An error occurred');
|
|
67
|
-
expect(el).toBeDefined();
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('handle success', async () => {
|
|
72
|
-
avRegionsApi.getCurrentRegion.mockResolvedValueOnce({
|
|
73
|
-
config: { polling: false },
|
|
74
|
-
data: {
|
|
75
|
-
regions: [
|
|
76
|
-
{
|
|
77
|
-
id: 'FL',
|
|
78
|
-
value: 'Florida',
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
},
|
|
82
|
-
status: 200,
|
|
83
|
-
statusText: 'Ok',
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const { getByText } = renderWithClient(
|
|
87
|
-
queryClient,
|
|
88
|
-
<Component log={pushState} />
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
getByText('Status: loading');
|
|
92
|
-
await waitFor(() => {
|
|
93
|
-
const el = getByText(
|
|
94
|
-
`Data: ${JSON.stringify({
|
|
95
|
-
code: 'FL',
|
|
96
|
-
value: 'Florida',
|
|
97
|
-
})}`
|
|
98
|
-
);
|
|
99
|
-
expect(el).toBeDefined();
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { waitFor, cleanup } from '@testing-library/react';
|
|
4
|
-
import { avUserApi } from '@availity/api-axios';
|
|
5
|
-
import { QueryClient } from 'react-query';
|
|
6
|
-
import { useCurrentUser } from '..';
|
|
7
|
-
import renderWithClient from './util';
|
|
8
|
-
|
|
9
|
-
jest.mock('@availity/api-axios');
|
|
10
|
-
|
|
11
|
-
let queryStates = [];
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
queryStates = [];
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const queryClient = new QueryClient();
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
jest.clearAllMocks();
|
|
20
|
-
cleanup();
|
|
21
|
-
queryClient.clear();
|
|
22
|
-
queryStates = [];
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const pushState = (state) => {
|
|
26
|
-
queryStates.push(state);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const Component = ({ log }) => {
|
|
30
|
-
// Mirror testing methods from react-query instead of relying on timing or booleans
|
|
31
|
-
// https://github.com/tannerlinsley/react-query/blob/master/src/react/tests/useQuery.test.tsx
|
|
32
|
-
const state = useCurrentUser({ cacheTime: 0, retry: false });
|
|
33
|
-
|
|
34
|
-
// not directly used in assertions here, but useful for debugging purposes
|
|
35
|
-
if (log) log(state);
|
|
36
|
-
|
|
37
|
-
const { data, error, status } = state;
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<div>
|
|
41
|
-
<h1>Status: {status}</h1>
|
|
42
|
-
<h1>Data: {JSON.stringify(data)}</h1>
|
|
43
|
-
<h1>Error: {error}</h1>
|
|
44
|
-
</div>
|
|
45
|
-
);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
Component.propTypes = {
|
|
49
|
-
log: PropTypes.func,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
describe('useCurrentUser', () => {
|
|
53
|
-
test('should set error on rejected promise', async () => {
|
|
54
|
-
avUserApi.me.mockRejectedValueOnce('An error occurred');
|
|
55
|
-
|
|
56
|
-
const { getByText } = renderWithClient(
|
|
57
|
-
queryClient,
|
|
58
|
-
<Component log={pushState} />
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
getByText('Status: loading');
|
|
62
|
-
await waitFor(() => {
|
|
63
|
-
const el = getByText('Status: error');
|
|
64
|
-
expect(el).toBeDefined();
|
|
65
|
-
});
|
|
66
|
-
await waitFor(() => {
|
|
67
|
-
const el = getByText('Error: An error occurred');
|
|
68
|
-
expect(el).toBeDefined();
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('should return user', async () => {
|
|
73
|
-
avUserApi.me.mockResolvedValueOnce({
|
|
74
|
-
id: 'aka12345',
|
|
75
|
-
userId: 'testExample',
|
|
76
|
-
akaname: 'aka12345',
|
|
77
|
-
lastName: 'Last',
|
|
78
|
-
firstName: 'First',
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
const { getByText } = renderWithClient(
|
|
82
|
-
queryClient,
|
|
83
|
-
<Component log={pushState} />
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
getByText('Status: loading');
|
|
87
|
-
await waitFor(() => {
|
|
88
|
-
const el = getByText(
|
|
89
|
-
`Data: ${JSON.stringify({
|
|
90
|
-
id: 'aka12345',
|
|
91
|
-
userId: 'testExample',
|
|
92
|
-
akaname: 'aka12345',
|
|
93
|
-
lastName: 'Last',
|
|
94
|
-
firstName: 'First',
|
|
95
|
-
})}`
|
|
96
|
-
);
|
|
97
|
-
expect(el).toBeDefined();
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import { render, waitFor, act, cleanup } from '@testing-library/react';
|
|
3
|
-
import { useEffectAsync } from '..';
|
|
4
|
-
|
|
5
|
-
afterEach(cleanup);
|
|
6
|
-
|
|
7
|
-
// eslint-disable-next-line react/prop-types
|
|
8
|
-
const Component = ({ asyncFunc }) => {
|
|
9
|
-
const [state, setState] = useState('Hello');
|
|
10
|
-
|
|
11
|
-
useEffectAsync(async () => {
|
|
12
|
-
const newState = await asyncFunc();
|
|
13
|
-
|
|
14
|
-
act(() => setState(newState));
|
|
15
|
-
}, []);
|
|
16
|
-
|
|
17
|
-
return <div data-testid="effect-test">{state}</div>;
|
|
18
|
-
};
|
|
19
|
-
const asyncFunc = () => Promise.resolve('World');
|
|
20
|
-
|
|
21
|
-
describe('useEffectAsync', () => {
|
|
22
|
-
test('should render "Hello" then "World"', async () => {
|
|
23
|
-
// Create Async Method
|
|
24
|
-
// Render
|
|
25
|
-
const { getByTestId } = render(<Component asyncFunc={asyncFunc} />);
|
|
26
|
-
|
|
27
|
-
// Expect the component to render "Hello"
|
|
28
|
-
expect(getByTestId('effect-test').textContent).toEqual('Hello');
|
|
29
|
-
|
|
30
|
-
// Wait for the Async Function to be called after mounting
|
|
31
|
-
await waitFor(() => getByTestId('effect-test'));
|
|
32
|
-
|
|
33
|
-
// Expect the component to render "World"
|
|
34
|
-
expect(getByTestId('effect-test').textContent).toEqual('World');
|
|
35
|
-
});
|
|
36
|
-
});
|
package/tests/useMount.test.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import { render, cleanup } from '@testing-library/react';
|
|
3
|
-
import { useMount } from '..';
|
|
4
|
-
|
|
5
|
-
afterEach(cleanup);
|
|
6
|
-
|
|
7
|
-
// eslint-disable-next-line react/prop-types
|
|
8
|
-
const Component = () => {
|
|
9
|
-
const [state, setState] = useState();
|
|
10
|
-
|
|
11
|
-
useMount(() => {
|
|
12
|
-
setState('test');
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
return <p data-testid="mount-test">{state}</p>;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
describe('useMount', () => {
|
|
19
|
-
test('should render "test"', () => {
|
|
20
|
-
const { getByTestId } = render(<Component />);
|
|
21
|
-
|
|
22
|
-
expect(getByTestId('mount-test').textContent).toEqual('test');
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { waitFor, cleanup } from '@testing-library/react';
|
|
4
|
-
import { avOrganizationsApi } from '@availity/api-axios';
|
|
5
|
-
import { QueryClient } from 'react-query';
|
|
6
|
-
import renderWithClient from './util';
|
|
7
|
-
import { useOrganizations } from '..';
|
|
8
|
-
|
|
9
|
-
jest.mock('@availity/api-axios');
|
|
10
|
-
|
|
11
|
-
let queryStates = [];
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
queryStates = [];
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const queryClient = new QueryClient();
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
jest.clearAllMocks();
|
|
20
|
-
cleanup();
|
|
21
|
-
queryClient.clear();
|
|
22
|
-
queryStates = [];
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const pushState = (state) => {
|
|
26
|
-
queryStates.push(state);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const Component = ({ log }) => {
|
|
30
|
-
// Mirror testing methods from react-query instead of relying on timing or booleans
|
|
31
|
-
// https://github.com/tannerlinsley/react-query/blob/master/src/react/tests/useQuery.test.tsx
|
|
32
|
-
const state = useOrganizations({}, { cacheTime: 0, retry: false });
|
|
33
|
-
|
|
34
|
-
// not directly used in assertions here, but useful for debugging purposes
|
|
35
|
-
if (log) log(state);
|
|
36
|
-
|
|
37
|
-
const { data, error, status } = state;
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<div>
|
|
41
|
-
<h1>Status: {status}</h1>
|
|
42
|
-
<h1>Data: {JSON.stringify(data)}</h1>
|
|
43
|
-
<h1>Error: {error}</h1>
|
|
44
|
-
</div>
|
|
45
|
-
);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
Component.propTypes = {
|
|
49
|
-
log: PropTypes.func,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
describe('useOrganizations', () => {
|
|
53
|
-
test('should return an error', async () => {
|
|
54
|
-
avOrganizationsApi.getOrganizations.mockRejectedValueOnce(
|
|
55
|
-
'An error occurred'
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
const { getByText } = renderWithClient(
|
|
59
|
-
queryClient,
|
|
60
|
-
<Component log={pushState} />
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
getByText('Status: loading');
|
|
64
|
-
await waitFor(() => {
|
|
65
|
-
const el = getByText('Status: error');
|
|
66
|
-
expect(el).toBeDefined();
|
|
67
|
-
});
|
|
68
|
-
await waitFor(() => {
|
|
69
|
-
const el = getByText('Error: An error occurred');
|
|
70
|
-
expect(el).toBeDefined();
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test('should return organizations', async () => {
|
|
75
|
-
avOrganizationsApi.getOrganizations.mockResolvedValueOnce({
|
|
76
|
-
data: {
|
|
77
|
-
organizations: [
|
|
78
|
-
{
|
|
79
|
-
links: {
|
|
80
|
-
permissions: { href: 'test' },
|
|
81
|
-
patients: { href: 'test' },
|
|
82
|
-
self: { href: 'test' },
|
|
83
|
-
admin: { href: 'test' },
|
|
84
|
-
businessArrangements: { href: 'test' },
|
|
85
|
-
users: { href: 'test' },
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
],
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
const { getByText } = renderWithClient(
|
|
93
|
-
queryClient,
|
|
94
|
-
<Component log={pushState} />
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
getByText('Status: loading');
|
|
98
|
-
await waitFor(() => {
|
|
99
|
-
const el = getByText(
|
|
100
|
-
`Data: ${JSON.stringify({
|
|
101
|
-
data: {
|
|
102
|
-
organizations: [
|
|
103
|
-
{
|
|
104
|
-
links: {
|
|
105
|
-
permissions: { href: 'test' },
|
|
106
|
-
patients: { href: 'test' },
|
|
107
|
-
self: { href: 'test' },
|
|
108
|
-
admin: { href: 'test' },
|
|
109
|
-
businessArrangements: { href: 'test' },
|
|
110
|
-
users: { href: 'test' },
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
],
|
|
114
|
-
},
|
|
115
|
-
})}`
|
|
116
|
-
);
|
|
117
|
-
expect(el).toBeDefined();
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
});
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { waitFor, cleanup } from '@testing-library/react';
|
|
4
|
-
import { avPermissionsApi } from '@availity/api-axios';
|
|
5
|
-
import { QueryClient } from 'react-query';
|
|
6
|
-
import renderWithClient from './util';
|
|
7
|
-
import { usePermissions } from '..';
|
|
8
|
-
|
|
9
|
-
jest.mock('@availity/api-axios');
|
|
10
|
-
|
|
11
|
-
let queryStates = [];
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
queryStates = [];
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const queryClient = new QueryClient();
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
jest.clearAllMocks();
|
|
20
|
-
cleanup();
|
|
21
|
-
queryClient.clear();
|
|
22
|
-
queryStates = [];
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const pushState = (state) => {
|
|
26
|
-
queryStates.push(state);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const Component = ({ log }) => {
|
|
30
|
-
// Mirror testing methods from react-query instead of relying on timing or booleans
|
|
31
|
-
// https://github.com/tannerlinsley/react-query/blob/master/src/react/tests/useQuery.test.tsx
|
|
32
|
-
const state = usePermissions({}, { cacheTime: 0, retry: false });
|
|
33
|
-
|
|
34
|
-
// not directly used in assertions here, but useful for debugging purposes
|
|
35
|
-
if (log) log(state);
|
|
36
|
-
|
|
37
|
-
const { data, error, status } = state;
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<div>
|
|
41
|
-
<h1>Status: {status}</h1>
|
|
42
|
-
<h1>Data: {JSON.stringify(data)}</h1>
|
|
43
|
-
<h1>Error: {error}</h1>
|
|
44
|
-
</div>
|
|
45
|
-
);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
Component.propTypes = {
|
|
49
|
-
log: PropTypes.func,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
describe('usePermissions', () => {
|
|
53
|
-
test('should return an error', async () => {
|
|
54
|
-
avPermissionsApi.getPermissions.mockRejectedValueOnce('An error occurred');
|
|
55
|
-
|
|
56
|
-
const { getByText } = renderWithClient(
|
|
57
|
-
queryClient,
|
|
58
|
-
<Component log={pushState} />
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
getByText('Status: loading');
|
|
62
|
-
await waitFor(() => {
|
|
63
|
-
const el = getByText('Status: error');
|
|
64
|
-
expect(el).toBeDefined();
|
|
65
|
-
});
|
|
66
|
-
await waitFor(() => {
|
|
67
|
-
const el = getByText('Error: An error occurred');
|
|
68
|
-
expect(el).toBeDefined();
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('should return permissions', async () => {
|
|
73
|
-
avPermissionsApi.getPermissions.mockResolvedValueOnce({
|
|
74
|
-
id: '44',
|
|
75
|
-
description: 'test',
|
|
76
|
-
links: { self: { href: 'test.com' } },
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const { getByText } = renderWithClient(
|
|
80
|
-
queryClient,
|
|
81
|
-
<Component log={pushState} />
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
getByText('Status: loading');
|
|
85
|
-
await waitFor(() => {
|
|
86
|
-
const el = getByText(
|
|
87
|
-
`Data: ${JSON.stringify({
|
|
88
|
-
id: '44',
|
|
89
|
-
description: 'test',
|
|
90
|
-
links: { self: { href: 'test.com' } },
|
|
91
|
-
})}`
|
|
92
|
-
);
|
|
93
|
-
expect(el).toBeDefined();
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
});
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { waitFor, cleanup } from '@testing-library/react';
|
|
4
|
-
import { avProvidersApi } from '@availity/api-axios';
|
|
5
|
-
import { QueryClient } from 'react-query';
|
|
6
|
-
import renderWithClient from './util';
|
|
7
|
-
import { useProviders } from '..';
|
|
8
|
-
|
|
9
|
-
jest.mock('@availity/api-axios');
|
|
10
|
-
|
|
11
|
-
let queryStates = [];
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
queryStates = [];
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const queryClient = new QueryClient();
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
jest.clearAllMocks();
|
|
20
|
-
cleanup();
|
|
21
|
-
queryClient.clear();
|
|
22
|
-
queryStates = [];
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const pushState = (state) => {
|
|
26
|
-
queryStates.push(state);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const Component = ({ log }) => {
|
|
30
|
-
// Mirror testing methods from react-query instead of relying on timing or booleans
|
|
31
|
-
// https://github.com/tannerlinsley/react-query/blob/master/src/react/tests/useQuery.test.tsx
|
|
32
|
-
const state = useProviders({}, { cacheTime: 0, retry: false });
|
|
33
|
-
|
|
34
|
-
// not directly used in assertions here, but useful for debugging purposes
|
|
35
|
-
if (log) log(state);
|
|
36
|
-
|
|
37
|
-
const { data, error, status } = state;
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<div>
|
|
41
|
-
<h1>Status: {status}</h1>
|
|
42
|
-
<h1>Data: {JSON.stringify(data)}</h1>
|
|
43
|
-
<h1>Error: {error}</h1>
|
|
44
|
-
</div>
|
|
45
|
-
);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
Component.propTypes = {
|
|
49
|
-
log: PropTypes.func,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
describe('useProviders', () => {
|
|
53
|
-
test('should return an error', async () => {
|
|
54
|
-
avProvidersApi.getProviders.mockRejectedValueOnce('An error occurred');
|
|
55
|
-
|
|
56
|
-
const { getByText } = renderWithClient(
|
|
57
|
-
queryClient,
|
|
58
|
-
<Component log={pushState} />
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
getByText('Status: loading');
|
|
62
|
-
await waitFor(() => {
|
|
63
|
-
const el = getByText('Status: error');
|
|
64
|
-
expect(el).toBeDefined();
|
|
65
|
-
});
|
|
66
|
-
await waitFor(() => {
|
|
67
|
-
const el = getByText('Error: An error occurred');
|
|
68
|
-
expect(el).toBeDefined();
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('should return providers', async () => {
|
|
73
|
-
avProvidersApi.getProviders.mockResolvedValueOnce({
|
|
74
|
-
data: {
|
|
75
|
-
providers: [
|
|
76
|
-
{
|
|
77
|
-
id: 'test',
|
|
78
|
-
lastName: 'test',
|
|
79
|
-
firstName: 'test',
|
|
80
|
-
middleName: 'test',
|
|
81
|
-
uiDisplayName: 'test',
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
const { getByText } = renderWithClient(
|
|
88
|
-
queryClient,
|
|
89
|
-
<Component log={pushState} />
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
getByText('Status: loading');
|
|
93
|
-
await waitFor(() => {
|
|
94
|
-
const el = getByText(
|
|
95
|
-
`Data: ${JSON.stringify({
|
|
96
|
-
data: {
|
|
97
|
-
providers: [
|
|
98
|
-
{
|
|
99
|
-
id: 'test',
|
|
100
|
-
lastName: 'test',
|
|
101
|
-
firstName: 'test',
|
|
102
|
-
middleName: 'test',
|
|
103
|
-
uiDisplayName: 'test',
|
|
104
|
-
},
|
|
105
|
-
],
|
|
106
|
-
},
|
|
107
|
-
})}`
|
|
108
|
-
);
|
|
109
|
-
expect(el).toBeDefined();
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
});
|
package/tests/useTimeout.test.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render, cleanup, waitFor } from '@testing-library/react';
|
|
3
|
-
import { useTimeout } from '..';
|
|
4
|
-
|
|
5
|
-
afterEach(cleanup);
|
|
6
|
-
|
|
7
|
-
// eslint-disable-next-line react/prop-types
|
|
8
|
-
const Component = () => {
|
|
9
|
-
const timeout = useTimeout(1000);
|
|
10
|
-
|
|
11
|
-
return <p data-testid="timeout-test">{timeout ? 'True' : 'False'}</p>;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
describe('useTimeout', () => {
|
|
15
|
-
test('should render "False"', () => {
|
|
16
|
-
const { getByTestId } = render(<Component />);
|
|
17
|
-
|
|
18
|
-
expect(getByTestId('timeout-test').textContent).toEqual('False');
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('should render "True"', async () => {
|
|
22
|
-
const { getByTestId } = render(<Component />);
|
|
23
|
-
|
|
24
|
-
await waitFor(() => {
|
|
25
|
-
expect(getByTestId('timeout-test').textContent).toEqual('True');
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
});
|
package/tests/useToggle.test.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render, fireEvent, cleanup } from '@testing-library/react';
|
|
3
|
-
import { useToggle } from '..';
|
|
4
|
-
|
|
5
|
-
afterEach(cleanup);
|
|
6
|
-
|
|
7
|
-
// eslint-disable-next-line react/prop-types
|
|
8
|
-
const Component = ({ initialToggle = false }) => {
|
|
9
|
-
const [isToggled, toggle] = useToggle(initialToggle);
|
|
10
|
-
|
|
11
|
-
return (
|
|
12
|
-
<button type="button" data-testid="toggle-test" onClick={toggle}>
|
|
13
|
-
{isToggled ? 'Hello' : 'World'}
|
|
14
|
-
</button>
|
|
15
|
-
);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
describe('useToggle', () => {
|
|
19
|
-
test('should render "Hello"', () => {
|
|
20
|
-
const { getByTestId } = render(<Component />);
|
|
21
|
-
|
|
22
|
-
expect(getByTestId('toggle-test').textContent).toEqual('World');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('should render "World"', () => {
|
|
26
|
-
const { getByTestId } = render(<Component initialToggle />);
|
|
27
|
-
|
|
28
|
-
expect(getByTestId('toggle-test').textContent).toEqual('Hello');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('should toggle the state when clicked', () => {
|
|
32
|
-
const { getByTestId } = render(<Component />);
|
|
33
|
-
|
|
34
|
-
const button = getByTestId('toggle-test');
|
|
35
|
-
|
|
36
|
-
expect(button.textContent).toEqual('World');
|
|
37
|
-
|
|
38
|
-
fireEvent.click(button);
|
|
39
|
-
|
|
40
|
-
expect(getByTestId('toggle-test').textContent).toEqual('Hello');
|
|
41
|
-
});
|
|
42
|
-
});
|