Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues/1217 #1430

Merged
merged 10 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions kafka-ui-react-app/src/components/Connect/Edit/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const Edit: React.FC<EditProps> = ({
clusterName,
connectName,
connectorName,
JSON.parse(values.config)
JSON.parse(values.config.trim())
);
if (connector) {
history.push(
Expand Down Expand Up @@ -116,7 +116,7 @@ const Edit: React.FC<EditProps> = ({
accidentally breaking your connector config!
</ConnectEditWarningMessageStyled>
)}
<form onSubmit={handleSubmit(onSubmit)}>
<form onSubmit={handleSubmit(onSubmit)} aria-label="Edit connect form">
<div>
<Controller
control={control}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import React from 'react';
import { create } from 'react-test-renderer';
import { mount } from 'enzyme';
import { act } from 'react-dom/test-utils';
import { containerRendersView, TestRouterWrapper } from 'lib/testHelpers';
import { containerRendersView, render } from 'lib/testHelpers';
import {
clusterConnectConnectorConfigPath,
clusterConnectConnectorEditPath,
} from 'lib/paths';
import EditContainer from 'components/Connect/Edit/EditContainer';
import Edit, { EditProps } from 'components/Connect/Edit/Edit';
import { connector } from 'redux/reducers/connect/__test__/fixtures';
import { ThemeProvider } from 'styled-components';
import theme from 'theme/theme';
import { Route } from 'react-router';
import { waitFor } from '@testing-library/dom';
import { fireEvent, screen } from '@testing-library/react';

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

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

const setupWrapper = (props: Partial<EditProps> = {}) => (
<ThemeProvider theme={theme}>
<TestRouterWrapper
pathname={pathname}
urlParams={{ clusterName, connectName, connectorName }}
>
const renderComponent = (props: Partial<EditProps> = {}) =>
render(
<Route path={pathname}>
<Edit
fetchConfig={jest.fn()}
isConfigFetching={false}
config={connector.config}
updateConfig={jest.fn()}
{...props}
/>
</TestRouterWrapper>
</ThemeProvider>
);

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: '******' } })
</Route>,
{
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,
Expand All @@ -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')));
Motherships marked this conversation as resolved.
Show resolved Hide resolved
expect(updateConfig).toHaveBeenCalledTimes(1);
expect(updateConfig).toHaveBeenCalledWith(
clusterName,
Expand All @@ -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(
Expand All @@ -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();
});
});
Expand Down

This file was deleted.

12 changes: 12 additions & 0 deletions kafka-ui-react-app/src/components/Connect/New/New.styled.ts
Original file line number Diff line number Diff line change
@@ -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;
}
`;
Loading