From 69d304100b56ada664f361f23eb67df22688b135 Mon Sep 17 00:00:00 2001 From: Isaac Hellendag Date: Mon, 16 Oct 2023 13:53:02 -0500 Subject: [PATCH] [ui] Refactor RunActionsMenu.test --- .../ui-core/src/runs/RunActionsMenu.tsx | 8 +- .../__fixtures__/RunActionsMenu.fixtures.tsx | 114 ++++++++++++++++++ .../runs/__tests__/RunActionsMenu.test.tsx | 84 ++++++------- 3 files changed, 153 insertions(+), 53 deletions(-) create mode 100644 js_modules/dagster-ui/packages/ui-core/src/runs/__fixtures__/RunActionsMenu.fixtures.tsx diff --git a/js_modules/dagster-ui/packages/ui-core/src/runs/RunActionsMenu.tsx b/js_modules/dagster-ui/packages/ui-core/src/runs/RunActionsMenu.tsx index 287921e0aa94a..6d11a086c2a72 100644 --- a/js_modules/dagster-ui/packages/ui-core/src/runs/RunActionsMenu.tsx +++ b/js_modules/dagster-ui/packages/ui-core/src/runs/RunActionsMenu.tsx @@ -48,11 +48,13 @@ import {RunTableRunFragment} from './types/RunTable.types'; import {useJobAvailabilityErrorForRun} from './useJobAvailabilityErrorForRun'; import {useJobReexecution} from './useJobReExecution'; -export const RunActionsMenu: React.FC<{ +interface Props { run: RunTableRunFragment; additionalActionsForRun?: (run: RunTableRunFragment) => React.ReactNode[]; onAddTag?: (token: RunFilterToken) => void; -}> = React.memo(({run, onAddTag, additionalActionsForRun}) => { +} + +export const RunActionsMenu = React.memo(({run, onAddTag, additionalActionsForRun}: Props) => { const {refetch} = React.useContext(RunsQueryRefetchContext); const [visibleDialog, setVisibleDialog] = React.useState< 'none' | 'terminate' | 'delete' | 'config' | 'tags' @@ -467,7 +469,7 @@ const OPEN_LAUNCHPAD_UNKNOWN = 'Launchpad is unavailable because the pipeline is not present in the current repository.'; // Avoid fetching envYaml and parentPipelineSnapshotId on load in Runs page, they're slow. -const PIPELINE_ENVIRONMENT_QUERY = gql` +export const PIPELINE_ENVIRONMENT_QUERY = gql` query PipelineEnvironmentQuery($runId: ID!) { pipelineRunOrError(runId: $runId) { ... on Run { diff --git a/js_modules/dagster-ui/packages/ui-core/src/runs/__fixtures__/RunActionsMenu.fixtures.tsx b/js_modules/dagster-ui/packages/ui-core/src/runs/__fixtures__/RunActionsMenu.fixtures.tsx new file mode 100644 index 0000000000000..e0c89d4cccf42 --- /dev/null +++ b/js_modules/dagster-ui/packages/ui-core/src/runs/__fixtures__/RunActionsMenu.fixtures.tsx @@ -0,0 +1,114 @@ +import {MockedResponse} from '@apollo/client/testing'; + +import { + RunStatus, + buildPipeline, + buildRepository, + buildRepositoryLocation, + buildRepositoryOrigin, + buildRun, + buildWorkspace, + buildWorkspaceLocationEntry, +} from '../../graphql/types'; +import {ROOT_WORKSPACE_QUERY} from '../../workspace/WorkspaceContext'; +import {RootWorkspaceQuery} from '../../workspace/types/WorkspaceContext.types'; +import {PIPELINE_ENVIRONMENT_QUERY} from '../RunActionsMenu'; +import { + PipelineEnvironmentQuery, + PipelineEnvironmentQueryVariables, +} from '../types/RunActionsMenu.types'; + +const LOCATION_NAME = 'my-origin'; +const REPO_NAME = 'my-repo'; +const JOB_NAME = 'job-bar'; +const RUN_ID = 'run-foo-bar'; +const SNAPSHOT_ID = 'snapshotID'; + +type RunConfigInput = { + hasReExecutePermission: boolean; +}; + +export const buildRunActionsMenuFragment = ({hasReExecutePermission}: RunConfigInput) => { + return buildRun({ + id: RUN_ID, + status: RunStatus.SUCCESS, + stepKeysToExecute: null, + canTerminate: true, + hasDeletePermission: true, + hasReExecutePermission, + hasTerminatePermission: true, + mode: 'default', + rootRunId: 'abcdef12', + parentRunId: null, + pipelineSnapshotId: SNAPSHOT_ID, + pipelineName: JOB_NAME, + repositoryOrigin: buildRepositoryOrigin({ + id: 'repo', + repositoryName: REPO_NAME, + repositoryLocationName: LOCATION_NAME, + }), + solidSelection: null, + assetSelection: null, + assetCheckSelection: null, + tags: [], + startTime: 123, + endTime: 456, + updateTime: 789, + }); +}; + +export const buildMockRootWorkspaceQuery = (): MockedResponse => { + return { + request: { + query: ROOT_WORKSPACE_QUERY, + }, + result: { + data: { + __typename: 'Query', + workspaceOrError: buildWorkspace({ + id: 'workspace', + locationEntries: [ + buildWorkspaceLocationEntry({ + id: LOCATION_NAME, + locationOrLoadError: buildRepositoryLocation({ + id: LOCATION_NAME, + repositories: [ + buildRepository({ + id: REPO_NAME, + name: REPO_NAME, + pipelines: [ + buildPipeline({ + id: JOB_NAME, + name: JOB_NAME, + pipelineSnapshotId: SNAPSHOT_ID, + }), + ], + }), + ], + }), + }), + ], + }), + }, + }, + }; +}; + +export const buildPipelineEnvironmentQuery = ( + runConfig: RunConfigInput, +): MockedResponse => { + return { + request: { + query: PIPELINE_ENVIRONMENT_QUERY, + variables: { + runId: RUN_ID, + }, + }, + result: { + data: { + __typename: 'Query', + pipelineRunOrError: buildRunActionsMenuFragment(runConfig), + }, + }, + }; +}; diff --git a/js_modules/dagster-ui/packages/ui-core/src/runs/__tests__/RunActionsMenu.test.tsx b/js_modules/dagster-ui/packages/ui-core/src/runs/__tests__/RunActionsMenu.test.tsx index fe4b195bd98f7..c20540b544690 100644 --- a/js_modules/dagster-ui/packages/ui-core/src/runs/__tests__/RunActionsMenu.test.tsx +++ b/js_modules/dagster-ui/packages/ui-core/src/runs/__tests__/RunActionsMenu.test.tsx @@ -1,56 +1,34 @@ +import {MockedProvider} from '@apollo/client/testing'; import {render, screen} from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import * as React from 'react'; +import {MemoryRouter} from 'react-router-dom'; -import {RunStatus} from '../../graphql/types'; -import {TestProvider} from '../../testing/TestProvider'; +import {WorkspaceProvider} from '../../workspace/WorkspaceContext'; import {RunActionsMenu} from '../RunActionsMenu'; -import {RunTableRunFragment} from '../types/RunTable.types'; +import { + buildMockRootWorkspaceQuery, + buildPipelineEnvironmentQuery, + buildRunActionsMenuFragment, +} from '../__fixtures__/RunActionsMenu.fixtures'; describe('RunActionsMenu', () => { - const Test: React.FC<{permissionOverrides?: any; run: RunTableRunFragment}> = ({ - permissionOverrides, - run, - }) => { - return ( - - - - ); - }; - - const runFragment: RunTableRunFragment = { - __typename: 'Run', - id: 'run-foo-bar', - status: RunStatus.SUCCESS, - stepKeysToExecute: null, - canTerminate: true, - hasDeletePermission: true, - hasReExecutePermission: true, - hasTerminatePermission: true, - mode: 'default', - rootRunId: 'abcdef12', - parentRunId: null, - pipelineSnapshotId: 'snapshotID', - pipelineName: 'job-bar', - repositoryOrigin: { - __typename: 'RepositoryOrigin', - id: 'repo', - repositoryName: 'my-repo', - repositoryLocationName: 'my-origin', - }, - solidSelection: null, - assetSelection: null, - assetCheckSelection: null, - tags: [], - startTime: 123, - endTime: 456, - updateTime: 789, - }; - describe('Permissions', () => { it('renders menu when open', async () => { - render(); + render( + + + + + + + , + ); const button = await screen.findByRole('button'); expect(button).toBeVisible(); @@ -66,12 +44,18 @@ describe('RunActionsMenu', () => { it('disables re-execution if no permission', async () => { render( - , + + + + + + + , ); const button = await screen.findByRole('button');