@availity/hooks 5.2.0 → 6.0.1
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 +17 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +158 -0
- package/package.json +25 -15
- package/project.json +14 -6
- package/src/index.ts +20 -0
- package/src/types.ts +4 -0
- package/src/useCurrentRegion.ts +23 -0
- package/src/useCurrentUser.ts +13 -0
- package/src/useEffectAsync.ts +9 -0
- package/src/useMount.ts +6 -0
- package/src/useOrganizations.ts +22 -0
- package/src/usePermissions.ts +15 -0
- package/src/useProviders.ts +20 -0
- package/src/useStash.ts +21 -0
- package/src/{useTimeout.js → useTimeout.ts} +1 -1
- package/src/{useToggle.js → useToggle.ts} +2 -2
- package/src/{useUpdateNav.js → useUpdateNav.ts} +1 -1
- package/src/{useWindowDimensions.js → useWindowDimensions.ts} +9 -9
- package/stories/ResourceComponent.tsx +12 -10
- package/tests/useCurrentRegion.test.tsx +49 -0
- package/tests/useCurrentUser.test.tsx +52 -0
- package/tests/useEffectAsync.test.tsx +30 -0
- package/tests/useMount.test.tsx +23 -0
- package/tests/useOrganizations.test.tsx +49 -0
- package/tests/usePermissions.test.tsx +52 -0
- package/tests/useProviders.test.tsx +49 -0
- package/tests/useStash.test.tsx +58 -0
- package/tests/useTimeout.test.tsx +33 -0
- package/tests/useToggle.test.tsx +41 -0
- package/tests/useUpdateNav.test.tsx +46 -0
- package/tests/useWindowDimensions.test.tsx +37 -0
- package/tests/util.tsx +7 -0
- package/vitest.config.ts +17 -0
- package/index.d.ts +0 -12
- package/index.js +0 -12
- package/jest.config.js +0 -7
- package/src/useCurrentRegion.js +0 -15
- package/src/useCurrentUser.js +0 -8
- package/src/useEffectAsync.js +0 -8
- package/src/useMount.js +0 -6
- package/src/useOrganizations.js +0 -8
- package/src/usePermissions.js +0 -8
- package/src/useProviders.js +0 -8
- package/src/useStash.js +0 -14
- package/tests/util.js +0 -8
- package/tsconfig.spec.json +0 -10
- package/types/aries.d.ts +0 -12
- package/types/useCurrentRegion.d.ts +0 -12
- package/types/useCurrentUser.d.ts +0 -21
- package/types/useEffectAsync.d.ts +0 -3
- package/types/useMount.d.ts +0 -5
- package/types/useOrganizations.d.ts +0 -75
- package/types/usePermissions.d.ts +0 -22
- package/types/useProviders.d.ts +0 -50
- package/types/useStash.d.ts +0 -10
- package/types/useTimeout.d.ts +0 -3
- package/types/useToggle.d.ts +0 -3
- package/types/useUpdateNav.d.ts +0 -3
- package/types/useWindowDimensions.d.ts +0 -8
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { waitFor, cleanup } from '@testing-library/react';
|
|
3
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { http, HttpResponse } from 'msw';
|
|
5
|
+
import { server } from '@availity/mock/src/server';
|
|
6
|
+
import { USER_A2 } from '@availity/mock/src/routes';
|
|
7
|
+
import { useCurrentUser } from '../src/index';
|
|
8
|
+
import renderWithClient from './util';
|
|
9
|
+
|
|
10
|
+
const queryClient = new QueryClient();
|
|
11
|
+
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
cleanup();
|
|
14
|
+
queryClient.clear();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const Component = () => {
|
|
18
|
+
const { data, error, status } = useCurrentUser({ gcTime: 0, retry: false });
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div>
|
|
22
|
+
<h1>Status: {status}</h1>
|
|
23
|
+
<h1>Data: {JSON.stringify(data)}</h1>
|
|
24
|
+
<h1>Error: {error?.message}</h1>
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
describe('useCurrentUser', () => {
|
|
30
|
+
test('should set error on rejected promise', async () => {
|
|
31
|
+
server.use(http.get(USER_A2, () => HttpResponse.error()));
|
|
32
|
+
|
|
33
|
+
const { getByText } = renderWithClient(queryClient, <Component />);
|
|
34
|
+
|
|
35
|
+
getByText('Status: pending');
|
|
36
|
+
await waitFor(() => {
|
|
37
|
+
expect(getByText('Status: error')).toBeDefined();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('should return user', async () => {
|
|
42
|
+
const { getByText } = renderWithClient(queryClient, <Component />);
|
|
43
|
+
|
|
44
|
+
getByText('Status: pending');
|
|
45
|
+
await waitFor(() => {
|
|
46
|
+
expect(getByText(/aka123456789/)).toBeDefined();
|
|
47
|
+
});
|
|
48
|
+
await waitFor(() => {
|
|
49
|
+
expect(getByText(/Sanchez/)).toBeDefined();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { render, waitFor, act, cleanup } from '@testing-library/react';
|
|
3
|
+
import { useEffectAsync } from '../src/index';
|
|
4
|
+
|
|
5
|
+
afterEach(cleanup);
|
|
6
|
+
|
|
7
|
+
const Component = ({ asyncFunc }: { asyncFunc: () => Promise<string> }) => {
|
|
8
|
+
const [state, setState] = useState('Hello');
|
|
9
|
+
|
|
10
|
+
useEffectAsync(async () => {
|
|
11
|
+
const newState = await asyncFunc();
|
|
12
|
+
|
|
13
|
+
act(() => setState(newState));
|
|
14
|
+
}, []);
|
|
15
|
+
|
|
16
|
+
return <div data-testid="effect-test">{state}</div>;
|
|
17
|
+
};
|
|
18
|
+
const asyncFunc = () => Promise.resolve('World');
|
|
19
|
+
|
|
20
|
+
describe('useEffectAsync', () => {
|
|
21
|
+
test('should render "Hello" then "World"', async () => {
|
|
22
|
+
const { getByTestId } = render(<Component asyncFunc={asyncFunc} />);
|
|
23
|
+
|
|
24
|
+
expect(getByTestId('effect-test').textContent).toEqual('Hello');
|
|
25
|
+
|
|
26
|
+
await waitFor(() => getByTestId('effect-test'));
|
|
27
|
+
|
|
28
|
+
expect(getByTestId('effect-test').textContent).toEqual('World');
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { render, cleanup } from '@testing-library/react';
|
|
3
|
+
import { useMount } from '../src/index';
|
|
4
|
+
|
|
5
|
+
afterEach(cleanup);
|
|
6
|
+
|
|
7
|
+
const Component = () => {
|
|
8
|
+
const [state, setState] = useState<string | undefined>();
|
|
9
|
+
|
|
10
|
+
useMount(() => {
|
|
11
|
+
setState('test');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
return <p data-testid="mount-test">{state}</p>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
describe('useMount', () => {
|
|
18
|
+
test('should render "test"', () => {
|
|
19
|
+
const { getByTestId } = render(<Component />);
|
|
20
|
+
|
|
21
|
+
expect(getByTestId('mount-test').textContent).toEqual('test');
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { waitFor, cleanup } from '@testing-library/react';
|
|
3
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { http, HttpResponse } from 'msw';
|
|
5
|
+
import { server } from '@availity/mock/src/server';
|
|
6
|
+
import { USER_A2 } from '@availity/mock/src/routes';
|
|
7
|
+
import renderWithClient from './util';
|
|
8
|
+
import { useOrganizations } from '../src/index';
|
|
9
|
+
|
|
10
|
+
const queryClient = new QueryClient();
|
|
11
|
+
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
cleanup();
|
|
14
|
+
queryClient.clear();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const Component = () => {
|
|
18
|
+
const { data, error, status } = useOrganizations({}, { gcTime: 0, retry: false });
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div>
|
|
22
|
+
<h1>Status: {status}</h1>
|
|
23
|
+
<h1>Data: {JSON.stringify(data?.data)}</h1>
|
|
24
|
+
<h1>Error: {error?.message}</h1>
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
describe('useOrganizations', () => {
|
|
30
|
+
test('should return an error', async () => {
|
|
31
|
+
server.use(http.get(USER_A2, () => HttpResponse.error()));
|
|
32
|
+
|
|
33
|
+
const { getByText } = renderWithClient(queryClient, <Component />);
|
|
34
|
+
|
|
35
|
+
getByText('Status: pending');
|
|
36
|
+
await waitFor(() => {
|
|
37
|
+
expect(getByText('Status: error')).toBeDefined();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('should return organizations', async () => {
|
|
42
|
+
const { getByText } = renderWithClient(queryClient, <Component />);
|
|
43
|
+
|
|
44
|
+
getByText('Status: pending');
|
|
45
|
+
await waitFor(() => {
|
|
46
|
+
expect(getByText(/Techmania/)).toBeDefined();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { waitFor, cleanup } from '@testing-library/react';
|
|
3
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { http, HttpResponse } from 'msw';
|
|
5
|
+
import { server } from '@availity/mock/src/server';
|
|
6
|
+
import { PERMISSIONS } from '@availity/mock/src/routes';
|
|
7
|
+
import renderWithClient from './util';
|
|
8
|
+
import { usePermissions } from '../src/index';
|
|
9
|
+
|
|
10
|
+
const queryClient = new QueryClient();
|
|
11
|
+
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
cleanup();
|
|
14
|
+
queryClient.clear();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const Component = () => {
|
|
18
|
+
const { data, error, status } = usePermissions({}, { gcTime: 0, retry: false });
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div>
|
|
22
|
+
<h1>Status: {status}</h1>
|
|
23
|
+
<h1>Data: {JSON.stringify(data?.data)}</h1>
|
|
24
|
+
<h1>Error: {error?.message}</h1>
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
describe('usePermissions', () => {
|
|
30
|
+
test('should return an error', async () => {
|
|
31
|
+
server.use(http.get(PERMISSIONS, () => HttpResponse.error()));
|
|
32
|
+
|
|
33
|
+
const { getByText } = renderWithClient(queryClient, <Component />);
|
|
34
|
+
|
|
35
|
+
getByText('Status: pending');
|
|
36
|
+
await waitFor(() => {
|
|
37
|
+
expect(getByText('Status: error')).toBeDefined();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('should return permissions', async () => {
|
|
42
|
+
const { getByText } = renderWithClient(queryClient, <Component />);
|
|
43
|
+
|
|
44
|
+
getByText('Status: pending');
|
|
45
|
+
await waitFor(() => {
|
|
46
|
+
expect(getByText(/"id":"123"/)).toBeDefined();
|
|
47
|
+
});
|
|
48
|
+
await waitFor(() => {
|
|
49
|
+
expect(getByText(/Do the thing/)).toBeDefined();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { waitFor, cleanup } from '@testing-library/react';
|
|
3
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { http, HttpResponse } from 'msw';
|
|
5
|
+
import { server } from '@availity/mock/src/server';
|
|
6
|
+
import { PROVIDERS } from '@availity/mock/src/routes';
|
|
7
|
+
import renderWithClient from './util';
|
|
8
|
+
import { useProviders } from '../src/index';
|
|
9
|
+
|
|
10
|
+
const queryClient = new QueryClient();
|
|
11
|
+
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
cleanup();
|
|
14
|
+
queryClient.clear();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const Component = () => {
|
|
18
|
+
const { data, error, status } = useProviders({}, { gcTime: 0, retry: false });
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div>
|
|
22
|
+
<h1>Status: {status}</h1>
|
|
23
|
+
<h1>Data: {JSON.stringify(data?.data)}</h1>
|
|
24
|
+
<h1>Error: {error?.message}</h1>
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
describe('useProviders', () => {
|
|
30
|
+
test('should return an error', async () => {
|
|
31
|
+
server.use(http.get(PROVIDERS, () => HttpResponse.error()));
|
|
32
|
+
|
|
33
|
+
const { getByText } = renderWithClient(queryClient, <Component />);
|
|
34
|
+
|
|
35
|
+
getByText('Status: pending');
|
|
36
|
+
await waitFor(() => {
|
|
37
|
+
expect(getByText('Status: error')).toBeDefined();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('should return providers', async () => {
|
|
42
|
+
const { getByText } = renderWithClient(queryClient, <Component />);
|
|
43
|
+
|
|
44
|
+
getByText('Status: pending');
|
|
45
|
+
await waitFor(() => {
|
|
46
|
+
expect(getByText(/BITREX/)).toBeDefined();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { waitFor, cleanup } from '@testing-library/react';
|
|
3
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { http, HttpResponse } from 'msw';
|
|
5
|
+
import { server } from '@availity/mock/src/server';
|
|
6
|
+
import { STASH } from '@availity/mock/src/routes';
|
|
7
|
+
import { useStash } from '../src';
|
|
8
|
+
import renderWithClient from './util';
|
|
9
|
+
|
|
10
|
+
const queryClient = new QueryClient();
|
|
11
|
+
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
cleanup();
|
|
14
|
+
queryClient.clear();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const Component = ({ sessionId }: { sessionId: string }) => {
|
|
18
|
+
const { data, error, status } = useStash(sessionId, { gcTime: 0, retry: false });
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div>
|
|
22
|
+
<h1>Status: {status}</h1>
|
|
23
|
+
<h1>Data: {JSON.stringify(data)}</h1>
|
|
24
|
+
<h1>Error: {error?.message}</h1>
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
describe('useStash', () => {
|
|
30
|
+
test('should return an error', async () => {
|
|
31
|
+
server.use(http.get(STASH, () => HttpResponse.error()));
|
|
32
|
+
|
|
33
|
+
const { getByText } = renderWithClient(queryClient, <Component sessionId="test-session-id" />);
|
|
34
|
+
|
|
35
|
+
getByText('Status: pending');
|
|
36
|
+
await waitFor(() => {
|
|
37
|
+
expect(getByText('Status: error')).toBeDefined();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('should return stash data', async () => {
|
|
42
|
+
const { getByText } = renderWithClient(queryClient, <Component sessionId="test-session-id" />);
|
|
43
|
+
|
|
44
|
+
getByText('Status: pending');
|
|
45
|
+
await waitFor(() => {
|
|
46
|
+
expect(getByText(/"key":"value"/)).toBeDefined();
|
|
47
|
+
});
|
|
48
|
+
await waitFor(() => {
|
|
49
|
+
expect(getByText(/"nested":\{"foo":"bar"\}/)).toBeDefined();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('should not fetch when sessionId is empty', () => {
|
|
54
|
+
const { getByText } = renderWithClient(queryClient, <Component sessionId="" />);
|
|
55
|
+
|
|
56
|
+
expect(getByText('Status: pending')).toBeDefined();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, waitFor } from '@testing-library/react';
|
|
3
|
+
import { useTimeout } from '../src/index';
|
|
4
|
+
|
|
5
|
+
const Component = () => {
|
|
6
|
+
const timeout = useTimeout(1000);
|
|
7
|
+
|
|
8
|
+
return <p data-testid="timeout-test">{timeout ? 'True' : 'False'}</p>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
vi.useFakeTimers();
|
|
12
|
+
|
|
13
|
+
describe('useTimeout', () => {
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
vi.useRealTimers();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('should render "False"', () => {
|
|
19
|
+
const { getByTestId } = render(<Component />);
|
|
20
|
+
|
|
21
|
+
expect(getByTestId('timeout-test').textContent).toEqual('False');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test.todo('should render "True"', async () => {
|
|
25
|
+
const { getByTestId } = render(<Component />);
|
|
26
|
+
|
|
27
|
+
vi.runAllTimers();
|
|
28
|
+
|
|
29
|
+
await waitFor(() => {
|
|
30
|
+
expect(getByTestId('timeout-test').textContent).toEqual('True');
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, fireEvent, cleanup } from '@testing-library/react';
|
|
3
|
+
import { useToggle } from '../src/index';
|
|
4
|
+
|
|
5
|
+
afterEach(cleanup);
|
|
6
|
+
|
|
7
|
+
const Component = ({ initialToggle = false }: { initialToggle?: boolean }) => {
|
|
8
|
+
const [isToggled, toggle] = useToggle(initialToggle);
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<button type="button" data-testid="toggle-test" onClick={toggle}>
|
|
12
|
+
{isToggled ? 'Hello' : 'World'}
|
|
13
|
+
</button>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
describe('useToggle', () => {
|
|
18
|
+
test('should render "Hello"', () => {
|
|
19
|
+
const { getByTestId } = render(<Component />);
|
|
20
|
+
|
|
21
|
+
expect(getByTestId('toggle-test').textContent).toEqual('World');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('should render "World"', () => {
|
|
25
|
+
const { getByTestId } = render(<Component initialToggle />);
|
|
26
|
+
|
|
27
|
+
expect(getByTestId('toggle-test').textContent).toEqual('Hello');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('should toggle the state when clicked', () => {
|
|
31
|
+
const { getByTestId } = render(<Component />);
|
|
32
|
+
|
|
33
|
+
const button = getByTestId('toggle-test');
|
|
34
|
+
|
|
35
|
+
expect(button.textContent).toEqual('World');
|
|
36
|
+
|
|
37
|
+
fireEvent.click(button);
|
|
38
|
+
|
|
39
|
+
expect(getByTestId('toggle-test').textContent).toEqual('Hello');
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import { MemoryRouter, useNavigate, Routes, Route } from 'react-router-dom';
|
|
4
|
+
import avMessageMock from '@availity/message-core';
|
|
5
|
+
|
|
6
|
+
import useUpdateNav from '../src/useUpdateNav';
|
|
7
|
+
|
|
8
|
+
vi.mock('@availity/message-core');
|
|
9
|
+
|
|
10
|
+
const Component = () => {
|
|
11
|
+
const navigate = useNavigate();
|
|
12
|
+
|
|
13
|
+
useUpdateNav();
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<button
|
|
17
|
+
type="button"
|
|
18
|
+
onClick={() => {
|
|
19
|
+
navigate('/test');
|
|
20
|
+
}}
|
|
21
|
+
>
|
|
22
|
+
Click
|
|
23
|
+
</button>
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
describe('useUpdateNav', () => {
|
|
28
|
+
test.todo('calls avMessage on location change', () => {
|
|
29
|
+
render(
|
|
30
|
+
<MemoryRouter initialEntries={['/']}>n <Routes>
|
|
31
|
+
<Route path="/" element={<Component />} />
|
|
32
|
+
<Route path="/test" element={<div>Example</div>} />
|
|
33
|
+
</Routes>
|
|
34
|
+
</MemoryRouter>
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const button = screen.getByText('Click');
|
|
38
|
+
|
|
39
|
+
fireEvent.click(button);
|
|
40
|
+
|
|
41
|
+
expect(avMessageMock.send).toHaveBeenCalledWith({
|
|
42
|
+
event: 'navChange',
|
|
43
|
+
url: 'http://localhost:3000/',
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, waitFor, act, fireEvent } from '@testing-library/react';
|
|
3
|
+
import { useWindowDimensions } from '../src/index';
|
|
4
|
+
|
|
5
|
+
const Component = () => {
|
|
6
|
+
const { height, width } = useWindowDimensions();
|
|
7
|
+
return (
|
|
8
|
+
<div data-testid="window_dimensions">
|
|
9
|
+
<span data-testid="window_height">{height}</span>
|
|
10
|
+
<span data-testid="window_width">{width}</span>
|
|
11
|
+
</div>
|
|
12
|
+
);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe('useWindowDimensions', () => {
|
|
16
|
+
test('should show window dimensions', async () => {
|
|
17
|
+
const { getByTestId } = render(<Component />);
|
|
18
|
+
|
|
19
|
+
const element = getByTestId('window_dimensions');
|
|
20
|
+
expect(element).not.toBeNull();
|
|
21
|
+
|
|
22
|
+
act(() => {
|
|
23
|
+
window.innerWidth = 500;
|
|
24
|
+
window.innerHeight = 500;
|
|
25
|
+
|
|
26
|
+
fireEvent(window, new Event('resize'));
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const heightEl = getByTestId('window_height');
|
|
30
|
+
const widthEl = getByTestId('window_width');
|
|
31
|
+
|
|
32
|
+
await waitFor(() => {
|
|
33
|
+
expect(heightEl.textContent).toBe('500');
|
|
34
|
+
expect(widthEl.textContent).toBe('500');
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
package/tests/util.tsx
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { QueryClientProvider, QueryClient } from '@tanstack/react-query';
|
|
4
|
+
|
|
5
|
+
export default function renderWithClient(client: QueryClient, ui: React.ReactElement) {
|
|
6
|
+
return render(<QueryClientProvider client={client}>{ui}</QueryClientProvider>);
|
|
7
|
+
}
|
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineProject } from 'vitest/config';
|
|
2
|
+
|
|
3
|
+
export default defineProject({
|
|
4
|
+
test: {
|
|
5
|
+
name: 'hooks',
|
|
6
|
+
globals: true,
|
|
7
|
+
environment: 'jsdom',
|
|
8
|
+
setupFiles: ['../../vitest.setup.ts'],
|
|
9
|
+
include: ['src/**/*.test.{ts,tsx,js,jsx}', 'tests/**/*.test.{ts,tsx,js,jsx}'],
|
|
10
|
+
env: { TZ: 'UTC' },
|
|
11
|
+
server: {
|
|
12
|
+
deps: {
|
|
13
|
+
inline: [/lodash/, /@availity\/yup/],
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|
package/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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';
|
|
10
|
-
export { default as useUpdateNav } from './types/useUpdateNav';
|
|
11
|
-
export { default as useWindowDimensions } from './types/useWindowDimensions';
|
|
12
|
-
export { default as useStash } from './types/useStash';
|
package/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export { default as useEffectAsync } from './src/useEffectAsync';
|
|
2
|
-
export { default as useMount } from './src/useMount';
|
|
3
|
-
export { default as useTimeout } from './src/useTimeout';
|
|
4
|
-
export { default as useToggle } from './src/useToggle';
|
|
5
|
-
export { default as useCurrentRegion } from './src/useCurrentRegion';
|
|
6
|
-
export { default as useCurrentUser } from './src/useCurrentUser';
|
|
7
|
-
export { default as useProviders } from './src/useProviders';
|
|
8
|
-
export { default as usePermissions } from './src/usePermissions';
|
|
9
|
-
export { default as useOrganizations } from './src/useOrganizations';
|
|
10
|
-
export { default as useUpdateNav } from './src/useUpdateNav';
|
|
11
|
-
export { default as useWindowDimensions } from './src/useWindowDimensions';
|
|
12
|
-
export { default as useStash } from './src/useStash';
|
package/jest.config.js
DELETED
package/src/useCurrentRegion.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useQuery } from '@tanstack/react-query';
|
|
2
|
-
import { avRegionsApi } from '@availity/api-axios';
|
|
3
|
-
|
|
4
|
-
async function fetchRegion() {
|
|
5
|
-
const response = await avRegionsApi.getCurrentRegion();
|
|
6
|
-
|
|
7
|
-
return {
|
|
8
|
-
code: response?.data?.regions?.[0]?.id || '',
|
|
9
|
-
value: response?.data?.regions?.[0]?.value || '',
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default function useCurrentRegion(options) {
|
|
14
|
-
return useQuery(['region'], fetchRegion, options);
|
|
15
|
-
}
|
package/src/useCurrentUser.js
DELETED
package/src/useEffectAsync.js
DELETED
package/src/useMount.js
DELETED
package/src/useOrganizations.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { useQuery } from '@tanstack/react-query';
|
|
2
|
-
import { avOrganizationsApi } from '@availity/api-axios';
|
|
3
|
-
|
|
4
|
-
const fetchOrganization = async (config) => avOrganizationsApi.getOrganizations(config);
|
|
5
|
-
|
|
6
|
-
export default function useOrganization(config, options) {
|
|
7
|
-
return useQuery(['organizations', config], () => fetchOrganization(config), options);
|
|
8
|
-
}
|
package/src/usePermissions.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { useQuery } from '@tanstack/react-query';
|
|
2
|
-
import { avPermissionsApi } from '@availity/api-axios';
|
|
3
|
-
|
|
4
|
-
const fetchPermissions = async (config) => avPermissionsApi.getPermissions(config);
|
|
5
|
-
|
|
6
|
-
export default function usePermissions(config, options) {
|
|
7
|
-
return useQuery(['permissions', config], () => fetchPermissions(config), options);
|
|
8
|
-
}
|
package/src/useProviders.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { useQuery } from '@tanstack/react-query';
|
|
2
|
-
import { avProvidersApi } from '@availity/api-axios';
|
|
3
|
-
|
|
4
|
-
const fetchProviders = async (config) => avProvidersApi.getProviders(config.customerId, config);
|
|
5
|
-
|
|
6
|
-
export default function useProviders(config, options) {
|
|
7
|
-
return useQuery(['providers', config], () => fetchProviders(config), options);
|
|
8
|
-
}
|
package/src/useStash.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { avStashApi } from '@availity/api-axios';
|
|
2
|
-
import { useQuery } from '@tanstack/react-query';
|
|
3
|
-
|
|
4
|
-
const fetchStash = async (sessionId) => {
|
|
5
|
-
const response = await avStashApi.get(sessionId);
|
|
6
|
-
return response?.data;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export default function useStash(sessionId, options) {
|
|
10
|
-
return useQuery(['stash', sessionId], () => fetchStash(sessionId), {
|
|
11
|
-
enabled: !!sessionId,
|
|
12
|
-
...options,
|
|
13
|
-
});
|
|
14
|
-
}
|
package/tests/util.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
import { QueryClientProvider } from '@tanstack/react-query';
|
|
4
|
-
|
|
5
|
-
// Taken from https://github.com/tannerlinsley/react-query/blob/master/src/react/tests/utils.tsx#L6
|
|
6
|
-
export default function renderWithClient(client, ui) {
|
|
7
|
-
return render(<QueryClientProvider client={client}>{ui}</QueryClientProvider>);
|
|
8
|
-
}
|
package/tsconfig.spec.json
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../dist/out-tsc",
|
|
5
|
-
"module": "commonjs",
|
|
6
|
-
"types": ["jest", "node", "@testing-library/jest-dom"],
|
|
7
|
-
"allowJs": true
|
|
8
|
-
},
|
|
9
|
-
"include": ["**/*.test.js", "**/*.test.ts", "**/*.test.tsx", "**/*.d.ts"]
|
|
10
|
-
}
|