@dr.pogodin/react-utils 1.38.1 → 1.39.0
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/build/development/index.js +0 -9
- package/build/development/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +2 -0
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/utils/jest/index.js +28 -0
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/style.css +8 -8
- package/build/development/web.bundle.js +7 -17
- package/build/production/index.js +1 -1
- package/build/production/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js +1 -1
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/utils/jest/index.js +3 -2
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/style.css +1 -1
- package/build/production/style.css.map +1 -1
- package/build/production/web.bundle.js +1 -1
- package/build/production/web.bundle.js.map +1 -1
- package/build/types-code/index.d.ts +0 -1
- package/build/types-code/shared/components/Input/index.d.ts +1 -0
- package/build/types-code/shared/utils/jest/index.d.ts +3 -0
- package/package.json +5 -5
- package/src/index.ts +0 -2
- package/src/shared/components/Input/index.tsx +3 -0
- package/src/shared/components/Throbber/theme.scss +5 -5
- package/src/shared/utils/jest/index.tsx +43 -0
|
@@ -2,7 +2,6 @@ import 'styles/global.scss';
|
|
|
2
2
|
import type ServerT from './server';
|
|
3
3
|
declare const server: (typeof ServerT) | null;
|
|
4
4
|
declare const client: any;
|
|
5
|
-
export { default as api } from 'axios';
|
|
6
5
|
export { type AsyncCollectionLoaderT, type AsyncDataEnvelopeT, type AsyncDataLoaderT, type ForceT, type UseAsyncDataOptionsT, type UseAsyncDataResT, type UseGlobalStateResT, type ValueOrInitializerT, getGlobalState, GlobalStateProvider, newAsyncDataEnvelope, useAsyncCollection, useAsyncData, useGlobalState, withGlobalStateType, } from '@dr.pogodin/react-global-state';
|
|
7
6
|
export * from './shared/components';
|
|
8
7
|
export { type Listener, type Theme, config, Barrier, Emitter, isomorphy, getSsrContext, Semaphore, splitComponent, themed, ThemeProvider, time, webpack, withRetries, } from './shared/utils';
|
|
@@ -2,6 +2,7 @@ import { type Theme } from '@dr.pogodin/react-themes';
|
|
|
2
2
|
type ThemeKeyT = 'container' | 'input' | 'label';
|
|
3
3
|
declare const _default: import("@dr.pogodin/react-themes").ThemedComponent<React.InputHTMLAttributes<HTMLInputElement> & {
|
|
4
4
|
label?: React.ReactNode;
|
|
5
|
+
testId?: string;
|
|
5
6
|
theme: Theme<ThemeKeyT>;
|
|
6
7
|
} & React.RefAttributes<HTMLInputElement>>;
|
|
7
8
|
export default _default;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
1
2
|
import { type ReactNode, act } from 'react';
|
|
2
3
|
import { type RenderResult } from '@testing-library/react';
|
|
3
4
|
/**
|
|
@@ -25,6 +26,8 @@ export declare function unmockClientSide(): void;
|
|
|
25
26
|
* @return {string}
|
|
26
27
|
*/
|
|
27
28
|
export declare function getMockUuid(seed?: number): string;
|
|
29
|
+
export type AxiosRequestHandlerT = (config: AxiosRequestConfig) => Partial<AxiosResponse> | null | undefined;
|
|
30
|
+
export declare function mockAxios(handlers: AxiosRequestHandlerT[]): any;
|
|
28
31
|
/**
|
|
29
32
|
* Advances mock timers, and mock date by the specified time.
|
|
30
33
|
* @param {number} time Time step [ms].
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.39.0",
|
|
3
3
|
"bin": {
|
|
4
4
|
"react-utils-build": "bin/build.js",
|
|
5
5
|
"react-utils-setup": "bin/setup.js"
|
|
@@ -30,14 +30,14 @@
|
|
|
30
30
|
"lodash": "^4.17.21",
|
|
31
31
|
"morgan": "^1.10.0",
|
|
32
32
|
"node-forge": "^1.3.1",
|
|
33
|
-
"qs": "^6.12.
|
|
33
|
+
"qs": "^6.12.3",
|
|
34
34
|
"raf": "^3.4.1",
|
|
35
35
|
"react": "^18.3.1",
|
|
36
36
|
"react-dom": "^18.3.1",
|
|
37
37
|
"react-helmet": "^6.1.0",
|
|
38
38
|
"react-router-dom": "^6.24.1",
|
|
39
39
|
"request-ip": "^3.3.0",
|
|
40
|
-
"rimraf": "^
|
|
40
|
+
"rimraf": "^6.0.0",
|
|
41
41
|
"serialize-javascript": "^6.0.2",
|
|
42
42
|
"serve-favicon": "^2.5.0",
|
|
43
43
|
"source-map-support": "^0.5.21",
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
"react-refresh": "^0.14.2",
|
|
114
114
|
"regenerator-runtime": "^0.14.1",
|
|
115
115
|
"resolve-url-loader": "^5.0.0",
|
|
116
|
-
"sass": "^1.77.
|
|
116
|
+
"sass": "^1.77.7",
|
|
117
117
|
"sass-loader": "^14.2.1",
|
|
118
118
|
"sitemap": "^8.0.0",
|
|
119
119
|
"stylelint": "^16.6.1",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"tstyche": "^2.0.0",
|
|
124
124
|
"typed-scss-modules": "^8.0.1",
|
|
125
125
|
"typescript": "^5.5.3",
|
|
126
|
-
"typescript-eslint": "^7.
|
|
126
|
+
"typescript-eslint": "^7.16.0",
|
|
127
127
|
"webpack": "^5.92.1",
|
|
128
128
|
"webpack-dev-middleware": "^7.2.1",
|
|
129
129
|
"webpack-hot-middleware": "^2.26.1",
|
package/src/index.ts
CHANGED
|
@@ -8,8 +8,6 @@ const server = webpack.requireWeak('./server', __dirname) as (typeof ServerT) |
|
|
|
8
8
|
|
|
9
9
|
const client = server ? undefined : require('./client').default;
|
|
10
10
|
|
|
11
|
-
export { default as api } from 'axios';
|
|
12
|
-
|
|
13
11
|
export {
|
|
14
12
|
type AsyncCollectionLoaderT,
|
|
15
13
|
type AsyncDataEnvelopeT,
|
|
@@ -11,6 +11,7 @@ type ThemeKeyT =
|
|
|
11
11
|
|
|
12
12
|
type PropsT = React.InputHTMLAttributes<HTMLInputElement> & {
|
|
13
13
|
label?: React.ReactNode;
|
|
14
|
+
testId?: string;
|
|
14
15
|
theme: Theme<ThemeKeyT>;
|
|
15
16
|
};
|
|
16
17
|
|
|
@@ -26,6 +27,7 @@ type PropsT = React.InputHTMLAttributes<HTMLInputElement> & {
|
|
|
26
27
|
const Input = forwardRef<HTMLInputElement, PropsT>((
|
|
27
28
|
{
|
|
28
29
|
label,
|
|
30
|
+
testId,
|
|
29
31
|
theme,
|
|
30
32
|
...rest
|
|
31
33
|
}: PropsT,
|
|
@@ -35,6 +37,7 @@ const Input = forwardRef<HTMLInputElement, PropsT>((
|
|
|
35
37
|
{ label === undefined ? null : <div className={theme.label}>{label}</div> }
|
|
36
38
|
<input
|
|
37
39
|
className={theme.input}
|
|
40
|
+
data-testid={testId}
|
|
38
41
|
ref={ref}
|
|
39
42
|
{...rest} // eslint-disable-line react/jsx-props-no-spreading
|
|
40
43
|
/>
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
@keyframes bouncing {
|
|
2
|
+
from { top: -0.3em; }
|
|
3
|
+
to { top: 0.3em; }
|
|
4
|
+
}
|
|
5
|
+
|
|
1
6
|
*,
|
|
2
7
|
.context,
|
|
3
8
|
.ad.hoc {
|
|
@@ -6,11 +11,6 @@
|
|
|
6
11
|
}
|
|
7
12
|
|
|
8
13
|
&.circle {
|
|
9
|
-
@keyframes bouncing {
|
|
10
|
-
from { top: -0.3em; }
|
|
11
|
-
to { top: 0.3em; }
|
|
12
|
-
}
|
|
13
|
-
|
|
14
14
|
animation: bouncing 0.4s ease-in infinite alternate;
|
|
15
15
|
background: black;
|
|
16
16
|
border-radius: 0.3em;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/* global jest, document */
|
|
2
2
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
3
3
|
|
|
4
|
+
import type {
|
|
5
|
+
AxiosRequestConfig,
|
|
6
|
+
AxiosResponse,
|
|
7
|
+
InternalAxiosRequestConfig,
|
|
8
|
+
} from 'axios';
|
|
9
|
+
|
|
4
10
|
import mockdate from 'mockdate';
|
|
5
11
|
import { type ReactNode, act } from 'react';
|
|
6
12
|
import { type Root, createRoot } from 'react-dom/client';
|
|
@@ -53,6 +59,43 @@ export function getMockUuid(seed = 0) {
|
|
|
53
59
|
return `${x.slice(0, 8)}-${x.slice(8, 12)}-${x.slice(12, 16)}-${x.slice(16, 20)}-${x.slice(20)}`;
|
|
54
60
|
}
|
|
55
61
|
|
|
62
|
+
export type AxiosRequestHandlerT =
|
|
63
|
+
(config: AxiosRequestConfig) => Partial<AxiosResponse> | null | undefined;
|
|
64
|
+
|
|
65
|
+
export function mockAxios(handlers: AxiosRequestHandlerT[]) {
|
|
66
|
+
const axios = jest.requireActual('axios');
|
|
67
|
+
|
|
68
|
+
axios.defaults.adapter = async (config: AxiosRequestConfig): Promise<AxiosResponse> => {
|
|
69
|
+
for (let i = 0; i < handlers.length; ++i) {
|
|
70
|
+
const res = handlers[i]?.(config);
|
|
71
|
+
if (res) {
|
|
72
|
+
return {
|
|
73
|
+
config: config as InternalAxiosRequestConfig,
|
|
74
|
+
data: null,
|
|
75
|
+
headers: {},
|
|
76
|
+
status: 200,
|
|
77
|
+
statusText: 'OK',
|
|
78
|
+
...res,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Fallback to the regular network request.
|
|
84
|
+
const res = await axios({ ...config, adapter: ['xhr', 'http', 'fetch'] });
|
|
85
|
+
|
|
86
|
+
console.warn(
|
|
87
|
+
'Network request has not been mocked for a test.\n\nConfig:\n',
|
|
88
|
+
config,
|
|
89
|
+
'\n\nResult:\n',
|
|
90
|
+
JSON.stringify(res, null, 2),
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
return res;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
return axios;
|
|
97
|
+
}
|
|
98
|
+
|
|
56
99
|
/**
|
|
57
100
|
* Advances mock timers, and mock date by the specified time.
|
|
58
101
|
* @param {number} time Time step [ms].
|