Skip to content

Commit 2b79fee

Browse files
HurenkaEkaterina PetrovaHaarolean
authored
Space sensitive syntax for Create Connector #1217
* added trim to json config * refactored new tests * refactored edit tests * fix new test act warning * first working tests * fixed textarea props * resolved discussions Co-authored-by: Ekaterina Petrova <[email protected]> Co-authored-by: Roman Zabaluev <[email protected]>
1 parent 8639403 commit 2b79fee

File tree

8 files changed

+89
-656
lines changed

8 files changed

+89
-656
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const Edit: React.FC<EditProps> = ({
8888
clusterName,
8989
connectName,
9090
connectorName,
91-
JSON.parse(values.config)
91+
JSON.parse(values.config.trim())
9292
);
9393
if (connector) {
9494
history.push(
@@ -116,7 +116,7 @@ const Edit: React.FC<EditProps> = ({
116116
accidentally breaking your connector config!
117117
</ConnectEditWarningMessageStyled>
118118
)}
119-
<form onSubmit={handleSubmit(onSubmit)}>
119+
<form onSubmit={handleSubmit(onSubmit)} aria-label="Edit connect form">
120120
<div>
121121
<Controller
122122
control={control}

kafka-ui-react-app/src/components/Connect/Edit/__tests__/Edit.spec.tsx

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import React from 'react';
2-
import { create } from 'react-test-renderer';
3-
import { mount } from 'enzyme';
4-
import { act } from 'react-dom/test-utils';
5-
import { containerRendersView, TestRouterWrapper } from 'lib/testHelpers';
2+
import { containerRendersView, render } from 'lib/testHelpers';
63
import {
74
clusterConnectConnectorConfigPath,
85
clusterConnectConnectorEditPath,
96
} from 'lib/paths';
107
import EditContainer from 'components/Connect/Edit/EditContainer';
118
import Edit, { EditProps } from 'components/Connect/Edit/Edit';
129
import { connector } from 'redux/reducers/connect/__test__/fixtures';
13-
import { ThemeProvider } from 'styled-components';
14-
import theme from 'theme/theme';
10+
import { Route } from 'react-router';
11+
import { waitFor } from '@testing-library/dom';
12+
import { fireEvent, screen } from '@testing-library/react';
1513

1614
jest.mock('components/common/PageLoader/PageLoader', () => 'mock-PageLoader');
1715

@@ -38,43 +36,29 @@ describe('Edit', () => {
3836
const connectName = 'my-connect';
3937
const connectorName = 'my-connector';
4038

41-
const setupWrapper = (props: Partial<EditProps> = {}) => (
42-
<ThemeProvider theme={theme}>
43-
<TestRouterWrapper
44-
pathname={pathname}
45-
urlParams={{ clusterName, connectName, connectorName }}
46-
>
39+
const renderComponent = (props: Partial<EditProps> = {}) =>
40+
render(
41+
<Route path={pathname}>
4742
<Edit
4843
fetchConfig={jest.fn()}
4944
isConfigFetching={false}
5045
config={connector.config}
5146
updateConfig={jest.fn()}
5247
{...props}
5348
/>
54-
</TestRouterWrapper>
55-
</ThemeProvider>
56-
);
57-
58-
it('matches snapshot', () => {
59-
const wrapper = create(setupWrapper());
60-
expect(wrapper.toJSON()).toMatchSnapshot();
61-
});
62-
63-
it('matches snapshot when fetching config', () => {
64-
const wrapper = create(setupWrapper({ isConfigFetching: true }));
65-
expect(wrapper.toJSON()).toMatchSnapshot();
66-
});
67-
68-
it('matches snapshot when config has credentials', () => {
69-
const wrapper = create(
70-
setupWrapper({ config: { ...connector.config, password: '******' } })
49+
</Route>,
50+
{
51+
pathname: clusterConnectConnectorEditPath(
52+
clusterName,
53+
connectName,
54+
connectorName
55+
),
56+
}
7157
);
72-
expect(wrapper.toJSON()).toMatchSnapshot();
73-
});
7458

7559
it('fetches config on mount', () => {
7660
const fetchConfig = jest.fn();
77-
mount(setupWrapper({ fetchConfig }));
61+
renderComponent({ fetchConfig });
7862
expect(fetchConfig).toHaveBeenCalledTimes(1);
7963
expect(fetchConfig).toHaveBeenCalledWith(
8064
clusterName,
@@ -85,10 +69,8 @@ describe('Edit', () => {
8569

8670
it('calls updateConfig on form submit', async () => {
8771
const updateConfig = jest.fn();
88-
const wrapper = mount(setupWrapper({ updateConfig }));
89-
await act(async () => {
90-
wrapper.find('form').simulate('submit');
91-
});
72+
renderComponent({ updateConfig });
73+
await waitFor(() => fireEvent.submit(screen.getByRole('form')));
9274
expect(updateConfig).toHaveBeenCalledTimes(1);
9375
expect(updateConfig).toHaveBeenCalledWith(
9476
clusterName,
@@ -100,10 +82,8 @@ describe('Edit', () => {
10082

10183
it('redirects to connector config view on successful submit', async () => {
10284
const updateConfig = jest.fn().mockResolvedValueOnce(connector);
103-
const wrapper = mount(setupWrapper({ updateConfig }));
104-
await act(async () => {
105-
wrapper.find('form').simulate('submit');
106-
});
85+
renderComponent({ updateConfig });
86+
await waitFor(() => fireEvent.submit(screen.getByRole('form')));
10787
expect(mockHistoryPush).toHaveBeenCalledTimes(1);
10888
expect(mockHistoryPush).toHaveBeenCalledWith(
10989
clusterConnectConnectorConfigPath(
@@ -116,10 +96,8 @@ describe('Edit', () => {
11696

11797
it('does not redirect to connector config view on unsuccessful submit', async () => {
11898
const updateConfig = jest.fn().mockResolvedValueOnce(undefined);
119-
const wrapper = mount(setupWrapper({ updateConfig }));
120-
await act(async () => {
121-
wrapper.find('form').simulate('submit');
122-
});
99+
renderComponent({ updateConfig });
100+
await waitFor(() => fireEvent.submit(screen.getByRole('form')));
123101
expect(mockHistoryPush).not.toHaveBeenCalled();
124102
});
125103
});

kafka-ui-react-app/src/components/Connect/Edit/__tests__/__snapshots__/Edit.spec.tsx.snap

Lines changed: 0 additions & 209 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import styled from 'styled-components';
2+
3+
export const NewConnectFormStyled = styled.form`
4+
padding: 0 16px 16px;
5+
display: flex;
6+
flex-direction: column;
7+
gap: 16px;
8+
9+
& > button:last-child {
10+
align-self: flex-start;
11+
}
12+
`;

0 commit comments

Comments
 (0)