Skip to content

Commit

Permalink
Added extra tests verifying interruptible override
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Müller <[email protected]>
  • Loading branch information
Nick Müller committed May 3, 2022
1 parent eb46ae7 commit 12b8bff
Show file tree
Hide file tree
Showing 4 changed files with 291 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ describe('ExecutionMetadata', () => {
it('shows true if execution was marked as interruptible', () => {
execution.spec.interruptible = Protobuf.BoolValue.create({ value: true });
const { getByTestId } = renderMetadata();

expect(execution.spec.metadata.systemMetadata?.executionCluster).toBeDefined();
expect(getByTestId(interruptibleTestId)).toHaveTextContent('true');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from 'components/Launch/LaunchForm/utils';
import { mockSimpleVariables } from 'components/Launch/LaunchForm/__mocks__/mockInputs';
import { primitiveLiteral } from 'components/Launch/LaunchForm/__mocks__/utils';
import { Admin } from 'flyteidl';
import { Admin, Protobuf } from 'flyteidl';
import { LiteralMap, ResourceType, Variable } from 'models/Common/types';
import { getExecutionData } from 'models/Execution/api';
import { Execution, ExecutionData } from 'models/Execution/types';
Expand Down Expand Up @@ -155,6 +155,39 @@ describe('RelaunchExecutionForm', () => {
}),
});
});

it('should not set interruptible value if not provided', async () => {
delete execution.spec.interruptible;
const { getByText } = renderForm();
await waitFor(() => expect(getByText(mockContentString)));
checkLaunchFormProps({
initialParameters: expect.objectContaining({
interruptible: undefined,
}),
});
});

it('should have correct interruptible value if override is enabled', async () => {
execution.spec.interruptible = Protobuf.BoolValue.create({ value: true });
const { getByText } = renderForm();
await waitFor(() => expect(getByText(mockContentString)));
checkLaunchFormProps({
initialParameters: expect.objectContaining({
interruptible: Protobuf.BoolValue.create({ value: true }),
}),
});
});

it('should have correct interruptible value if override is disabled', async () => {
execution.spec.interruptible = Protobuf.BoolValue.create({ value: false });
const { getByText } = renderForm();
await waitFor(() => expect(getByText(mockContentString)));
checkLaunchFormProps({
initialParameters: expect.objectContaining({
interruptible: Protobuf.BoolValue.create({ value: false }),
}),
});
});
});

describe('Launch form with full inputs', () => {
Expand Down Expand Up @@ -256,5 +289,38 @@ describe('RelaunchExecutionForm', () => {
}),
});
});

it('should not set interruptible value if not provided', async () => {
delete execution.spec.interruptible;
const { getByText } = renderForm();
await waitFor(() => expect(getByText(mockContentString)));
checkLaunchFormProps({
initialParameters: expect.objectContaining({
interruptible: undefined,
}),
});
});

it('should have correct interruptible value if override is enabled', async () => {
execution.spec.interruptible = Protobuf.BoolValue.create({ value: true });
const { getByText } = renderForm();
await waitFor(() => expect(getByText(mockContentString)));
checkLaunchFormProps({
initialParameters: expect.objectContaining({
interruptible: Protobuf.BoolValue.create({ value: true }),
}),
});
});

it('should have correct interruptible value if override is disabled', async () => {
execution.spec.interruptible = Protobuf.BoolValue.create({ value: false });
const { getByText } = renderForm();
await waitFor(() => expect(getByText(mockContentString)));
checkLaunchFormProps({
initialParameters: expect.objectContaining({
interruptible: Protobuf.BoolValue.create({ value: false }),
}),
});
});
});
});
107 changes: 107 additions & 0 deletions src/components/Launch/LaunchForm/test/LaunchTaskForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,113 @@ describe('LaunchForm: Task', () => {
expect(inputElement).toBeInTheDocument();
expect(inputElement).toBeChecked();
});

it('should cycle between states correctly', async () => {
const { getByLabelText } = renderForm();

let inputElement = await waitFor(() =>
getByLabelText(`${formStrings.interruptible} (no override)`, { exact: true }),
);
expect(inputElement).toBeInTheDocument();
expect(inputElement).not.toBeChecked();
expect(inputElement).toHaveAttribute('data-indeterminate', 'true');

fireEvent.click(inputElement);
inputElement = await waitFor(() =>
getByLabelText(`${formStrings.interruptible} (enabled)`, { exact: true }),
);
expect(inputElement).toBeInTheDocument();
expect(inputElement).toBeChecked();
expect(inputElement).toHaveAttribute('data-indeterminate', 'false');

fireEvent.click(inputElement);
inputElement = await waitFor(() =>
getByLabelText(`${formStrings.interruptible} (disabled)`, { exact: true }),
);
expect(inputElement).toBeInTheDocument();
expect(inputElement).not.toBeChecked();
expect(inputElement).toHaveAttribute('data-indeterminate', 'false');

fireEvent.click(inputElement);
inputElement = await waitFor(() =>
getByLabelText(`${formStrings.interruptible} (no override)`, { exact: true }),
);
expect(inputElement).toBeInTheDocument();
expect(inputElement).not.toBeChecked();
expect(inputElement).toHaveAttribute('data-indeterminate', 'true');
});

it('should submit without interruptible override set', async () => {
const { container, getByLabelText } = renderForm();

const inputElement = await waitFor(() =>
getByLabelText(formStrings.interruptible, { exact: false }),
);
expect(inputElement).toBeInTheDocument();
expect(inputElement).not.toBeChecked();
expect(inputElement).toHaveAttribute('data-indeterminate', 'true');

await fillInputs(container);
fireEvent.click(getSubmitButton(container));

await waitFor(() =>
expect(mockCreateWorkflowExecution).toHaveBeenCalledWith(
expect.objectContaining({
interruptible: null,
}),
),
);
});

