Skip to content

Commit

Permalink
[ML] update unit tests for solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Nov 17, 2020
1 parent 15724fc commit 4c6b00b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ test('MLLink produces the correct URL', async () => {
);

expect(href).toMatchInlineSnapshot(
`"/app/ml/jobs?_a=(queryText:'id:(something)%20groups:(apm)')&_g=(refreshInterval:(pause:!t,value:0),time:(from:now-5h,to:now-2h))"`
`"/app/ml/jobs?_a=(jobs:(queryText:'id:(something)%20groups:(apm)'))&_g=(refreshInterval:(pause:!t,value:0),time:(from:now-5h,to:now-2h))"`
);
});
11 changes: 2 additions & 9 deletions x-pack/plugins/ml/public/application/jobs/jobs_list/jobs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { NavigationMenu } from '../../components/navigation_menu';
import { JobsListView } from './components/jobs_list_view/index';
import { usePageUrlState } from '../../util/url_state';
import { ML_PAGES } from '../../../../common/constants/ml_url_generator';
import { ListingPageUrlState } from '../../../../common/types/common';

interface JobsPageProps {
blockRefresh?: boolean;
Expand All @@ -18,15 +19,7 @@ interface JobsPageProps {
lastRefresh?: number;
}

export interface AnomalyDetectionJobsListState {
pageSize: number;
pageIndex: number;
sortField: string;
sortDirection: string;
queryText?: string;
}

export const getDefaultAnomalyDetectionJobsListState = (): AnomalyDetectionJobsListState => ({
export const getDefaultAnomalyDetectionJobsListState = (): ListingPageUrlState => ({
pageIndex: 0,
pageSize: 10,
sortField: 'id',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import type {
import { ML_PAGES } from '../../common/constants/ml_url_generator';
import { createGenericMlUrl } from './common';
import { setStateToKbnUrl } from '../../../../../src/plugins/kibana_utils/public';
import type { AnomalyDetectionJobsListState } from '../application/jobs/jobs_list/jobs';
import { getGroupQueryText, getJobQueryText } from '../../common/util/string_utils';
import { AppPageState, ListingPageUrlState } from '../../common/types/common';
/**
* Creates URL to the Anomaly Detection Job management page
*/
Expand All @@ -41,11 +41,15 @@ export function createAnomalyDetectionJobManagementUrl(
if (groupIds) {
queryTextArr.push(getGroupQueryText(groupIds));
}
const queryState: Partial<AnomalyDetectionJobsListState> = {
const jobsListState: Partial<ListingPageUrlState> = {
...(queryTextArr.length > 0 ? { queryText: queryTextArr.join(' ') } : {}),
};

url = setStateToKbnUrl<Partial<AnomalyDetectionJobsListState>>(
const queryState: AppPageState<ListingPageUrlState> = {
[ML_PAGES.ANOMALY_DETECTION_JOBS_MANAGE]: jobsListState,
};

url = setStateToKbnUrl<AppPageState<ListingPageUrlState>>(
'_a',
queryState,
{ useHash: false, storeInHashQuery: false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('MlUrlGenerator', () => {
jobId: 'fq_single_1',
},
});
expect(url).toBe("/app/ml/jobs?_a=(queryText:'id:fq_single_1')");
expect(url).toBe("/app/ml/jobs?_a=(jobs:(queryText:'id:fq_single_1'))");
});

it('should generate valid URL for the Anomaly Detection job management page for groupIds', async () => {
Expand All @@ -40,7 +40,9 @@ describe('MlUrlGenerator', () => {
groupIds: ['farequote', 'categorization'],
},
});
expect(url).toBe("/app/ml/jobs?_a=(queryText:'groups:(farequote%20or%20categorization)')");
expect(url).toBe(
"/app/ml/jobs?_a=(jobs:(queryText:'groups:(farequote%20or%20categorization)'))"
);
});

it('should generate valid URL for the page for selecting the type of anomaly detection job to create', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ describe('JobsTableComponent', () => {
'[data-test-subj="jobs-table-link"]'
);
await waitFor(() =>
expect(href).toEqual('/app/ml/jobs?_a=(queryText:linux_anomalous_network_activity_ecs)')
expect(href).toEqual(
"/app/ml/jobs?_a=(jobs:(queryText:'id:linux_anomalous_network_activity_ecs'))"
)
);
});

Expand All @@ -72,7 +74,7 @@ describe('JobsTableComponent', () => {
'[data-test-subj="jobs-table-link"]'
);
await waitFor(() =>
expect(href).toEqual("/app/ml/jobs?_a=(queryText:'job%20id%20with%20spaces')")
expect(href).toEqual("/app/ml/jobs?_a=(jobs:(queryText:'id:job%20id%20with%20spaces'))")
);
});

Expand Down

0 comments on commit 4c6b00b

Please sign in to comment.