From afd85bf37026000fffc8005b9b96bf5a15ad49f7 Mon Sep 17 00:00:00 2001 From: james-union <105876962+james-union@users.noreply.github.com> Date: Wed, 7 Sep 2022 12:17:36 -0400 Subject: [PATCH] fix: fix test of launchform (#581) * fix: fix test of launchform Signed-off-by: James * fix: inputHelpers tests regression Signed-off-by: Olga Nad * fix: update tests description Signed-off-by: Olga Nad * fix: spelling typo Signed-off-by: Olga Nad Signed-off-by: James Signed-off-by: Olga Nad Co-authored-by: Olga Nad --- .../inputHelpers/test/inputHelpers.test.ts | 10 +++-- .../LaunchForm/test/LaunchTaskForm.test.tsx | 28 +++----------- .../test/LaunchWorkflowForm.test.tsx | 37 +++---------------- 3 files changed, 18 insertions(+), 57 deletions(-) diff --git a/packages/zapp/console/src/components/Launch/LaunchForm/inputHelpers/test/inputHelpers.test.ts b/packages/zapp/console/src/components/Launch/LaunchForm/inputHelpers/test/inputHelpers.test.ts index bde0430fc..bd4308cc7 100644 --- a/packages/zapp/console/src/components/Launch/LaunchForm/inputHelpers/test/inputHelpers.test.ts +++ b/packages/zapp/console/src/components/Launch/LaunchForm/inputHelpers/test/inputHelpers.test.ts @@ -99,7 +99,7 @@ describe('literalToInputValue', () => { }); }); - it('should return empty for noneType literals', () => { + it('should return literal as an empty object for noneType literals', () => { const map: Core.ILiteral = { map: { literals: { a: literalNone() }, @@ -111,7 +111,9 @@ describe('literalToInputValue', () => { type: InputType.None, }; - expect(literalToInputValue(mapInputTypeDefinition(typeDefinition), map)).toEqual('{}'); + expect(literalToInputValue(mapInputTypeDefinition(typeDefinition), map)).toEqual(`{ + "a": {} +}`); }); }); @@ -136,7 +138,7 @@ describe('literalToInputValue', () => { }); }); - it('should return empty for noneType literals', () => { + it('should return empty objects for each noneType literals', () => { const collection: Core.ILiteral = { collection: { // Duplicate it to test comma separation @@ -151,7 +153,7 @@ describe('literalToInputValue', () => { expect( literalToInputValue(collectionInputTypeDefinition(typeDefinition), collection), - ).toEqual('[]'); + ).toEqual('[{},{}]'); }); }); 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..a492f6832 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,22 +242,7 @@ 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 () => { + it('should show disabled submit button if the value in input is invalid', 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..7abe6393c 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,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 () => { + it('should show disabled submit button if the value in input is invalid', 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 () => { @@ -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()); });