Skip to content

Commit 8f63cf7

Browse files
authored
[CHORE] Specs. Improvements (#202)
* [CHORE] Improve types * [CHORE] Example of actions & thunks specs * [CHORE] Example of reducer & selectors specs * [CHORE] Update dependencies
1 parent 92c0332 commit 8f63cf7

File tree

18 files changed

+580
-228
lines changed

18 files changed

+580
-228
lines changed

kafka-ui-react-app/package-lock.json

Lines changed: 321 additions & 177 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kafka-ui-react-app/package.json

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@hookform/error-message": "0.0.5",
7+
"@types/node-fetch": "^2.5.8",
68
"bulma": "^0.9.2",
79
"bulma-switch": "^2.0.0",
810
"classnames": "^2.2.6",
9-
"date-fns": "^2.16.1",
11+
"date-fns": "^2.17.0",
1012
"eslint-import-resolver-node": "^0.3.4",
11-
"eslint-import-resolver-typescript": "^2.3.0",
13+
"eslint-import-resolver-typescript": "^2.4.0",
1214
"immer": "^8.0.1",
1315
"lodash": "^4.17.20",
16+
"node-fetch": "^2.6.1",
1417
"pretty-ms": "^6.0.1",
1518
"react": "^17.0.1",
16-
"react-datepicker": "^3.3.0",
19+
"react-datepicker": "^3.5.0",
1720
"react-dom": "^17.0.1",
18-
"react-hook-form": "^4.10.2",
21+
"react-hook-form": "^6.15.1",
1922
"react-json-tree": "^0.13.0",
2023
"react-multi-select-component": "^2.0.14",
2124
"react-redux": "^7.2.2",
@@ -73,39 +76,42 @@
7376
"@types/enzyme": "^3.10.8",
7477
"@types/jest": "^26.0.20",
7578
"@types/lodash": "^4.14.165",
76-
"@types/node": "^12.19.8",
77-
"@types/react": "^17.0.0",
79+
"@types/node": "^12.20.2",
80+
"@types/react": "^17.0.2",
7881
"@types/react-datepicker": "^3.1.1",
79-
"@types/react-dom": "^17.0.0",
82+
"@types/react-dom": "^17.0.1",
8083
"@types/react-redux": "^7.1.11",
8184
"@types/react-router-dom": "^5.1.6",
8285
"@types/redux": "^3.6.0",
86+
"@types/redux-mock-store": "^1.0.2",
8387
"@types/redux-thunk": "^2.1.0",
8488
"@types/uuid": "^8.3.0",
85-
"@typescript-eslint/eslint-plugin": "^4.9.0",
86-
"@typescript-eslint/parser": "^4.9.0",
89+
"@typescript-eslint/eslint-plugin": "^4.15.1",
90+
"@typescript-eslint/parser": "^4.15.1",
8791
"@wojtekmaj/enzyme-adapter-react-17": "^0.4.1",
8892
"dotenv": "^8.2.0",
8993
"enzyme": "^3.11.0",
9094
"enzyme-to-json": "^3.6.1",
91-
"eslint": "^7.14.0",
95+
"eslint": "^7.20.0",
9296
"eslint-config-airbnb": "^18.2.1",
93-
"eslint-config-airbnb-typescript": "^12.0.0",
97+
"eslint-config-airbnb-typescript": "^12.3.1",
9498
"eslint-config-prettier": "^6.15.0",
9599
"eslint-plugin-import": "^2.22.1",
96100
"eslint-plugin-jsx-a11y": "^6.4.1",
97101
"eslint-plugin-prettier": "^3.1.4",
98102
"eslint-plugin-react": "^7.21.5",
99103
"eslint-plugin-react-hooks": "^2.5.1",
100104
"esprint": "^0.6.0",
105+
"fetch-mock-jest": "^1.5.1",
101106
"husky": "^4.3.0",
102-
"lint-staged": "^10.5.2",
107+
"lint-staged": "^10.5.4",
103108
"node-sass": "^4.14.1",
104109
"prettier": "^2.2.1",
105110
"react-scripts": "4.0.2",
106-
"ts-jest": "^26.4.4",
111+
"redux-mock-store": "^1.5.4",
112+
"ts-jest": "^26.5.1",
107113
"ts-node": "^9.1.1",
108-
"typescript": "~4.1.2"
114+
"typescript": "^4.1.5"
109115
},
110116
"engines": {
111117
"node": ">=14.15.4"

kafka-ui-react-app/src/components/Topics/Edit/Edit.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
CleanupPolicy,
99
} from 'redux/interfaces';
1010
import { TopicConfig } from 'generated-sources';
11-
import { useForm, FormContext } from 'react-hook-form';
11+
import { useForm, FormProvider } from 'react-hook-form';
1212
import { camelCase } from 'lodash';
1313

