Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix test of launchform #581

Merged
merged 4 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const baseInputProps: InputProps = {
onChange: () => {},
required: false,
typeDefinition: inputTypes.unknown,
setIsError: () => {},
};

function makeSimpleInput(typeDefinition: InputTypeDefinition, value: any): InputProps {
Expand Down Expand Up @@ -98,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 @@ -110,7 +111,9 @@ describe('literalToInputValue', () => {
type: InputType.None,
};

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

Expand All @@ -135,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 @@ -150,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