Skip to content

Commit

Permalink
add jest test for launch all
Browse files Browse the repository at this point in the history
  • Loading branch information
dliu27 committed Dec 6, 2024
1 parent cec2b43 commit 8f73433
Show file tree
Hide file tree
Showing 4 changed files with 314 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {MockedResponse} from '@apollo/client/testing';

import {
RunStatus,
buildDryRunInstigationTick,
buildErrorChainLink,
buildPipelineTag,
Expand All @@ -9,6 +10,8 @@ import {
buildSchedule,
buildTickEvaluation,
} from '../../graphql/types';
import {LAUNCH_MULTIPLE_RUNS_MUTATION} from '../../runs/RunUtils';
import {LaunchMultipleRunsMutation} from '../../runs/types/RunUtils.types';
import {GET_SCHEDULE_QUERY, SCHEDULE_DRY_RUN_MUTATION} from '../EvaluateScheduleDialog';
import {GetScheduleQuery, ScheduleDryRunMutation} from '../types/EvaluateScheduleDialog.types';

Expand Down Expand Up @@ -63,7 +66,7 @@ export const scheduleDryWithWithRunRequest = {
value: 'okay',
}),
],
runKey: null,
runKey: 'EvaluateScheduleDialog.test.tsx:1675705668.993122345',
}),
],
skipReason: null,
Expand Down Expand Up @@ -164,3 +167,89 @@ export const ScheduleDryRunMutationSkipped: MockedResponse<ScheduleDryRunMutatio
},
},
};