1414
import TopicForm from '../shared/Form/TopicForm';
@@ -127,15 +127,15 @@ const Edit: React.FC<Props> = ({
127127

128128
<div className="box">
129129
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
130-
<FormContext {...methods}>
130+
<FormProvider {...methods}>
131131
<TopicForm
132132
topicName={topicName}
133133
config={config}
134134
isSubmitting={isSubmitting}
135135
isEditing
136136
onSubmit={methods.handleSubmit(onSubmit)}
137137
/>
138-
</FormContext>
138+
</FormProvider>
139139
</div>
140140
</div>
141141
);

kafka-ui-react-app/src/components/Topics/New/New.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { ClusterName, TopicName, TopicFormDataRaw } from 'redux/interfaces';
3-
import { useForm, FormContext } from 'react-hook-form';
3+
import { useForm, FormProvider } from 'react-hook-form';
44

55
import Breadcrumb from 'components/common/Breadcrumb/Breadcrumb';
66
import { clusterTopicsPath } from 'lib/paths';
@@ -54,12 +54,12 @@ const New: React.FC<Props> = ({
5454

5555
<div className="box">
5656
{/* eslint-disable react/jsx-props-no-spreading */}
57-
<FormContext {...methods}>
57+
<FormProvider {...methods}>
5858
<TopicForm
5959
isSubmitting={isSubmitting}
6060
onSubmit={methods.handleSubmit(onSubmit)}
6161
/>
62-
</FormContext>
62+
</FormProvider>
6363
</div>
6464
</div>
6565
);

kafka-ui-react-app/src/components/Topics/shared/Form/CustomParams/CustomParamSelect.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
2-
import { useFormContext, ErrorMessage } from 'react-hook-form';
2+
import { useFormContext } from 'react-hook-form';
33
import { TopicConfigValue } from 'redux/interfaces';
4+
import { ErrorMessage } from '@hookform/error-message';
45
import CustomParamOptions from './CustomParamOptions';
56
import { INDEX_PREFIX } from './CustomParams';
67

@@ -19,11 +20,11 @@ const CustomParamSelect: React.FC<Props> = ({
1920
existingFields,
2021
onNameChange,
2122
}) => {
22-
const { register, errors, getValues, triggerValidation } = useFormContext();
23+
const { register, errors, getValues, trigger } = useFormContext();
2324
const optInputName = `${index}[name]`;
2425

2526
const selectedMustBeUniq = (selected: string) => {
26-
const values = getValues({ nest: true });
27+
const values = getValues();
2728
const customParamsValues: TopicConfigValue = values.customParams;
2829

2930
const valid = !Object.entries(customParamsValues).some(
@@ -40,7 +41,7 @@ const CustomParamSelect: React.FC<Props> = ({
4041
const onChange = (inputName: string) => (
4142
event: React.ChangeEvent<HTMLSelectElement>
4243
) => {
43-
triggerValidation(inputName);
44+
trigger(inputName);
4445
onNameChange(index, event.target.value);
4546
};
4647

kafka-ui-react-app/src/components/Topics/shared/Form/CustomParams/CustomParamValue.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
2-
import { useFormContext, ErrorMessage } from 'react-hook-form';
2+
import { useFormContext } from 'react-hook-form';
33
import { TopicConfig } from 'generated-sources';
4+
import { ErrorMessage } from '@hookform/error-message';
45
import CUSTOM_PARAMS_OPTIONS from './customParamsOptions';
56

67
interface Props {
@@ -25,8 +26,7 @@ const CustomParamValue: React.FC<Props> = ({
2526
if (selectedParamName && !defaultValue) {
2627
setValue(
2728
valInputName,
28-
CUSTOM_PARAMS_OPTIONS[selectedParamName].defaultValue,
29-
true
29+
CUSTOM_PARAMS_OPTIONS[selectedParamName].defaultValue
3030
);
3131
}
3232
}, [selectedParamName, setValue, valInputName]);

kafka-ui-react-app/src/components/Topics/shared/Form/TimeToRetain.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react';
22
import prettyMilliseconds from 'pretty-ms';
3-
import { useFormContext, ErrorMessage } from 'react-hook-form';
3+
import { useFormContext } from 'react-hook-form';
4+
import { ErrorMessage } from '@hookform/error-message';
5+
46
import { MILLISECONDS_IN_WEEK, MILLISECONDS_IN_SECOND } from 'lib/constants';
57
import TimeToRetainBtns from './TimeToRetainBtns';
68

kafka-ui-react-app/src/components/Topics/shared/Form/TopicForm.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react';
2-
import { useFormContext, ErrorMessage } from 'react-hook-form';
2+
import { useFormContext } from 'react-hook-form';
33
import { TOPIC_NAME_VALIDATION_PATTERN, BYTES_IN_GB } from 'lib/constants';
44
import { CleanupPolicy, TopicName, TopicConfigByName } from 'redux/interfaces';
5+
import { ErrorMessage } from '@hookform/error-message';
56
import CustomParamsContainer from './CustomParams/CustomParamsContainer';
67
import TimeToRetain from './TimeToRetain';
78

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as actions from '../actions';
2+
3+
describe('Actions', () => {
4+
describe('fetchClusterStatsAction', () => {
5+
it('creates an REQUEST action', () => {
6+
expect(actions.fetchClusterStatsAction.request()).toEqual({
7+
type: 'GET_CLUSTER_STATUS__REQUEST',
8+
});
9+
});
10+
11+
it('creates an SUCCESS action', () => {
12+
expect(
13+
actions.fetchClusterStatsAction.success({ brokerCount: 1 })
14+
).toEqual({
15+
type: 'GET_CLUSTER_STATUS__SUCCESS',
16+
payload: {
17+
brokerCount: 1,
18+
},
19+
});
20+
});
21+
22+
it('creates an FAILURE action', () => {
23+
expect(actions.fetchClusterStatsAction.failure()).toEqual({
24+
type: 'GET_CLUSTER_STATUS__FAILURE',
25+
});
26+
});
27+
});
28+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ClusterStats } from 'generated-sources';
2+
3+
export const clusterStats: ClusterStats = {
4+
brokerCount: 1,
5+
zooKeeperStatus: 1,
6+
activeControllers: 1,
7+
onlinePartitionCount: 6,
8+
offlinePartitionCount: 0,
9+
inSyncReplicasCount: 6,
10+
outOfSyncReplicasCount: 0,
11+
underReplicatedPartitionCount: 0,
12+
diskUsage: [{ brokerId: 1, segmentSize: 6538, segmentCount: 6 }],
13+
};

0 commit comments

Comments
 (0)