Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dliu27 committed Dec 19, 2024
1 parent 0b70ce4 commit 29606a4
Show file tree
Hide file tree
Showing 4 changed files with 336 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,44 @@ export const scheduleDryWithWithRunRequest = {
}),
};

export const scheduleDryWithWithRunRequestUndefinedName = {
__typename: 'Mutation' as const,
scheduleDryRun: buildDryRunInstigationTick({
timestamp: 1674950400,
evaluationResult: buildTickEvaluation({
runRequests: [
buildRunRequest({
jobName: undefined,
runConfigYaml:
'ops:\n configurable_op:\n config:\n scheduled_date: 2023-01-29\n',
tags: [
buildPipelineTag({
key: 'dagster/schedule_name',
value: 'configurable_job_schedule',
}),
buildPipelineTag({
key: 'date',
value: '2023-01-29',
__typename: 'PipelineTag' as const,
}),
buildPipelineTag({
key: 'github_test',
value: 'test',
}),
buildPipelineTag({
key: 'okay_t2',
value: 'okay',
}),
],
runKey: 'EvaluateScheduleDialog.test.tsx:1675705668.993122345',
}),
],
skipReason: null,
error: null,
}),
}),
};

export const ScheduleDryRunMutationRunRequests: MockedResponse<ScheduleDryRunMutation> = {
request: {
query: SCHEDULE_DRY_RUN_MUTATION,
Expand All @@ -94,6 +132,22 @@ export const ScheduleDryRunMutationRunRequests: MockedResponse<ScheduleDryRunMut
result: {data: scheduleDryWithWithRunRequest},
};

export const ScheduleDryRunMutationRunRequestsWithUndefinedName: MockedResponse<ScheduleDryRunMutation> =
{
request: {
query: SCHEDULE_DRY_RUN_MUTATION,
variables: {
selectorData: {
scheduleName: 'test',
repositoryLocationName: 'testLocation',
repositoryName: 'testName',
},
timestamp: 5,
},
},
result: {data: scheduleDryWithWithRunRequestUndefinedName},
};

export const ScheduleDryRunMutationError: MockedResponse<ScheduleDryRunMutation> = {
request: {
query: SCHEDULE_DRY_RUN_MUTATION,
Expand Down Expand Up @@ -253,3 +307,87 @@ export const ScheduleLaunchAllMutation: MockedResponse<LaunchMultipleRunsMutatio
},
},
};

export const ScheduleLaunchAllMutationWithUndefinedName: 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: 'testJobName', // fallback
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: 'testJobName', // fallback
}),
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 @@ -55,6 +55,19 @@ export const runRequests: RunRequest[] = [
}),
];

export const runRequestWithUndefinedJobName: RunRequest[] = [
buildRunRequest({
jobName: undefined, // undefined jobName
runKey: 'DryRunRequestTable.test.tsx:1675705668.9931223',
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',
tags: [
buildPipelineTag({key: 'dagster2', value: 'test'}),
buildPipelineTag({key: 'marco2', value: 'salazar2'}),
],
}),
];

export const SensorDryRunMutationRunRequests: MockedResponse<SensorDryRunMutation> = {
request: {
query: EVALUATE_SENSOR_MUTATION,
Expand All @@ -81,6 +94,33 @@ export const SensorDryRunMutationRunRequests: MockedResponse<SensorDryRunMutatio
},
};

export const SensorDryRunMutationRunRequestWithUndefinedJobName: MockedResponse<SensorDryRunMutation> =
{
request: {
query: EVALUATE_SENSOR_MUTATION,
variables: {
selectorData: {
sensorName: 'test',
repositoryLocationName: 'testLocation',
repositoryName: 'testName',
},
cursor: 'testCursortesting123',
},
},
result: {
data: {
__typename: 'Mutation',
sensorDryRun: buildDryRunInstigationTick({
evaluationResult: buildTickEvaluation({
cursor: 'a new cursor',
runRequests: runRequestWithUndefinedJobName,
error: null,
}),
}),
},
},
};

export const SensorDryRunMutationError: MockedResponse<SensorDryRunMutation> = {
request: {
query: EVALUATE_SENSOR_MUTATION,
Expand Down Expand Up @@ -335,3 +375,67 @@ export const SensorLaunchAllMutation: MockedResponse<LaunchMultipleRunsMutation>
},
},
};

