Skip to content

Commit

Permalink
fix: fix test of launchform (#581)
Browse files Browse the repository at this point in the history
* fix: fix test of launchform

Signed-off-by: James <[email protected]>

* fix: inputHelpers tests regression

Signed-off-by: Olga Nad <[email protected]>

* fix: update tests description

Signed-off-by: Olga Nad <[email protected]>

* fix: spelling typo

Signed-off-by: Olga Nad <[email protected]>

Signed-off-by: James <[email protected]>
Signed-off-by: Olga Nad <[email protected]>
Co-authored-by: Olga Nad <[email protected]>
  • Loading branch information
james-union and olga-union authored Sep 7, 2022
1 parent f027c43 commit afd85bf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() },
Expand All @@ -111,7 +111,9 @@ describe('literalToInputValue', () => {
type: InputType.None,
};

expect(literalToInputValue(mapInputTypeDefinition(typeDefinition), map)).toEqual('{}');
expect(literalToInputValue(mapInputTypeDefinition(typeDefinition), map)).toEqual(`{
"a": {}
}`);
});
});

Expand All @@ -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
Expand All @@ -151,7 +153,7 @@ describe('literalToInputValue', () => {

expect(
literalToInputValue(collectionInputTypeDefinition(typeDefinition), collection),
).toEqual('[]');
).toEqual('[{},{}]');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {});

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 () => {
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 () => {
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 afd85bf

Please sign in to comment.