fixing create topic (#2275)
This commit is contained in:
parent
620d2955fb
commit
002e4db355
13 changed files with 63 additions and 51 deletions
|
@ -80,7 +80,7 @@ describe('New', () => {
|
||||||
|
|
||||||
it('validates form', async () => {
|
it('validates form', async () => {
|
||||||
await act(() => renderComponent(clusterTopicNewPath(clusterName)));
|
await act(() => renderComponent(clusterTopicNewPath(clusterName)));
|
||||||
userEvent.click(screen.getByText(/submit/i));
|
userEvent.click(screen.getByText('Create topic'));
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(screen.getByText('name is a required field')).toBeInTheDocument();
|
expect(screen.getByText('name is a required field')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
@ -97,7 +97,7 @@ describe('New', () => {
|
||||||
await act(() => renderComponent(clusterTopicNewPath(clusterName)));
|
await act(() => renderComponent(clusterTopicNewPath(clusterName)));
|
||||||
|
|
||||||
userEvent.type(screen.getByPlaceholderText('Topic Name'), topicName);
|
userEvent.type(screen.getByPlaceholderText('Topic Name'), topicName);
|
||||||
userEvent.click(screen.getByText(/submit/i));
|
userEvent.click(screen.getByText('Create topic'));
|
||||||
|
|
||||||
await waitFor(() => expect(mockNavigate).toBeCalledTimes(1));
|
await waitFor(() => expect(mockNavigate).toBeCalledTimes(1));
|
||||||
expect(mockNavigate).toHaveBeenLastCalledWith(`../${topicName}`);
|
expect(mockNavigate).toHaveBeenLastCalledWith(`../${topicName}`);
|
||||||
|
@ -115,7 +115,7 @@ describe('New', () => {
|
||||||
await act(() =>
|
await act(() =>
|
||||||
userEvent.type(screen.getByPlaceholderText('Topic Name'), topicName)
|
userEvent.type(screen.getByPlaceholderText('Topic Name'), topicName)
|
||||||
);
|
);
|
||||||
await act(() => userEvent.click(screen.getByText(/submit/i)));
|
await act(() => userEvent.click(screen.getByText('Create topic')));
|
||||||
expect(mockNavigate).not.toHaveBeenCalled();
|
expect(mockNavigate).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ describe('New', () => {
|
||||||
await act(() => renderComponent(clusterTopicNewPath(clusterName)));
|
await act(() => renderComponent(clusterTopicNewPath(clusterName)));
|
||||||
await act(() => {
|
await act(() => {
|
||||||
userEvent.type(screen.getByPlaceholderText('Topic Name'), topicName);
|
userEvent.type(screen.getByPlaceholderText('Topic Name'), topicName);
|
||||||
userEvent.click(screen.getByText(/submit/i));
|
userEvent.click(screen.getByText('Create topic'));
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(useDispatchMock).toHaveBeenCalledTimes(1);
|
expect(useDispatchMock).toHaveBeenCalledTimes(1);
|
||||||
|
|
|
@ -116,7 +116,7 @@ describe('Edit Component', () => {
|
||||||
|
|
||||||
renderComponent({ updateTopic: updateTopicMock }, undefined);
|
renderComponent({ updateTopic: updateTopicMock }, undefined);
|
||||||
|
|
||||||
const btn = screen.getAllByText(/submit/i)[0];
|
const btn = screen.getAllByText(/Save/i)[0];
|
||||||
expect(btn).toBeEnabled();
|
expect(btn).toBeEnabled();
|
||||||
|
|
||||||
await act(() => {
|
await act(() => {
|
||||||
|
@ -138,7 +138,7 @@ describe('Edit Component', () => {
|
||||||
undefined
|
undefined
|
||||||
);
|
);
|
||||||
|
|
||||||
const btn = screen.getAllByText(/submit/i)[0];
|
const btn = screen.getAllByText(/Save/i)[0];
|
||||||
|
|
||||||
await act(() => {
|
await act(() => {
|
||||||
userEvent.type(
|
userEvent.type(
|
||||||
|
|
|
@ -18,23 +18,27 @@ const TimeToRetainBtnsWrapper = styled.div`
|
||||||
const TimeToRetainBtns: React.FC<Props> = ({ name }) => (
|
const TimeToRetainBtns: React.FC<Props> = ({ name }) => (
|
||||||
<TimeToRetainBtnsWrapper>
|
<TimeToRetainBtnsWrapper>
|
||||||
<TimeToRetainBtn
|
<TimeToRetainBtn
|
||||||
text="12h"
|
text="12 hours"
|
||||||
inputName={name}
|
inputName={name}
|
||||||
value={MILLISECONDS_IN_DAY / 2}
|
value={MILLISECONDS_IN_DAY / 2}
|
||||||
/>
|
/>
|
||||||
<TimeToRetainBtn text="1d" inputName={name} value={MILLISECONDS_IN_DAY} />
|
|
||||||
<TimeToRetainBtn
|
<TimeToRetainBtn
|
||||||
text="2d"
|
text="1 day"
|
||||||
|
inputName={name}
|
||||||
|
value={MILLISECONDS_IN_DAY}
|
||||||
|
/>
|
||||||
|
<TimeToRetainBtn
|
||||||
|
text="2 days"
|
||||||
inputName={name}
|
inputName={name}
|
||||||
value={MILLISECONDS_IN_DAY * 2}
|
value={MILLISECONDS_IN_DAY * 2}
|
||||||
/>
|
/>
|
||||||
<TimeToRetainBtn
|
<TimeToRetainBtn
|
||||||
text="7d"
|
text="7 days"
|
||||||
inputName={name}
|
inputName={name}
|
||||||
value={MILLISECONDS_IN_DAY * 7}
|
value={MILLISECONDS_IN_DAY * 7}
|
||||||
/>
|
/>
|
||||||
<TimeToRetainBtn
|
<TimeToRetainBtn
|
||||||
text="4w"
|
text="4 weeks"
|
||||||
inputName={name}
|
inputName={name}
|
||||||
value={MILLISECONDS_IN_DAY * 7 * 4}
|
value={MILLISECONDS_IN_DAY * 7 * 4}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -29,15 +29,23 @@ export const Label = styled.div`
|
||||||
export const Button = styled.button<{ isActive: boolean }>`
|
export const Button = styled.button<{ isActive: boolean }>`
|
||||||
background-color: ${({ theme, ...props }) =>
|
background-color: ${({ theme, ...props }) =>
|
||||||
props.isActive
|
props.isActive
|
||||||
? theme.button.primary.backgroundColor.active
|
? theme.button.secondary.invertedColors.normal
|
||||||
: theme.button.primary.backgroundColor.normal};
|
: theme.button.secondary.backgroundColor.normal};
|
||||||
height: 32px;
|
color: ${({ theme, ...props }) =>
|
||||||
width: 46px;
|
props.isActive
|
||||||
border: 1px solid
|
? theme.button.secondary.isActiveColor
|
||||||
${({ theme, ...props }) =>
|
: theme.button.primary.color};
|
||||||
props.isActive ? theme.button.border.active : theme.button.primary.color};
|
height: 24px;
|
||||||
|
padding: 0 5px;
|
||||||
|
min-width: 51px;
|
||||||
|
border: none;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
&:hover {
|
&:hover {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
export const ButtonWrapper = styled.div`
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
`;
|
||||||
|
|
|
@ -208,10 +208,14 @@ const TopicForm: React.FC<Props> = ({
|
||||||
|
|
||||||
<S.CustomParamsHeading>Custom parameters</S.CustomParamsHeading>
|
<S.CustomParamsHeading>Custom parameters</S.CustomParamsHeading>
|
||||||
<CustomParams isSubmitting={isSubmitting} />
|
<CustomParams isSubmitting={isSubmitting} />
|
||||||
|
<S.ButtonWrapper>
|
||||||
<Button type="submit" buttonType="primary" buttonSize="L">
|
<Button type="submit" buttonType="primary" buttonSize="L">
|
||||||
Submit
|
{isEditing ? 'Save' : 'Create topic'}
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button type="button" buttonType="primary" buttonSize="L">
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
</S.ButtonWrapper>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</StyledForm>
|
</StyledForm>
|
||||||
);
|
);
|
||||||
|
|
|
@ -42,21 +42,17 @@ describe('TimeToRetainBtn', () => {
|
||||||
it('should test the non active state of the button and its styling', () => {
|
it('should test the non active state of the button and its styling', () => {
|
||||||
const buttonElement = screen.getByRole('button');
|
const buttonElement = screen.getByRole('button');
|
||||||
expect(buttonElement).toHaveStyle(
|
expect(buttonElement).toHaveStyle(
|
||||||
`background-color:${theme.button.primary.backgroundColor.normal}`
|
`background-color:${theme.button.secondary.backgroundColor.normal}`
|
||||||
);
|
|
||||||
expect(buttonElement).toHaveStyle(
|
|
||||||
`border:1px solid ${theme.button.primary.color}`
|
|
||||||
);
|
);
|
||||||
|
expect(buttonElement).toHaveStyle(`border:none`);
|
||||||
});
|
});
|
||||||
it('should test the non active state with click becoming active', () => {
|
it('should test the non active state with click becoming active', () => {
|
||||||
const buttonElement = screen.getByRole('button');
|
const buttonElement = screen.getByRole('button');
|
||||||
userEvent.click(buttonElement);
|
userEvent.click(buttonElement);
|
||||||
expect(buttonElement).toHaveStyle(
|
expect(buttonElement).toHaveStyle(
|
||||||
`background-color:${theme.button.primary.backgroundColor.active}`
|
`background-color:${theme.button.secondary.invertedColors.normal}`
|
||||||
);
|
|
||||||
expect(buttonElement).toHaveStyle(
|
|
||||||
`border:1px solid ${theme.button.border.active}`
|
|
||||||
);
|
);
|
||||||
|
expect(buttonElement).toHaveStyle(`border:none`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -65,11 +61,9 @@ describe('TimeToRetainBtn', () => {
|
||||||
SetUpComponent({ value: 604800000 });
|
SetUpComponent({ value: 604800000 });
|
||||||
const buttonElement = screen.getByRole('button');
|
const buttonElement = screen.getByRole('button');
|
||||||
expect(buttonElement).toHaveStyle(
|
expect(buttonElement).toHaveStyle(
|
||||||
`background-color:${theme.button.primary.backgroundColor.active}`
|
`background-color:${theme.button.secondary.invertedColors.normal}`
|
||||||
);
|
|
||||||
expect(buttonElement).toHaveStyle(
|
|
||||||
`border:1px solid ${theme.button.border.active}`
|
|
||||||
);
|
);
|
||||||
|
expect(buttonElement).toHaveStyle(`border:none`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -44,10 +44,10 @@ describe('TopicForm', () => {
|
||||||
'spinbutton',
|
'spinbutton',
|
||||||
'Time to retain data (in ms)'
|
'Time to retain data (in ms)'
|
||||||
);
|
);
|
||||||
expectByRoleAndNameToBeInDocument('button', '12h');
|
expectByRoleAndNameToBeInDocument('button', '12 hours');
|
||||||
expectByRoleAndNameToBeInDocument('button', '2d');
|
expectByRoleAndNameToBeInDocument('button', '2 days');
|
||||||
expectByRoleAndNameToBeInDocument('button', '7d');
|
expectByRoleAndNameToBeInDocument('button', '7 days');
|
||||||
expectByRoleAndNameToBeInDocument('button', '4w');
|
expectByRoleAndNameToBeInDocument('button', '4 weeks');
|
||||||
|
|
||||||
expectByRoleAndNameToBeInDocument('listbox', 'Max size on disk in GB');
|
expectByRoleAndNameToBeInDocument('listbox', 'Max size on disk in GB');
|
||||||
expectByRoleAndNameToBeInDocument(
|
expectByRoleAndNameToBeInDocument(
|
||||||
|
@ -57,7 +57,7 @@ describe('TopicForm', () => {
|
||||||
|
|
||||||
expectByRoleAndNameToBeInDocument('heading', 'Custom parameters');
|
expectByRoleAndNameToBeInDocument('heading', 'Custom parameters');
|
||||||
|
|
||||||
expectByRoleAndNameToBeInDocument('button', 'Submit');
|
expectByRoleAndNameToBeInDocument('button', 'Create topic');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('submits', () => {
|
it('submits', () => {
|
||||||
|
@ -66,7 +66,7 @@ describe('TopicForm', () => {
|
||||||
onSubmit: onSubmit.mockImplementation((e) => e.preventDefault()),
|
onSubmit: onSubmit.mockImplementation((e) => e.preventDefault()),
|
||||||
});
|
});
|
||||||
|
|
||||||
userEvent.click(screen.getByRole('button', { name: 'Submit' }));
|
userEvent.click(screen.getByRole('button', { name: 'Create topic' }));
|
||||||
expect(onSubmit).toBeCalledTimes(1);
|
expect(onSubmit).toBeCalledTimes(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,8 +10,8 @@ describe('TopicForm styled components', () => {
|
||||||
render(<S.Button isActive />);
|
render(<S.Button isActive />);
|
||||||
const button = screen.getByRole('button');
|
const button = screen.getByRole('button');
|
||||||
expect(button).toHaveStyle({
|
expect(button).toHaveStyle({
|
||||||
border: `1px solid ${theme.button.border.active}`,
|
border: `none`,
|
||||||
backgroundColor: theme.button.primary.backgroundColor.active,
|
backgroundColor: theme.button.secondary.invertedColors.normal,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ describe('TopicForm styled components', () => {
|
||||||
render(<S.Button isActive={false} />);
|
render(<S.Button isActive={false} />);
|
||||||
const button = screen.getByRole('button');
|
const button = screen.getByRole('button');
|
||||||
expect(button).toHaveStyle({
|
expect(button).toHaveStyle({
|
||||||
border: `1px solid ${theme.button.primary.color}`,
|
border: `none`,
|
||||||
backgroundColor: theme.button.primary.backgroundColor.normal,
|
backgroundColor: theme.button.secondary.backgroundColor.normal,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -29,12 +29,12 @@ describe('Breadcrumb component', () => {
|
||||||
|
|
||||||
it('renders the list of links', async () => {
|
it('renders the list of links', async () => {
|
||||||
const { getByText } = setupComponent(createTopicPath, createTopicRoutePath);
|
const { getByText } = setupComponent(createTopicPath, createTopicRoutePath);
|
||||||
expect(getByText('Topics')).toBeInTheDocument();
|
expect(getByText('All Topics')).toBeInTheDocument();
|
||||||
expect(getByText('Create New')).toBeInTheDocument();
|
expect(getByText('Create New Topic')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
it('renders the topic overview', async () => {
|
it('renders the topic overview', async () => {
|
||||||
const { getByText } = setupComponent(topicPath, topicRoutePath);
|
const { getByText } = setupComponent(topicPath, topicRoutePath);
|
||||||
expect(getByText('Topics')).toBeInTheDocument();
|
expect(getByText('All Topics')).toBeInTheDocument();
|
||||||
expect(getByText(topicName)).toBeInTheDocument();
|
expect(getByText(topicName)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,4 +3,5 @@ import styled from 'styled-components';
|
||||||
export const StyledForm = styled.form`
|
export const StyledForm = styled.form`
|
||||||
padding: 0 16px;
|
padding: 0 16px;
|
||||||
max-width: 800px;
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -120,7 +120,7 @@ describe('Paths', () => {
|
||||||
|
|
||||||
it('clusterTopicsPath', () => {
|
it('clusterTopicsPath', () => {
|
||||||
expect(paths.clusterTopicsPath(clusterName)).toEqual(
|
expect(paths.clusterTopicsPath(clusterName)).toEqual(
|
||||||
`${paths.clusterPath(clusterName)}/topics`
|
`${paths.clusterPath(clusterName)}/all-topics`
|
||||||
);
|
);
|
||||||
expect(paths.clusterTopicsPath()).toEqual(
|
expect(paths.clusterTopicsPath()).toEqual(
|
||||||
paths.clusterTopicsPath(RouteParams.clusterName)
|
paths.clusterTopicsPath(RouteParams.clusterName)
|
||||||
|
@ -128,7 +128,7 @@ describe('Paths', () => {
|
||||||
});
|
});
|
||||||
it('clusterTopicNewPath', () => {
|
it('clusterTopicNewPath', () => {
|
||||||
expect(paths.clusterTopicNewPath(clusterName)).toEqual(
|
expect(paths.clusterTopicNewPath(clusterName)).toEqual(
|
||||||
`${paths.clusterTopicsPath(clusterName)}/create-new`
|
`${paths.clusterTopicsPath(clusterName)}/create-new-topic`
|
||||||
);
|
);
|
||||||
expect(paths.clusterTopicNewPath()).toEqual(
|
expect(paths.clusterTopicNewPath()).toEqual(
|
||||||
paths.clusterTopicNewPath(RouteParams.clusterName)
|
paths.clusterTopicNewPath(RouteParams.clusterName)
|
||||||
|
|
|
@ -111,8 +111,8 @@ export type ClusterSubjectParam = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Topics
|
// Topics
|
||||||
export const clusterTopicsRelativePath = 'topics';
|
export const clusterTopicsRelativePath = 'all-topics';
|
||||||
export const clusterTopicNewRelativePath = 'create-new';
|
export const clusterTopicNewRelativePath = 'create-new-topic';
|
||||||
export const clusterTopicCopyRelativePath = 'copy';
|
export const clusterTopicCopyRelativePath = 'copy';
|
||||||
export const clusterTopicsPath = (
|
export const clusterTopicsPath = (
|
||||||
clusterName: ClusterName = RouteParams.clusterName
|
clusterName: ClusterName = RouteParams.clusterName
|
||||||
|
|
|
@ -181,6 +181,7 @@ const theme = {
|
||||||
active: Colors.neutral[15],
|
active: Colors.neutral[15],
|
||||||
},
|
},
|
||||||
color: Colors.neutral[90],
|
color: Colors.neutral[90],
|
||||||
|
isActiveColor: Colors.neutral[0],
|
||||||
invertedColors: {
|
invertedColors: {
|
||||||
normal: Colors.neutral[50],
|
normal: Colors.neutral[50],
|
||||||
hover: Colors.neutral[70],
|
hover: Colors.neutral[70],
|
||||||
|
|
Loading…
Add table
Reference in a new issue