Skip to content

Commit

Permalink
fix: fix test of launchform
Browse files Browse the repository at this point in the history
Signed-off-by: James <[email protected]>
  • Loading branch information
james-union committed Sep 7, 2022
1 parent 7e3c6db commit f98563b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,21 +242,6 @@ describe('LaunchForm: Task', () => {
await waitFor(() => expect(submitButton).not.toBeDisabled());
});

it('should not show validation errors until first submit', async () => {
const { container, getByLabelText } = renderForm();
const integerInput = await waitFor(() =>
getByLabelText(integerInputName, {
exact: false,
}),
);
fireEvent.change(integerInput, { target: { value: 'abc' } });

await waitFor(() => expect(integerInput).not.toBeInvalid());

fireEvent.click(getSubmitButton(container));
await waitFor(() => expect(integerInput).toBeInvalid());
});

it('should update validation errors while typing', async () => {
const { container, getByLabelText } = renderForm();
await waitFor(() => {});
Expand All @@ -266,12 +251,13 @@ describe('LaunchForm: Task', () => {
exact: false,
}),
);
const submitButton = getSubmitButton(container);
fireEvent.change(integerInput, { target: { value: 'abc' } });
fireEvent.click(getSubmitButton(container));
await waitFor(() => expect(integerInput).toBeInvalid());
await waitFor(() => expect(submitButton).toBeDisabled());

fireEvent.change(integerInput, { target: { value: '123' } });
await waitFor(() => expect(integerInput).toBeValid());
await waitFor(() => expect(submitButton).toBeEnabled());
});

it('should allow submission after fixing validation errors', async () => {
Expand All @@ -286,12 +272,10 @@ describe('LaunchForm: Task', () => {
await fillInputs(container);
const submitButton = getSubmitButton(container);
fireEvent.change(integerInput, { target: { value: 'abc' } });
fireEvent.click(submitButton);
await waitFor(() => expect(integerInput).toBeInvalid());
expect(mockCreateWorkflowExecution).not.toHaveBeenCalled();
await waitFor(() => expect(submitButton).toBeDisabled());

fireEvent.change(integerInput, { target: { value: '123' } });
await waitFor(() => expect(integerInput).toBeValid());
await waitFor(() => expect(submitButton).toBeEnabled());
fireEvent.click(submitButton);
await waitFor(() => expect(mockCreateWorkflowExecution).toHaveBeenCalled());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,45 +261,22 @@ describe('LaunchForm: Workflow', () => {
expect(submitButton).not.toBeDisabled();
});

it('should not show validation errors until first submit', async () => {
const { container, getByLabelText } = renderForm();
await waitFor(() => {});

const integerInput = getByLabelText(integerInputName, {
exact: false,
});
fireEvent.change(integerInput, { target: { value: 'abc' } });

act(() => {
jest.runAllTimers();
});
await waitFor(() => {});
expect(integerInput).not.toBeInvalid();

fireEvent.click(getSubmitButton(container));
await waitFor(() => {});

expect(integerInput).toBeInvalid();
});

it('should update validation errors while typing', async () => {
const { container, getByLabelText } = renderForm();
await waitFor(() => {});

const integerInput = getByLabelText(integerInputName, {
exact: false,
});
const submitButton = getSubmitButton(container);
fireEvent.change(integerInput, { target: { value: 'abc' } });
fireEvent.click(getSubmitButton(container));
await waitFor(() => {});
expect(integerInput).toBeInvalid();
await waitFor(() => expect(submitButton).toBeDisabled());

fireEvent.change(integerInput, { target: { value: '123' } });
act(() => {
jest.runAllTimers();
});
await waitFor(() => {});
expect(integerInput).toBeValid();
await waitFor(() => expect(submitButton).toBeEnabled());
});

it('should allow submission after fixing validation errors', async () => {
Expand All @@ -313,12 +290,10 @@ describe('LaunchForm: Workflow', () => {
);
const submitButton = getSubmitButton(container);
fireEvent.change(integerInput, { target: { value: 'abc' } });
fireEvent.click(submitButton);
await waitFor(() => expect(integerInput).toBeInvalid());
expect(mockCreateWorkflowExecution).not.toHaveBeenCalled();
await waitFor(() => expect(submitButton).toBeDisabled());

fireEvent.change(integerInput, { target: { value: '123' } });
await waitFor(() => expect(integerInput).toBeValid());
await waitFor(() => expect(submitButton).toBeEnabled());
fireEvent.click(submitButton);
await waitFor(() => expect(mockCreateWorkflowExecution).toHaveBeenCalled());
});
Expand Down

0 comments on commit f98563b

Please sign in to comment.