Skip to content

Commit

Permalink
[11/n] [RFC] add jest tests (#26249)
Browse files Browse the repository at this point in the history
## Summary & Motivation
Linear:
https://linear.app/dagster-labs/issue/FE-713/add-jest-tests-for-sensors-and-schedules

Adds jest tests for launch all

## How I Tested These Changes
yarn jest, ts, lint
  • Loading branch information
dliu27 authored Dec 9, 2024
1 parent c64a0f8 commit 2f38871
Show file tree
Hide file tree
Showing 7 changed files with 398 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const RunRequestTable = ({runRequests, isJob, repoAddress, mode, jobName}
</td>
<td style={{width: '7.5%', verticalAlign: 'middle', textAlign: 'center'}}>
<PreviewButton
request={request}
onClick={() => {
setSelectedRequest(request);
setVisibleDialog('config');
Expand Down Expand Up @@ -91,10 +92,14 @@ export const RunRequestTable = ({runRequests, isJob, repoAddress, mode, jobName}
);
};

function PreviewButton({onClick}: {onClick: () => void}) {
function PreviewButton({request, onClick}: {request: RunRequestFragment; onClick: () => void}) {
return (
<Tooltip content="Preview run config and tags" placement="left-start">
<Button icon={<Icon name="data_object" />} onClick={onClick} />
<Button
icon={<Icon name="data_object" />}
onClick={onClick}
data-testid={testId(`preview-${request.runKey || ''}`)}
/>
</Tooltip>
);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import {MockedResponse} from '@apollo/client/testing';

import {
RunStatus,
buildDryRunInstigationTick,
buildErrorChainLink,
buildLaunchMultipleRunsResult,
buildLaunchRunSuccess,
buildPipelineSnapshot,
buildPipelineTag,
buildPythonError,
buildRun,
buildRunRequest,
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 +70,7 @@ export const scheduleDryWithWithRunRequest = {
value: 'okay',
}),
],
runKey: null,
runKey: 'EvaluateScheduleDialog.test.tsx:1675705668.993122345',
}),
],
skipReason: null,
Expand Down Expand Up @@ -164,3 +171,85 @@ 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: buildLaunchMultipleRunsResult({
launchMultipleRunsResult: [
buildLaunchRunSuccess({
run: buildRun({
id: '504b3a77-d6c4-440c-a128-7f59c9d75d59',
pipeline: buildPipelineSnapshot({
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,16 +3,23 @@ import {MockedResponse} from '@apollo/client/testing';
import {
InstigationStatus,
RunRequest,
RunStatus,
buildDryRunInstigationTick,
buildErrorChainLink,
buildInstigationState,
buildLaunchMultipleRunsResult,
buildLaunchRunSuccess,
buildPipelineSnapshot,
buildPipelineTag,
buildPythonError,
buildRun,
buildRunRequest,
buildSensor,
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 +184,154 @@ 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: buildLaunchMultipleRunsResult({
launchMultipleRunsResult: [
buildLaunchRunSuccess({
__typename: 'LaunchRunSuccess',
run: buildRun({
__typename: 'Run',
id: '504b3a77-d6c4-440c-a128-7f59c9d75d59',
pipeline: buildPipelineSnapshot({
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,
}),
}),
buildLaunchRunSuccess({
__typename: 'LaunchRunSuccess',
run: buildRun({
__typename: 'Run',
id: '6745cd03-3d89-4fd2-a41f-6b9d9ffdc134',
pipeline: buildPipelineSnapshot({
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,
}),
}),
buildLaunchRunSuccess({
run: buildRun({
id: '7ed35f69-42cf-4518-84a4-c97d0551a56b',
pipeline: buildPipelineSnapshot({
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,4 +1,4 @@
import {render, screen} from '@testing-library/react';
import {render, screen, waitFor} from '@testing-library/react';
import {BrowserRouter} from 'react-router-dom';

import {RunRequestTable} from '../DryRunRequestTable';
Expand All @@ -9,6 +9,10 @@ jest.mock('../../workspace/WorkspaceContext/util', () => ({
useRepository: jest.fn(() => null),
}));

jest.mock('../../runs/RunConfigDialog', () => ({
RunConfigDialog: () => <div>RunConfigDialog</div>,
}));

function TestComponent() {
return (
<BrowserRouter>
Expand All @@ -31,10 +35,19 @@ describe('RunRequestTableTest', () => {
render(<TestComponent />);

runRequests.forEach((req) => {
req.tags.forEach(({key, value}) => {
expect(screen.getByText(`${key}: ${value}`)).toBeVisible();
});
expect(screen.getByTestId(req.runKey!)).toBeVisible();
});
});

it('renders preview button and opens dialog on click', async () => {
render(<TestComponent />);

const previewButton = screen.getByTestId(`preview-${runRequests[0]!.runKey || ''}`);
expect(previewButton).toBeVisible();
previewButton.click();

await waitFor(() => {
expect(screen.getByText(/RunConfigDialog/i)).toBeVisible();
});
});
});
Loading

1 comment on commit 2f38871

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for dagit-core-storybook ready!

✅ Preview
https://dagit-core-storybook-4we0jxxl3-elementl.vercel.app

Built with commit 2f38871.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.