export const SensorLaunchAllMutation1JobWithUndefinedJobName: 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: 'testJobName', // fallback
repositoryLocationName: 'testLocation',
repositoryName: 'testName',
assetSelection: [],
assetCheckSelection: [],
solidSelection: undefined,
},
mode: 'default',
executionMetadata: {
tags: [
{
key: 'dagster2',
value: 'test',
},
{
key: 'marco2',
value: 'salazar2',
},
],
},
},
],
},
},
result: {
data: {
__typename: 'Mutation',
launchMultipleRuns: buildLaunchMultipleRunsResult({
launchMultipleRunsResult: [
buildLaunchRunSuccess({
__typename: 'LaunchRunSuccess',
run: buildRun({
__typename: 'Run',
id: '504b3a77-d6c4-440c-a128-7f59c9d75d59',
pipeline: buildPipelineSnapshot({
name: 'testJobName',
}),
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,
}),
}),
],
}),
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import {
GetScheduleQueryMock,
ScheduleDryRunMutationError,
ScheduleDryRunMutationRunRequests,
ScheduleDryRunMutationRunRequestsWithUndefinedName,
ScheduleDryRunMutationSkipped,
ScheduleLaunchAllMutation,
ScheduleLaunchAllMutationWithUndefinedName,
} from '../__fixtures__/EvaluateScheduleDialog.fixtures';

// This component is unit tested separately so mocking it out
Expand Down Expand Up @@ -160,4 +162,49 @@ describe('EvaluateScheduleTest', () => {
expect(pushSpy).toHaveBeenCalled();
});
});

it('launches all runs for 1 runrequest with undefined job name in the runrequest', async () => {
const pushSpy = jest.fn();
const createHrefSpy = jest.fn();

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

(useTrackEvent as jest.Mock).mockReturnValue(jest.fn());

render(
<MemoryRouter initialEntries={['/automation']}>
<Test
mocks={[
GetScheduleQueryMock,
ScheduleDryRunMutationRunRequestsWithUndefinedName,
ScheduleLaunchAllMutationWithUndefinedName,
]}
/>
</MemoryRouter>,
);
const selectButton = await screen.findByTestId('tick-selection');
await userEvent.click(selectButton);
await waitFor(() => {
expect(screen.getByTestId('tick-5')).toBeVisible();
});
await userEvent.click(screen.getByTestId('tick-5'));
await userEvent.click(screen.getByTestId('continue'));
await waitFor(() => {
expect(screen.getByText(/1\s+run request/i)).toBeVisible();
expect(screen.getByTestId('launch-all')).not.toBeDisabled();
});

userEvent.click(screen.getByTestId('launch-all'));

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

await waitFor(() => {
expect(pushSpy).toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('SensorDryRunTest', () => {
expect(screen.getByTestId('cursor-input')).toBeVisible();
});

it('launches all runs', async () => {
it('launches all runs with well defined job names', async () => {
const pushSpy = jest.fn();
const createHrefSpy = jest.fn();

Expand Down Expand Up @@ -140,4 +140,50 @@ describe('SensorDryRunTest', () => {
expect(pushSpy).toHaveBeenCalled();
});
});

it('launches all runs for 1 runrequest with undefined job name in the runrequest', async () => {
const pushSpy = jest.fn();
const createHrefSpy = jest.fn();

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

(useTrackEvent as jest.Mock).mockReturnValue(jest.fn());

render(
<MemoryRouter initialEntries={['/automation']}>
<Test
mocks={[
Mocks.SensorDryRunMutationRunRequestWithUndefinedJobName,
Mocks.PersistCursorValueMock,
Mocks.SensorLaunchAllMutation1JobWithUndefinedJobName,
]}
/>
</MemoryRouter>,
);
const cursorInput = await screen.findByTestId('cursor-input');
await userEvent.type(cursorInput, 'testing123');
await userEvent.click(screen.getByTestId('continue'));
await waitFor(() => {
expect(screen.getByText(/1\srun requests/g)).toBeVisible();
expect(screen.queryByText('Skipped')).toBe(null);
expect(screen.queryByText('Failed')).toBe(null);
});

await waitFor(() => {
expect(screen.getByTestId('launch-all')).not.toBeDisabled();
});

userEvent.click(screen.getByTestId('launch-all'));

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

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

0 comments on commit 29606a4

Please sign in to comment.