it('should submit with interruptible override enabled', async () => {
const initialParameters: TaskInitialLaunchParameters = {
interruptible: Protobuf.BoolValue.create({ value: true }),
};
const { container, getByLabelText } = renderForm({ initialParameters });

const inputElement = await waitFor(() =>
getByLabelText(formStrings.interruptible, { exact: false }),
);
expect(inputElement).toBeInTheDocument();
expect(inputElement).toBeChecked();
expect(inputElement).toHaveAttribute('data-indeterminate', 'false');

await fillInputs(container);
fireEvent.click(getSubmitButton(container));

await waitFor(() =>
expect(mockCreateWorkflowExecution).toHaveBeenCalledWith(
expect.objectContaining({
interruptible: Protobuf.BoolValue.create({ value: true }),
}),
),
);
});

it('should submit with interruptible override disabled', async () => {
const initialParameters: TaskInitialLaunchParameters = {
interruptible: Protobuf.BoolValue.create({ value: false }),
};
const { container, getByLabelText } = renderForm({ initialParameters });

const inputElement = await waitFor(() =>
getByLabelText(formStrings.interruptible, { exact: false }),
);
expect(inputElement).toBeInTheDocument();
expect(inputElement).not.toBeChecked();
expect(inputElement).toHaveAttribute('data-indeterminate', 'false');

await fillInputs(container);
fireEvent.click(getSubmitButton(container));

await waitFor(() =>
expect(mockCreateWorkflowExecution).toHaveBeenCalledWith(
expect.objectContaining({
interruptible: Protobuf.BoolValue.create({ value: false }),
}),
),
);
});
});
});
});
117 changes: 117 additions & 0 deletions src/components/Launch/LaunchForm/test/LaunchWorkflowForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,123 @@ describe('LaunchForm: Workflow', () => {
expect(inputElement).toBeInTheDocument();
expect(inputElement).toBeChecked();
});

it('should cycle between states correctly when clicked', async () => {
const { getByLabelText } = renderForm();

let inputElement = await waitFor(() =>
getByLabelText(`${formStrings.interruptible} (no override)`, { exact: true }),
);
expect(inputElement).toBeInTheDocument();
expect(inputElement).not.toBeChecked();
expect(inputElement).toHaveAttribute('data-indeterminate', 'true');

fireEvent.click(inputElement);
inputElement = await waitFor(() =>
getByLabelText(`${formStrings.interruptible} (enabled)`, { exact: true }),
);
expect(inputElement).toBeInTheDocument();
expect(inputElement).toBeChecked();
expect(inputElement).toHaveAttribute('data-indeterminate', 'false');

fireEvent.click(inputElement);
inputElement = await waitFor(() =>
getByLabelText(`${formStrings.interruptible} (disabled)`, { exact: true }),
);
expect(inputElement).toBeInTheDocument();
expect(inputElement).not.toBeChecked();
expect(inputElement).toHaveAttribute('data-indeterminate', 'false');

fireEvent.click(inputElement);
inputElement = await waitFor(() =>
getByLabelText(`${formStrings.interruptible} (no override)`, { exact: true }),
);
expect(inputElement).toBeInTheDocument();
expect(inputElement).not.toBeChecked();
expect(inputElement).toHaveAttribute('data-indeterminate', 'true');
});

it('should submit without interruptible override set', async () => {
const { container, getByLabelText } = renderForm();

const inputElement = await waitFor(() =>
getByLabelText(formStrings.interruptible, { exact: false }),
);
expect(inputElement).toBeInTheDocument();
expect(inputElement).not.toBeChecked();
expect(inputElement).toHaveAttribute('data-indeterminate', 'true');

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

await waitFor(() =>
expect(mockCreateWorkflowExecution).toHaveBeenCalledWith(
expect.objectContaining({
interruptible: null,
}),
),
);
});

it('should submit with interruptible override enabled', async () => {
const initialParameters: WorkflowInitialLaunchParameters = {
interruptible: Protobuf.BoolValue.create({ value: true }),
};
const { container, getByLabelText } = renderForm({ initialParameters });

const inputElement = await waitFor(() =>
getByLabelText(formStrings.interruptible, { exact: false }),
);
expect(inputElement).toBeInTheDocument();
expect(inputElement).toBeChecked();
expect(inputElement).toHaveAttribute('data-indeterminate', 'false');

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

await waitFor(() =>
expect(mockCreateWorkflowExecution).toHaveBeenCalledWith(
expect.objectContaining({
interruptible: Protobuf.BoolValue.create({ value: true }),
}),
),
);
});

it('should submit with interruptible override disabled', async () => {
const initialParameters: WorkflowInitialLaunchParameters = {
interruptible: Protobuf.BoolValue.create({ value: false }),
};
const { container, getByLabelText } = renderForm({ initialParameters });

const inputElement = await waitFor(() =>
getByLabelText(formStrings.interruptible, { exact: false }),
);
expect(inputElement).toBeInTheDocument();
expect(inputElement).not.toBeChecked();
expect(inputElement).toHaveAttribute('data-indeterminate', 'false');

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

await waitFor(() =>
expect(mockCreateWorkflowExecution).toHaveBeenCalledWith(
expect.objectContaining({
interruptible: Protobuf.BoolValue.create({ value: false }),
}),
),
);
});
});
});
});

0 comments on commit 12b8bff

Please sign in to comment.