export const ScheduleLaunchAllMutation: MockedResponse<LaunchMultipleRunsMutation> = {
request: {
query: LAUNCH_MULTIPLE_RUNS_MUTATION,
variables: {
executionParamsList: [
{
runConfigData: 'ops:\n configurable_op:\n config:\n scheduled_date: 2023-01-29',
selector: {
jobName: 'saepe',
repositoryLocationName: 'testLocation',
repositoryName: 'testName',
assetSelection: [],
assetCheckSelection: [],
solidSelection: undefined,
},
mode: 'default',
executionMetadata: {
tags: [
{
key: 'dagster/schedule_name',
value: 'configurable_job_schedule',
},
{
key: 'date',
value: '2023-01-29',
},
{
key: 'github_test',
value: 'test',
},
{
key: 'okay_t2',
value: 'okay',
},
],
},
},
],
},
},
result: {
data: {
__typename: 'Mutation',
launchMultipleRuns: {
__typename: 'LaunchMultipleRunsResult',
launchMultipleRunsResult: [
{
__typename: 'LaunchRunSuccess',
run: {
__typename: 'Run',
id: '504b3a77-d6c4-440c-a128-7f59c9d75d59',
pipeline: {
__typename: 'PipelineSnapshot',
name: 'saepe',
},
tags: [
buildPipelineTag({
key: 'dagster/schedule_name',
value: 'configurable_job_schedule',
}),
buildPipelineTag({
key: 'date',
value: '2023-01-29',
}),
buildPipelineTag({
key: 'github_test',
value: 'test',
}),
buildPipelineTag({
key: 'okay_t2',
value: 'okay',
}),
],
status: RunStatus.QUEUED,
runConfigYaml:
'ops:\n configurable_op:\n config:\n scheduled_date: 2023-01-29',
mode: 'default',
resolvedOpSelection: null,
},
},
],
},
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {MockedResponse} from '@apollo/client/testing';
import {
InstigationStatus,
RunRequest,
RunStatus,
buildDryRunInstigationTick,
buildErrorChainLink,
buildInstigationState,
Expand All @@ -13,6 +14,8 @@ import {
buildSensorData,
buildTickEvaluation,
} from '../../graphql/types';
import {LAUNCH_MULTIPLE_RUNS_MUTATION} from '../../runs/RunUtils';
import {LaunchMultipleRunsMutation} from '../../runs/types/RunUtils.types';
import {SET_CURSOR_MUTATION} from '../../sensors/EditCursorDialog';
import {SetSensorCursorMutation} from '../../sensors/types/EditCursorDialog.types';
import {EVALUATE_SENSOR_MUTATION} from '../SensorDryRunDialog';
Expand Down Expand Up @@ -177,3 +180,161 @@ export const PersistCursorValueMock: MockedResponse<SetSensorCursorMutation> = {
},
},
};

export const SensorLaunchAllMutation: MockedResponse<LaunchMultipleRunsMutation> = {
request: {
query: LAUNCH_MULTIPLE_RUNS_MUTATION,
variables: {
executionParamsList: [
{
runConfigData:
'solids:\n read_file:\n config:\n directory: /Users/marcosalazar/code/dagster/js_modules/dagster-ui/packages/ui-core/src/ticks/tests\n filename: DryRunRequestTable.test.tsx',
selector: {
jobName: 'saepe',
repositoryLocationName: 'testLocation',
repositoryName: 'testName',
assetSelection: [],
assetCheckSelection: [],
solidSelection: undefined,
},
mode: 'default',
executionMetadata: {
tags: [
{
key: 'dagster2',
value: 'test',
},
{
key: 'marco2',
value: 'salazar2',
},
],
},
},
{
runConfigData:
'solids:\n read_file:\n config:\n directory: /Users/marcosalazar/code/dagster/js_modules/dagster-ui/packages/ui-core/src/ticks/tests\n filename: DryRunRequestTable.test.tsx',
selector: {
jobName: 'saepe',
repositoryLocationName: 'testLocation',
repositoryName: 'testName',
assetSelection: [],
assetCheckSelection: [],
solidSelection: undefined,
},
mode: 'default',
executionMetadata: {
tags: [
{
key: 'dagster3',
value: 'test',
},
{
key: 'marco3',
value: 'salazar3',
},
],
},
},
{
runConfigData:
'solids:\n read_file:\n config:\n directory: /Users/marcosalazar/code/dagster/js_modules/dagster-ui/packages/ui-core/src/ticks/tests\n filename: DryRunRequestTable.test.tsx',
selector: {
jobName: 'saepe',
repositoryLocationName: 'testLocation',
repositoryName: 'testName',
assetSelection: [],
assetCheckSelection: [],
solidSelection: undefined,
},
mode: 'default',
executionMetadata: {
tags: [
{
key: 'dagster6',
value: 'test',
},
{
key: 'marco6',
value: 'salazar6',
},
],
},
},
],
},
},
result: {
data: {
__typename: 'Mutation',
launchMultipleRuns: {
__typename: 'LaunchMultipleRunsResult',
launchMultipleRunsResult: [
{
__typename: 'LaunchRunSuccess',
run: {
__typename: 'Run',
id: '504b3a77-d6c4-440c-a128-7f59c9d75d59',
pipeline: {
__typename: 'PipelineSnapshot',
name: 'saepe',
},
tags: [
buildPipelineTag({key: 'dagster2', value: 'test'}),
buildPipelineTag({key: 'marco2', value: 'salazar2'}),
],
status: RunStatus.QUEUED,
runConfigYaml:
'solids:\n read_file:\n config:\n directory: /Users/marcosalazar/code/dagster/js_modules/dagster-ui/packages/ui-core/src/ticks/tests\n filename: DryRunRequestTable.test.tsx\n',
mode: 'default',
resolvedOpSelection: null,
},
},
{
__typename: 'LaunchRunSuccess',
run: {
__typename: 'Run',
id: '6745cd03-3d89-4fd2-a41f-6b9d9ffdc134',
pipeline: {
__typename: 'PipelineSnapshot',
name: 'saepe',
},
tags: [
buildPipelineTag({key: 'dagster3', value: 'test'}),
buildPipelineTag({key: 'marco3', value: 'salazar3'}),
],

status: RunStatus.QUEUED,
runConfigYaml:
'solids:\n read_file:\n config:\n directory: /Users/marcosalazar/code/dagster/js_modules/dagster-ui/packages/ui-core/src/ticks/tests\n filename: DryRunRequestTable.test.tsx\n',

mode: 'default',
resolvedOpSelection: null,
},
},
{
__typename: 'LaunchRunSuccess',
run: {
__typename: 'Run',
id: '7ed35f69-42cf-4518-84a4-c97d0551a56b',
pipeline: {
__typename: 'PipelineSnapshot',
name: 'simple_config_job',
},
tags: [
buildPipelineTag({key: 'dagster6', value: 'test'}),
buildPipelineTag({key: 'marco6', value: 'salazar6'}),
],
status: RunStatus.QUEUED,
runConfigYaml:
'solids:\n read_file:\n config:\n directory: /Users/marcosalazar/code/dagster/js_modules/dagster-ui/packages/ui-core/src/ticks/tests\n filename: DryRunRequestTable.test.tsx\n',

mode: 'default',
resolvedOpSelection: null,
},
},
],
},
},
},
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {MockedProvider, MockedResponse} from '@apollo/client/testing';
import {render, screen, waitFor} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import {MemoryRouter, useHistory} from 'react-router-dom';

import {Resolvers} from '../../apollo-client';
import {EvaluateScheduleDialog} from '../EvaluateScheduleDialog';
Expand All @@ -9,6 +10,7 @@ import {
ScheduleDryRunMutationError,
ScheduleDryRunMutationRunRequests,
ScheduleDryRunMutationSkipped,
ScheduleLaunchAllMutation,
} from '../__fixtures__/EvaluateScheduleDialog.fixtures';

// This component is unit tested separately so mocking it out
Expand All @@ -18,6 +20,12 @@ jest.mock('../DryRunRequestTable', () => {
};
});

// Mocking useHistory
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useHistory: jest.fn(),
}));

const onCloseMock = jest.fn();

function Test({mocks, resolvers}: {mocks?: MockedResponse[]; resolvers?: Resolvers}) {
Expand Down Expand Up @@ -103,7 +111,25 @@ describe('EvaluateScheduleTest', () => {
});

it('launches all runs', async () => {
render(<Test mocks={[GetScheduleQueryMock, ScheduleDryRunMutationRunRequests]} />);
const pushSpy = jest.fn();
const createHrefSpy = jest.fn();

(useHistory as jest.Mock).mockReturnValue({
push: pushSpy,
createHref: createHrefSpy,
});

render(
<MemoryRouter initialEntries={['/automation']}>
<Test
mocks={[
GetScheduleQueryMock,
ScheduleDryRunMutationRunRequests,
ScheduleLaunchAllMutation,
]}
/>
</MemoryRouter>,
);
const selectButton = await screen.findByTestId('tick-selection');
await userEvent.click(selectButton);
await waitFor(() => {
Expand All @@ -121,5 +147,9 @@ describe('EvaluateScheduleTest', () => {
await waitFor(() => {
expect(screen.getByText(/Launching runs/i)).toBeVisible();
});
}, 10000);

await waitFor(() => {
expect(pushSpy).toHaveBeenCalled();
});
});
});
Loading

0 comments on commit 8f73433

Please sign in to comment.