Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/oss-console/src/components/Entities/EntitySchedules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ export const EntitySchedules: React.FC<{
operation: FilterOperationName.EQ,
value: id.name,
},
{
key: 'workflow.project',
operation: FilterOperationName.EQ,
value: id.project,
},
{
key: 'workflow.domain',
operation: FilterOperationName.EQ,
value: id.domain,
},
],
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react';
import { render, waitFor } from '@testing-library/react';
import { QueryClientProvider } from 'react-query';
import { FilterOperationName } from '@clients/common/types/adminEntityTypes';
import { ResourceIdentifier, ResourceType } from '../../../models/Common/types';
import * as launchPlanApi from '../../../models/Launch/api';
import { CREATED_AT_DESCENDING_SORT } from '../../../models/Launch/constants';
import { LaunchPlanState } from '../../../models/Launch/types';
import { createTestQueryClient } from '../../../test/utils';
import { EntitySchedules } from '../EntitySchedules';

it('scopes active launch plans to the workflow project, domain and name', async () => {
const id: ResourceIdentifier = {
resourceType: ResourceType.WORKFLOW,
project: 'flytesnacks',
domain: 'development',
name: 'scheduled-workflow',
};
const client = createTestQueryClient();
const listLaunchPlans = jest.spyOn(launchPlanApi, 'listLaunchPlans').mockResolvedValue({
entities: [],
});

try {
render(
<QueryClientProvider client={client}>
<EntitySchedules id={id} />
</QueryClientProvider>,
);

await waitFor(() =>
expect(listLaunchPlans).toHaveBeenCalledWith(
{ project: id.project, domain: id.domain, name: undefined },
{
limit: 5,
sort: CREATED_AT_DESCENDING_SORT,
filter: [
{
key: 'state',
operation: FilterOperationName.EQ,
value: LaunchPlanState.ACTIVE,
},
{
key: 'workflow.name',
operation: FilterOperationName.EQ,
value: id.name,
},
{
key: 'workflow.project',
operation: FilterOperationName.EQ,
value: id.project,
},
{
key: 'workflow.domain',
operation: FilterOperationName.EQ,
value: id.domain,
},
],
},
),
);
} finally {
listLaunchPlans.mockRestore();
client.clear();
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
QueryClientProviderProps,
} from 'react-query';
import Long from 'long';
import { RequestConfig } from '@clients/common/types/adminEntityTypes';
import { FilterOperationName, RequestConfig } from '@clients/common/types/adminEntityTypes';
import { APIContext } from '../../../data/apiContext';
import { mockAPIContextValue } from '../../../data/__mocks__/apiContext';
import {
Expand Down Expand Up @@ -255,6 +255,50 @@ describe('LaunchForm: Workflow', () => {
});
});

it('should scope launch plans to the selected workflow identifier', async () => {
const selectedWorkflow = {
...mockWorkflowVersions[0].id,
project: 'other-project',
domain: 'production',
};
mockWorkflowVersions[0].id = selectedWorkflow;
renderForm();

await waitFor(() =>
expect(mockListLaunchPlans).toHaveBeenCalledWith(
{
project: selectedWorkflow.project,
domain: selectedWorkflow.domain,
},
{
limit: 50,
filter: [
{
key: 'workflow.name',
operation: FilterOperationName.EQ,
value: selectedWorkflow.name,
},
{
key: 'workflow.version',
operation: FilterOperationName.EQ,
value: selectedWorkflow.version,
},
{
key: 'workflow.project',
operation: FilterOperationName.EQ,
value: selectedWorkflow.project,
},
{
key: 'workflow.domain',
operation: FilterOperationName.EQ,
value: selectedWorkflow.domain,
},
],
},
),
);
});

it('should select the launch plan matching the workflow name by default', async () => {
const { container } = renderForm();
await waitFor(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ async function loadLaunchPlans(
operation: FilterOperationName.EQ,
value: version,
},
{
key: 'workflow.project',
operation: FilterOperationName.EQ,
value: project,
},
{
key: 'workflow.domain',
operation: FilterOperationName.EQ,
value: domain,
},
],
limit: 50,
},
Expand Down
Loading