From f98563b54713a1e0efe9f0fa0e45192ca862796e Mon Sep 17 00:00:00 2001 From: James Date: Tue, 6 Sep 2022 23:53:46 -0400 Subject: [PATCH] fix: fix test of launchform Signed-off-by: James --- .../LaunchForm/test/LaunchTaskForm.test.tsx | 26 +++----------- .../test/LaunchWorkflowForm.test.tsx | 35 +++---------------- 2 files changed, 10 insertions(+), 51 deletions(-) diff --git a/packages/zapp/console/src/components/Launch/LaunchForm/test/LaunchTaskForm.test.tsx b/packages/zapp/console/src/components/Launch/LaunchForm/test/LaunchTaskForm.test.tsx index 769c85287..90d5522ba 100644 --- a/packages/zapp/console/src/components/Launch/LaunchForm/test/LaunchTaskForm.test.tsx +++ b/packages/zapp/console/src/components/Launch/LaunchForm/test/LaunchTaskForm.test.tsx @@ -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(() => {}); @@ -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 () => { @@ -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()); }); diff --git a/packages/zapp/console/src/components/Launch/LaunchForm/test/LaunchWorkflowForm.test.tsx b/packages/zapp/console/src/components/Launch/LaunchForm/test/LaunchWorkflowForm.test.tsx index 579431f8f..965795965 100644 --- a/packages/zapp/console/src/components/Launch/LaunchForm/test/LaunchWorkflowForm.test.tsx +++ b/packages/zapp/console/src/components/Launch/LaunchForm/test/LaunchWorkflowForm.test.tsx @@ -261,27 +261,6 @@ 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(() => {}); @@ -289,17 +268,15 @@ describe('LaunchForm: Workflow', () => { 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 () => { @@ -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()); });