diff --git a/kafka-ui-react-app/src/components/Connect/Edit/Edit.tsx b/kafka-ui-react-app/src/components/Connect/Edit/Edit.tsx index 3e8cb1dce97..baf933cfdef 100644 --- a/kafka-ui-react-app/src/components/Connect/Edit/Edit.tsx +++ b/kafka-ui-react-app/src/components/Connect/Edit/Edit.tsx @@ -88,7 +88,7 @@ const Edit: React.FC = ({ clusterName, connectName, connectorName, - JSON.parse(values.config) + JSON.parse(values.config.trim()) ); if (connector) { history.push( @@ -116,7 +116,7 @@ const Edit: React.FC = ({ accidentally breaking your connector config! )} -
+
'mock-PageLoader'); @@ -38,12 +36,9 @@ describe('Edit', () => { const connectName = 'my-connect'; const connectorName = 'my-connector'; - const setupWrapper = (props: Partial = {}) => ( - - + const renderComponent = (props: Partial = {}) => + render( + { updateConfig={jest.fn()} {...props} /> - - - ); - - it('matches snapshot', () => { - const wrapper = create(setupWrapper()); - expect(wrapper.toJSON()).toMatchSnapshot(); - }); - - it('matches snapshot when fetching config', () => { - const wrapper = create(setupWrapper({ isConfigFetching: true })); - expect(wrapper.toJSON()).toMatchSnapshot(); - }); - - it('matches snapshot when config has credentials', () => { - const wrapper = create( - setupWrapper({ config: { ...connector.config, password: '******' } }) + , + { + pathname: clusterConnectConnectorEditPath( + clusterName, + connectName, + connectorName + ), + } ); - expect(wrapper.toJSON()).toMatchSnapshot(); - }); it('fetches config on mount', () => { const fetchConfig = jest.fn(); - mount(setupWrapper({ fetchConfig })); + renderComponent({ fetchConfig }); expect(fetchConfig).toHaveBeenCalledTimes(1); expect(fetchConfig).toHaveBeenCalledWith( clusterName, @@ -85,10 +69,8 @@ describe('Edit', () => { it('calls updateConfig on form submit', async () => { const updateConfig = jest.fn(); - const wrapper = mount(setupWrapper({ updateConfig })); - await act(async () => { - wrapper.find('form').simulate('submit'); - }); + renderComponent({ updateConfig }); + await waitFor(() => fireEvent.submit(screen.getByRole('form'))); expect(updateConfig).toHaveBeenCalledTimes(1); expect(updateConfig).toHaveBeenCalledWith( clusterName, @@ -100,10 +82,8 @@ describe('Edit', () => { it('redirects to connector config view on successful submit', async () => { const updateConfig = jest.fn().mockResolvedValueOnce(connector); - const wrapper = mount(setupWrapper({ updateConfig })); - await act(async () => { - wrapper.find('form').simulate('submit'); - }); + renderComponent({ updateConfig }); + await waitFor(() => fireEvent.submit(screen.getByRole('form'))); expect(mockHistoryPush).toHaveBeenCalledTimes(1); expect(mockHistoryPush).toHaveBeenCalledWith( clusterConnectConnectorConfigPath( @@ -116,10 +96,8 @@ describe('Edit', () => { it('does not redirect to connector config view on unsuccessful submit', async () => { const updateConfig = jest.fn().mockResolvedValueOnce(undefined); - const wrapper = mount(setupWrapper({ updateConfig })); - await act(async () => { - wrapper.find('form').simulate('submit'); - }); + renderComponent({ updateConfig }); + await waitFor(() => fireEvent.submit(screen.getByRole('form'))); expect(mockHistoryPush).not.toHaveBeenCalled(); }); }); diff --git a/kafka-ui-react-app/src/components/Connect/Edit/__tests__/__snapshots__/Edit.spec.tsx.snap b/kafka-ui-react-app/src/components/Connect/Edit/__tests__/__snapshots__/Edit.spec.tsx.snap deleted file mode 100644 index f8dd0c4fb6b..00000000000 --- a/kafka-ui-react-app/src/components/Connect/Edit/__tests__/__snapshots__/Edit.spec.tsx.snap +++ /dev/null @@ -1,209 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Edit view matches snapshot 1`] = ` -.c1 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; - -webkit-flex-direction: row; - -ms-flex-direction: row; - flex-direction: row; - -webkit-align-items: center; - -webkit-box-align: center; - -ms-flex-align: center; - align-items: center; - -webkit-box-pack: center; - -webkit-justify-content: center; - -ms-flex-pack: center; - justify-content: center; - padding: 0px 12px; - border: none; - border-radius: 4px; - white-space: nowrap; - background: #4F4FFF; - color: #FFFFFF; - font-size: 14px; - font-weight: 500; - height: 32px; -} - -.c1:hover:enabled { - background: #1717CF; - color: #FFFFFF; - cursor: pointer; -} - -.c1:active:enabled { - background: #1414B8; - color: #FFFFFF; -} - -.c1:disabled { - opacity: 0.5; - cursor: not-allowed; -} - -.c1 a { - color: white; -} - -.c1 i { - margin-right: 7px; -} - -.c0 { - margin: 16px; -} - -.c0 form > *:last-child { - margin-top: 16px; -} - -
- -
- -
-
- - -
-`; - -exports[`Edit view matches snapshot when config has credentials 1`] = ` -.c2 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; - -webkit-flex-direction: row; - -ms-flex-direction: row; - flex-direction: row; - -webkit-align-items: center; - -webkit-box-align: center; - -ms-flex-align: center; - align-items: center; - -webkit-box-pack: center; - -webkit-justify-content: center; - -ms-flex-pack: center; - justify-content: center; - padding: 0px 12px; - border: none; - border-radius: 4px; - white-space: nowrap; - background: #4F4FFF; - color: #FFFFFF; - font-size: 14px; - font-weight: 500; - height: 32px; -} - -.c2:hover:enabled { - background: #1717CF; - color: #FFFFFF; - cursor: pointer; -} - -.c2:active:enabled { - background: #1414B8; - color: #FFFFFF; -} - -.c2:disabled { - opacity: 0.5; - cursor: not-allowed; -} - -.c2 a { - color: white; -} - -.c2 i { - margin-right: 7px; -} - -.c0 { - margin: 16px; -} - -.c0 form > *:last-child { - margin-top: 16px; -} - -.c1 { - height: 48px; - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; - -webkit-align-items: center; - -webkit-box-align: center; - -ms-flex-align: center; - align-items: center; - background-color: #FFEECC; - border-radius: 8px; - padding: 8px; - margin-bottom: 16px; -} - -
-
- Please replace ****** with the real credential values to avoid accidentally breaking your connector config! -
-
-
- -
-
- - -
-`; - -exports[`Edit view matches snapshot when fetching config 1`] = ``; diff --git a/kafka-ui-react-app/src/components/Connect/New/New.styled.ts b/kafka-ui-react-app/src/components/Connect/New/New.styled.ts new file mode 100644 index 00000000000..c24eff561a3 --- /dev/null +++ b/kafka-ui-react-app/src/components/Connect/New/New.styled.ts @@ -0,0 +1,12 @@ +import styled from 'styled-components'; + +export const NewConnectFormStyled = styled.form` + padding: 0 16px 16px; + display: flex; + flex-direction: column; + gap: 16px; + + & > button:last-child { + align-self: flex-start; + } +`; diff --git a/kafka-ui-react-app/src/components/Connect/New/New.tsx b/kafka-ui-react-app/src/components/Connect/New/New.tsx index 205acb50013..0e25e934cbc 100644 --- a/kafka-ui-react-app/src/components/Connect/New/New.tsx +++ b/kafka-ui-react-app/src/components/Connect/New/New.tsx @@ -14,9 +14,10 @@ import Select from 'components/common/Select/Select'; import { FormError } from 'components/common/Input/Input.styled'; import Input from 'components/common/Input/Input'; import { Button } from 'components/common/Button/Button'; -import styled from 'styled-components'; import PageHeading from 'components/common/PageHeading/PageHeading'; +import * as S from './New.styled'; + const validationSchema = yup.object().shape({ name: yup.string().required(), config: yup.string().required().isJsonObject(), @@ -26,17 +27,6 @@ interface RouterParams { clusterName: ClusterName; } -const NewConnectFormStyled = styled.form` - padding: 16px; - padding-top: 0; - display: flex; - flex-direction: column; - gap: 16px; - & > button:last-child { - align-self: flex-start; - } -`; - export interface NewProps { fetchConnects(clusterName: ClusterName): void; areConnectsFetching: boolean; @@ -99,7 +89,7 @@ const New: React.FC = ({ async (values: FormValues) => { const connector = await createConnector(clusterName, values.connectName, { name: values.name, - config: JSON.parse(values.config), + config: JSON.parse(values.config.trim()), }); if (connector) { history.push( @@ -125,7 +115,10 @@ const New: React.FC = ({ return ( - +
Connect *