Skip to content

Commit

Permalink
test: RunActionDropdown.test
Browse files Browse the repository at this point in the history
  • Loading branch information
keita-determined committed Jul 8, 2024
1 parent d923e06 commit 09718b0
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions webui/react/src/components/RunActionDropdown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ConfirmationProvider } from 'hew/useConfirm';

import { handlePath } from 'routes/utils';
import { archiveRuns, deleteRuns, killRuns, unarchiveRuns } from 'services/api';
import { RunState } from 'types';
import { FlatRunExperiment, RunState } from 'types';

import RunActionDropdown, { Action } from './RunActionDropdown';
import { cell, run } from './RunActionDropdown.test.mock';
Expand Down Expand Up @@ -54,7 +54,12 @@ vi.mock('hooks/usePermissions', () => {
};
});

const setup = (link?: string, state?: RunState, archived?: boolean) => {
const setup = (
link?: string,
state?: RunState,
archived?: boolean,
experiment?: FlatRunExperiment,
) => {
const onComplete = vi.fn();
const onVisibleChange = vi.fn();
render(
Expand All @@ -68,6 +73,7 @@ const setup = (link?: string, state?: RunState, archived?: boolean) => {
run={{
...run,
archived: archived === undefined ? run.archived : archived,
experiment: experiment === undefined ? run.experiment : experiment,
state: state === undefined ? run.state : state,
}}
onComplete={onComplete}
Expand Down Expand Up @@ -176,4 +182,28 @@ describe('RunActionDropdown', () => {
setup();
expect(screen.queryByText(Action.Move)).not.toBeInTheDocument();
});

it('should provide Pause option', () => {
mocks.canModifyFlatRun.mockImplementation(() => true);
const experiment: FlatRunExperiment = {
description: '',
forkedFrom: 6634,
id: 6833,
isMultitrial: false,
name: 'iris_tf_keras_adaptive_search',
progress: 0.9444444,
resourcePool: 'compute-pool',
searcherMetric: 'val_categorical_accuracy',
searcherType: 'single',
unmanaged: false,
};
setup(undefined, RunState.Active, false, experiment);
expect(screen.getByText(Action.Pause)).toBeInTheDocument();
});

it('should hide Pause option without permissions', () => {
mocks.canModifyFlatRun.mockImplementation(() => false);
setup();
expect(screen.queryByText(Action.Pause)).not.toBeInTheDocument();
});
});

0 comments on commit 09718b0

Please sign in to comment.