Make Submit button inactive when required fields aren't filled (#2315)
* fixing create schema page validation issue * fixing schema create form schemaType select issue * adding test cases for schema creation
This commit is contained in:
parent
bffe316063
commit
d92fe63e8a
2 changed files with 27 additions and 2 deletions
|
@ -105,11 +105,11 @@ const New: React.FC = () => {
|
||||||
control={control}
|
control={control}
|
||||||
rules={{ required: 'Schema Type is required.' }}
|
rules={{ required: 'Schema Type is required.' }}
|
||||||
name="schemaType"
|
name="schemaType"
|
||||||
|
defaultValue={SchemaTypeOptions[0].value as SchemaType}
|
||||||
render={({ field: { name, onChange, value } }) => (
|
render={({ field: { name, onChange, value } }) => (
|
||||||
<Select
|
<Select
|
||||||
selectSize="M"
|
selectSize="M"
|
||||||
name={name}
|
name={name}
|
||||||
defaultValue={SchemaTypeOptions[0].value}
|
|
||||||
value={value}
|
value={value}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
minWidth="50%"
|
minWidth="50%"
|
||||||
|
|
|
@ -2,9 +2,12 @@ import React from 'react';
|
||||||
import New from 'components/Schemas/New/New';
|
import New from 'components/Schemas/New/New';
|
||||||
import { render, WithRoute } from 'lib/testHelpers';
|
import { render, WithRoute } from 'lib/testHelpers';
|
||||||
import { clusterSchemaNewPath } from 'lib/paths';
|
import { clusterSchemaNewPath } from 'lib/paths';
|
||||||
import { screen } from '@testing-library/dom';
|
import { act, screen } from '@testing-library/react';
|
||||||
|
import userEvent from '@testing-library/user-event';
|
||||||
|
|
||||||
const clusterName = 'local';
|
const clusterName = 'local';
|
||||||
|
const subjectValue = 'subject';
|
||||||
|
const schemaValue = 'schema';
|
||||||
|
|
||||||
describe('New Component', () => {
|
describe('New Component', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -21,4 +24,26 @@ describe('New Component', () => {
|
||||||
it('renders component', () => {
|
it('renders component', () => {
|
||||||
expect(screen.getByText('Create new schema')).toBeInTheDocument();
|
expect(screen.getByText('Create new schema')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
it('submit button will be disabled while form fields are not filled', () => {
|
||||||
|
const submitBtn = screen.getByRole('button', { name: /submit/i });
|
||||||
|
expect(submitBtn).toBeDisabled();
|
||||||
|
});
|
||||||
|
it('submit button will be enabled when form fields are filled', async () => {
|
||||||
|
const subject = screen.getByPlaceholderText('Schema Name');
|
||||||
|
const schema = screen.getAllByRole('textbox')[1];
|
||||||
|
const schemaTypeSelect = screen.getByRole('listbox');
|
||||||
|
|
||||||
|
await act(() => {
|
||||||
|
userEvent.type(subject, subjectValue);
|
||||||
|
});
|
||||||
|
await act(() => {
|
||||||
|
userEvent.type(schema, schemaValue);
|
||||||
|
});
|
||||||
|
await act(() => {
|
||||||
|
userEvent.selectOptions(schemaTypeSelect, ['AVRO']);
|
||||||
|
});
|
||||||
|
|
||||||
|
const submitBtn = screen.getByRole('button', { name: /Submit/i });
|
||||||
|
expect(submitBtn).toBeEnabled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue