@websolutespa/bom-mixer-hooks 3.1.0 → 3.1.2
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 +4 -0
- package/package.json +7 -7
- package/src/useApi/useApi.test.tsx +193 -193
- package/src/useCollectionApi/useCollectionApi.test.tsx +194 -194
- package/src/useHttp/useHttp.test.tsx +197 -197
- package/src/usePagination/usePagination.test.ts +79 -79
- package/src/usePaginationLegacy/usePaginationLegacy.test.ts +1 -1
- package/src/useSearchParams/useSearchParams.test.ts +65 -65
- package/src/useSearchParamsEncoded/useSearchParamsEncoded.test.ts +64 -64
- package/src/useSearchParamsQs/useSearchParamsQs.test.ts +82 -82
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import { act, renderHook } from '@testing-library/react';
|
|
2
|
-
import { useRouter as useCompatRouter } from 'next/compat/router';
|
|
3
|
-
import { describe, expect, it, vi, type Mock } from 'vitest';
|
|
4
|
-
import { useSearchParams } from './useSearchParams';
|
|
5
|
-
|
|
6
|
-
vi.mock('next/compat/router', () => ({ useRouter: vi.fn() }));
|
|
7
|
-
|
|
8
|
-
const useRouter = useCompatRouter as unknown as Mock;
|
|
9
|
-
|
|
10
|
-
describe('useSearchParams', () => {
|
|
11
|
-
|
|
12
|
-
it('should work correctly', async () => {
|
|
13
|
-
useRouter.mockReturnValue({
|
|
14
|
-
asPath: '',
|
|
15
|
-
});
|
|
16
|
-
const params = {};
|
|
17
|
-
const { result } = renderHook(() => useSearchParams());
|
|
18
|
-
expect(result.current.params).toEqual(params);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('should work correctly with params', async () => {
|
|
22
|
-
useRouter.mockReturnValue({
|
|
23
|
-
asPath: '?flag=1',
|
|
24
|
-
});
|
|
25
|
-
const params = { flag: '1' };
|
|
26
|
-
const { result } = renderHook(() => useSearchParams());
|
|
27
|
-
expect(result.current.params).toEqual(params);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should replace search params silently', async () => {
|
|
31
|
-
const handler = vi.fn();
|
|
32
|
-
useRouter.mockReturnValue({
|
|
33
|
-
asPath: '',
|
|
34
|
-
replace: handler,
|
|
35
|
-
});
|
|
36
|
-
const params = { flag: '1' };
|
|
37
|
-
const { result } = renderHook(() => useSearchParams());
|
|
38
|
-
expect(result.current.replaceParamsSilently).toEqual(expect.any(Function));
|
|
39
|
-
act(() => result.current.replaceParamsSilently(params));
|
|
40
|
-
expect(handler).toBeCalledTimes(1);
|
|
41
|
-
expect(handler).toBeCalledWith('', {
|
|
42
|
-
pathname: '',
|
|
43
|
-
query: { flag: '1' },
|
|
44
|
-
}, { shallow: true, scroll: false });
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should replace search params', async () => {
|
|
48
|
-
const handler = vi.fn();
|
|
49
|
-
useRouter.mockReturnValue({
|
|
50
|
-
asPath: '',
|
|
51
|
-
replace: handler,
|
|
52
|
-
});
|
|
53
|
-
const params = { flag: '1' };
|
|
54
|
-
const { result } = renderHook(() => useSearchParams());
|
|
55
|
-
window.history.replaceState = vi.fn();
|
|
56
|
-
expect(result.current.replaceParams).toEqual(expect.any(Function));
|
|
57
|
-
act(() => result.current.replaceParams(params));
|
|
58
|
-
expect(handler).toBeCalledTimes(1);
|
|
59
|
-
expect(handler).toBeCalledWith({
|
|
60
|
-
pathname: '',
|
|
61
|
-
query: { flag: '1' },
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
});
|
|
1
|
+
import { act, renderHook } from '@testing-library/react';
|
|
2
|
+
import { useRouter as useCompatRouter } from 'next/compat/router';
|
|
3
|
+
import { describe, expect, it, vi, type Mock } from 'vitest';
|
|
4
|
+
import { useSearchParams } from './useSearchParams';
|
|
5
|
+
|
|
6
|
+
vi.mock('next/compat/router', () => ({ useRouter: vi.fn() }));
|
|
7
|
+
|
|
8
|
+
const useRouter = useCompatRouter as unknown as Mock;
|
|
9
|
+
|
|
10
|
+
describe('useSearchParams', () => {
|
|
11
|
+
|
|
12
|
+
it('should work correctly', async () => {
|
|
13
|
+
useRouter.mockReturnValue({
|
|
14
|
+
asPath: '',
|
|
15
|
+
});
|
|
16
|
+
const params = {};
|
|
17
|
+
const { result } = renderHook(() => useSearchParams());
|
|
18
|
+
expect(result.current.params).toEqual(params);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should work correctly with params', async () => {
|
|
22
|
+
useRouter.mockReturnValue({
|
|
23
|
+
asPath: '?flag=1',
|
|
24
|
+
});
|
|
25
|
+
const params = { flag: '1' };
|
|
26
|
+
const { result } = renderHook(() => useSearchParams());
|
|
27
|
+
expect(result.current.params).toEqual(params);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should replace search params silently', async () => {
|
|
31
|
+
const handler = vi.fn();
|
|
32
|
+
useRouter.mockReturnValue({
|
|
33
|
+
asPath: '',
|
|
34
|
+
replace: handler,
|
|
35
|
+
});
|
|
36
|
+
const params = { flag: '1' };
|
|
37
|
+
const { result } = renderHook(() => useSearchParams());
|
|
38
|
+
expect(result.current.replaceParamsSilently).toEqual(expect.any(Function));
|
|
39
|
+
act(() => result.current.replaceParamsSilently(params));
|
|
40
|
+
expect(handler).toBeCalledTimes(1);
|
|
41
|
+
expect(handler).toBeCalledWith('', {
|
|
42
|
+
pathname: '',
|
|
43
|
+
query: { flag: '1' },
|
|
44
|
+
}, { shallow: true, scroll: false });
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should replace search params', async () => {
|
|
48
|
+
const handler = vi.fn();
|
|
49
|
+
useRouter.mockReturnValue({
|
|
50
|
+
asPath: '',
|
|
51
|
+
replace: handler,
|
|
52
|
+
});
|
|
53
|
+
const params = { flag: '1' };
|
|
54
|
+
const { result } = renderHook(() => useSearchParams());
|
|
55
|
+
window.history.replaceState = vi.fn();
|
|
56
|
+
expect(result.current.replaceParams).toEqual(expect.any(Function));
|
|
57
|
+
act(() => result.current.replaceParams(params));
|
|
58
|
+
expect(handler).toBeCalledTimes(1);
|
|
59
|
+
expect(handler).toBeCalledWith({
|
|
60
|
+
pathname: '',
|
|
61
|
+
query: { flag: '1' },
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
});
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import { act, renderHook } from '@testing-library/react';
|
|
2
|
-
import { useRouter as useCompatRouter } from 'next/compat/router';
|
|
3
|
-
import { describe, expect, it, vi, type Mock } from 'vitest';
|
|
4
|
-
import { useSearchParamsEncoded } from './useSearchParamsEncoded';
|
|
5
|
-
|
|
6
|
-
vi.mock('next/compat/router', () => ({ useRouter: vi.fn() }));
|
|
7
|
-
|
|
8
|
-
const useRouter = useCompatRouter as unknown as Mock;
|
|
9
|
-
|
|
10
|
-
describe('useSearchParamsEncoded', () => {
|
|
11
|
-
|
|
12
|
-
it('should work correctly', async () => {
|
|
13
|
-
useRouter.mockReturnValue({
|
|
14
|
-
asPath: '',
|
|
15
|
-
});
|
|
16
|
-
const { result } = renderHook(() => useSearchParamsEncoded());
|
|
17
|
-
expect(result.current.params).toEqual(null);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should work correctly with params', async () => {
|
|
21
|
-
useRouter.mockReturnValue({
|
|
22
|
-
asPath: '?params=eyJmbGFnIjoiMSJ9',
|
|
23
|
-
});
|
|
24
|
-
const params = { flag: '1' };
|
|
25
|
-
const { result } = renderHook(() => useSearchParamsEncoded());
|
|
26
|
-
expect(result.current.params).toEqual(params);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should replace search params silently', async () => {
|
|
30
|
-
const handler = vi.fn();
|
|
31
|
-
useRouter.mockReturnValue({
|
|
32
|
-
asPath: '',
|
|
33
|
-
replace: handler,
|
|
34
|
-
});
|
|
35
|
-
const params = { flag: '1' };
|
|
36
|
-
const { result } = renderHook(() => useSearchParamsEncoded());
|
|
37
|
-
expect(result.current.replaceParamsSilently).toEqual(expect.any(Function));
|
|
38
|
-
act(() => result.current.replaceParamsSilently(params));
|
|
39
|
-
expect(handler).toBeCalledTimes(1);
|
|
40
|
-
expect(handler).toBeCalledWith('', {
|
|
41
|
-
pathname: '',
|
|
42
|
-
query: { params: 'eyJmbGFnIjoiMSJ9' },
|
|
43
|
-
}, { shallow: true, scroll: false });
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('should replace search params', async () => {
|
|
47
|
-
const handler = vi.fn();
|
|
48
|
-
useRouter.mockReturnValue({
|
|
49
|
-
asPath: '',
|
|
50
|
-
replace: handler,
|
|
51
|
-
});
|
|
52
|
-
const params = { flag: '1' };
|
|
53
|
-
const { result } = renderHook(() => useSearchParamsEncoded());
|
|
54
|
-
window.history.replaceState = vi.fn();
|
|
55
|
-
expect(result.current.replaceParams).toEqual(expect.any(Function));
|
|
56
|
-
act(() => result.current.replaceParams(params));
|
|
57
|
-
expect(handler).toBeCalledTimes(1);
|
|
58
|
-
expect(handler).toBeCalledWith({
|
|
59
|
-
pathname: '',
|
|
60
|
-
query: { params: 'eyJmbGFnIjoiMSJ9' },
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
});
|
|
1
|
+
import { act, renderHook } from '@testing-library/react';
|
|
2
|
+
import { useRouter as useCompatRouter } from 'next/compat/router';
|
|
3
|
+
import { describe, expect, it, vi, type Mock } from 'vitest';
|
|
4
|
+
import { useSearchParamsEncoded } from './useSearchParamsEncoded';
|
|
5
|
+
|
|
6
|
+
vi.mock('next/compat/router', () => ({ useRouter: vi.fn() }));
|
|
7
|
+
|
|
8
|
+
const useRouter = useCompatRouter as unknown as Mock;
|
|
9
|
+
|
|
10
|
+
describe('useSearchParamsEncoded', () => {
|
|
11
|
+
|
|
12
|
+
it('should work correctly', async () => {
|
|
13
|
+
useRouter.mockReturnValue({
|
|
14
|
+
asPath: '',
|
|
15
|
+
});
|
|
16
|
+
const { result } = renderHook(() => useSearchParamsEncoded());
|
|
17
|
+
expect(result.current.params).toEqual(null);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should work correctly with params', async () => {
|
|
21
|
+
useRouter.mockReturnValue({
|
|
22
|
+
asPath: '?params=eyJmbGFnIjoiMSJ9',
|
|
23
|
+
});
|
|
24
|
+
const params = { flag: '1' };
|
|
25
|
+
const { result } = renderHook(() => useSearchParamsEncoded());
|
|
26
|
+
expect(result.current.params).toEqual(params);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should replace search params silently', async () => {
|
|
30
|
+
const handler = vi.fn();
|
|
31
|
+
useRouter.mockReturnValue({
|
|
32
|
+
asPath: '',
|
|
33
|
+
replace: handler,
|
|
34
|
+
});
|
|
35
|
+
const params = { flag: '1' };
|
|
36
|
+
const { result } = renderHook(() => useSearchParamsEncoded());
|
|
37
|
+
expect(result.current.replaceParamsSilently).toEqual(expect.any(Function));
|
|
38
|
+
act(() => result.current.replaceParamsSilently(params));
|
|
39
|
+
expect(handler).toBeCalledTimes(1);
|
|
40
|
+
expect(handler).toBeCalledWith('', {
|
|
41
|
+
pathname: '',
|
|
42
|
+
query: { params: 'eyJmbGFnIjoiMSJ9' },
|
|
43
|
+
}, { shallow: true, scroll: false });
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should replace search params', async () => {
|
|
47
|
+
const handler = vi.fn();
|
|
48
|
+
useRouter.mockReturnValue({
|
|
49
|
+
asPath: '',
|
|
50
|
+
replace: handler,
|
|
51
|
+
});
|
|
52
|
+
const params = { flag: '1' };
|
|
53
|
+
const { result } = renderHook(() => useSearchParamsEncoded());
|
|
54
|
+
window.history.replaceState = vi.fn();
|
|
55
|
+
expect(result.current.replaceParams).toEqual(expect.any(Function));
|
|
56
|
+
act(() => result.current.replaceParams(params));
|
|
57
|
+
expect(handler).toBeCalledTimes(1);
|
|
58
|
+
expect(handler).toBeCalledWith({
|
|
59
|
+
pathname: '',
|
|
60
|
+
query: { params: 'eyJmbGFnIjoiMSJ9' },
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
});
|
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
import { act, renderHook } from '@testing-library/react';
|
|
2
|
-
import { useRouter as useCompatRouter } from 'next/compat/router';
|
|
3
|
-
import { describe, expect, it, vi, type Mock } from 'vitest';
|
|
4
|
-
import { useSearchParamsQs } from './useSearchParamsQs';
|
|
5
|
-
|
|
6
|
-
vi.mock('next/compat/router', () => ({ useRouter: vi.fn() }));
|
|
7
|
-
|
|
8
|
-
const useRouter = useCompatRouter as unknown as Mock;
|
|
9
|
-
|
|
10
|
-
describe('useSearchParamsQs', () => {
|
|
11
|
-
|
|
12
|
-
it('should work correctly', async () => {
|
|
13
|
-
useRouter.mockReturnValue({
|
|
14
|
-
asPath: '',
|
|
15
|
-
});
|
|
16
|
-
const { result } = renderHook(() => useSearchParamsQs());
|
|
17
|
-
expect(result.current.params).toEqual({});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should work correctly with params', async () => {
|
|
21
|
-
useRouter.mockReturnValue({
|
|
22
|
-
asPath: '?where[market][equals]=ww',
|
|
23
|
-
});
|
|
24
|
-
const params = {
|
|
25
|
-
where: {
|
|
26
|
-
market: {
|
|
27
|
-
equals: 'ww',
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
const { result } = renderHook(() => useSearchParamsQs());
|
|
32
|
-
expect(result.current.params).toEqual(params);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should replace search params silently', async () => {
|
|
36
|
-
const handler = vi.fn();
|
|
37
|
-
useRouter.mockReturnValue({
|
|
38
|
-
asPath: '',
|
|
39
|
-
replace: handler,
|
|
40
|
-
});
|
|
41
|
-
const params = {
|
|
42
|
-
where: {
|
|
43
|
-
market: {
|
|
44
|
-
equals: 'ww',
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
const { result } = renderHook(() => useSearchParamsQs());
|
|
49
|
-
expect(result.current.replaceParamsSilently).toEqual(expect.any(Function));
|
|
50
|
-
act(() => result.current.replaceParamsSilently(params));
|
|
51
|
-
expect(handler).toBeCalledTimes(1);
|
|
52
|
-
expect(handler).toBeCalledWith('', {
|
|
53
|
-
pathname: '',
|
|
54
|
-
query: 'where[market][equals]=ww',
|
|
55
|
-
}, { shallow: true, scroll: false });
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should replace search params', async () => {
|
|
59
|
-
const handler = vi.fn();
|
|
60
|
-
useRouter.mockReturnValue({
|
|
61
|
-
asPath: '',
|
|
62
|
-
replace: handler,
|
|
63
|
-
});
|
|
64
|
-
const params = {
|
|
65
|
-
where: {
|
|
66
|
-
market: {
|
|
67
|
-
equals: 'ww',
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
const { result } = renderHook(() => useSearchParamsQs());
|
|
72
|
-
window.history.replaceState = vi.fn();
|
|
73
|
-
expect(result.current.replaceParams).toEqual(expect.any(Function));
|
|
74
|
-
act(() => result.current.replaceParams(params));
|
|
75
|
-
expect(handler).toBeCalledTimes(1);
|
|
76
|
-
expect(handler).toBeCalledWith({
|
|
77
|
-
pathname: '',
|
|
78
|
-
query: 'where[market][equals]=ww',
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
});
|
|
1
|
+
import { act, renderHook } from '@testing-library/react';
|
|
2
|
+
import { useRouter as useCompatRouter } from 'next/compat/router';
|
|
3
|
+
import { describe, expect, it, vi, type Mock } from 'vitest';
|
|
4
|
+
import { useSearchParamsQs } from './useSearchParamsQs';
|
|
5
|
+
|
|
6
|
+
vi.mock('next/compat/router', () => ({ useRouter: vi.fn() }));
|
|
7
|
+
|
|
8
|
+
const useRouter = useCompatRouter as unknown as Mock;
|
|
9
|
+
|
|
10
|
+
describe('useSearchParamsQs', () => {
|
|
11
|
+
|
|
12
|
+
it('should work correctly', async () => {
|
|
13
|
+
useRouter.mockReturnValue({
|
|
14
|
+
asPath: '',
|
|
15
|
+
});
|
|
16
|
+
const { result } = renderHook(() => useSearchParamsQs());
|
|
17
|
+
expect(result.current.params).toEqual({});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should work correctly with params', async () => {
|
|
21
|
+
useRouter.mockReturnValue({
|
|
22
|
+
asPath: '?where[market][equals]=ww',
|
|
23
|
+
});
|
|
24
|
+
const params = {
|
|
25
|
+
where: {
|
|
26
|
+
market: {
|
|
27
|
+
equals: 'ww',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
const { result } = renderHook(() => useSearchParamsQs());
|
|
32
|
+
expect(result.current.params).toEqual(params);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should replace search params silently', async () => {
|
|
36
|
+
const handler = vi.fn();
|
|
37
|
+
useRouter.mockReturnValue({
|
|
38
|
+
asPath: '',
|
|
39
|
+
replace: handler,
|
|
40
|
+
});
|
|
41
|
+
const params = {
|
|
42
|
+
where: {
|
|
43
|
+
market: {
|
|
44
|
+
equals: 'ww',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
const { result } = renderHook(() => useSearchParamsQs());
|
|
49
|
+
expect(result.current.replaceParamsSilently).toEqual(expect.any(Function));
|
|
50
|
+
act(() => result.current.replaceParamsSilently(params));
|
|
51
|
+
expect(handler).toBeCalledTimes(1);
|
|
52
|
+
expect(handler).toBeCalledWith('', {
|
|
53
|
+
pathname: '',
|
|
54
|
+
query: 'where[market][equals]=ww',
|
|
55
|
+
}, { shallow: true, scroll: false });
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should replace search params', async () => {
|
|
59
|
+
const handler = vi.fn();
|
|
60
|
+
useRouter.mockReturnValue({
|
|
61
|
+
asPath: '',
|
|
62
|
+
replace: handler,
|
|
63
|
+
});
|
|
64
|
+
const params = {
|
|
65
|
+
where: {
|
|
66
|
+
market: {
|
|
67
|
+
equals: 'ww',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
const { result } = renderHook(() => useSearchParamsQs());
|
|
72
|
+
window.history.replaceState = vi.fn();
|
|
73
|
+
expect(result.current.replaceParams).toEqual(expect.any(Function));
|
|
74
|
+
act(() => result.current.replaceParams(params));
|
|
75
|
+
expect(handler).toBeCalledTimes(1);
|
|
76
|
+
expect(handler).toBeCalledWith({
|
|
77
|
+
pathname: '',
|
|
78
|
+
query: 'where[market][equals]=ww',
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
});
|