Skip to content

Commit

Permalink
fix tests and update types
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarezmelissa87 committed Aug 10, 2020
1 parent 812cd04 commit e4d47f1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
EuiLink,
RIGHT_ALIGNMENT,
} from '@elastic/eui';
import { getJobIdUrl } from '../../../../../util/get_selected_ids_url';
import { getJobIdUrl, TAB_IDS } from '../../../../../util/get_selected_ids_url';

import { getAnalysisType, DataFrameAnalyticsId } from '../../../../common';
import {
Expand Down Expand Up @@ -137,7 +137,7 @@ export const progressColumn = {
};

export const getDFAnalyticsJobIdLink = (item: DataFrameAnalyticsListRow) => (
<EuiLink href={getJobIdUrl('data_frame_analytics', item.id)}>{item.id}</EuiLink>
<EuiLink href={getJobIdUrl(TAB_IDS.DATA_FRAME_ANALYTICS, item.id)}>{item.id}</EuiLink>
);

export const useColumns = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PropTypes from 'prop-types';
import React from 'react';

import { JobGroup } from '../job_group';
import { getGroupIdsUrl } from '../../../../util/get_selected_ids_url';
import { getGroupIdsUrl, TAB_IDS } from '../../../../util/get_selected_ids_url';

export function JobDescription({ job, isManagementTable }) {
return (
Expand All @@ -18,7 +18,7 @@ export function JobDescription({ job, isManagementTable }) {
{job.groups.map((group) => {
if (isManagementTable === true) {
return (
<a key={group} href={getGroupIdsUrl('jobs', [group])}>
<a key={group} href={getGroupIdsUrl(TAB_IDS.ANOMALY_DETECTION, [group])}>
<JobGroup name={group} />
</a>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { toLocaleString } from '../../../../util/string_utils';
import { ResultLinks, actionsMenuContent } from '../job_actions';
import { JobDescription } from './job_description';
import { JobIcon } from '../../../../components/job_message_icon';
import { getJobIdUrl } from '../../../../util/get_selected_ids_url';
import { getJobIdUrl, TAB_IDS } from '../../../../util/get_selected_ids_url';
import { TIME_FORMAT } from '../../../../../../common/constants/time_format';

import { EuiBadge, EuiBasicTable, EuiButtonIcon, EuiLink, EuiScreenReaderOnly } from '@elastic/eui';
Expand Down Expand Up @@ -71,7 +71,7 @@ export class JobsList extends Component {
return id;
}

return <EuiLink href={getJobIdUrl('jobs', id)}>{id}</EuiLink>;
return <EuiLink href={getJobIdUrl(TAB_IDS.ANOMALY_DETECTION, id)}>{id}</EuiLink>;
}

getPageOfJobs(index, size, sortField, sortDirection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
export function getSelectedIdFromUrl(str: string): { groupIds: string[] } | { jobId: string };

export function getSelectedIdFromUrl(str: string): { groupIds?: string[]; jobId?: string };
export function getGroupQueryText(arr: string[]): string;
export function clearSelectedJobIdFromUrl(str: string): void;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getGroupQueryText, getSelectedIdFromUrl } from './utils';

describe('ML - Jobs List utils', () => {
const jobId = 'test_job_id_1';
const jobIdUrl = `http://localhost:5601/aql/app/ml#/jobs?mlManagement=(jobId:!(${jobId}))`;
const jobIdUrl = `http://localhost:5601/aql/app/ml#/jobs?mlManagement=(jobId:${jobId})`;
const groupIdOne = 'test_group_id_1';
const groupIdTwo = 'test_group_id_2';
const groupIdsUrl = `http://localhost:5601/aql/app/ml#/jobs?mlManagement=(groupIds:!(${groupIdOne},${groupIdTwo}))`;
Expand All @@ -17,17 +17,17 @@ describe('ML - Jobs List utils', () => {
describe('getSelectedIdFromUrl', () => {
it('should get selected job id from the url', () => {
const actual = getSelectedIdFromUrl(jobIdUrl);
expect(actual).toStrictEqual({ ids: [jobId], isGroup: false });
expect(actual).toStrictEqual({ jobId });
});

it('should get selected group ids from the url', () => {
const expected = { ids: [groupIdOne, groupIdTwo], isGroup: true };
const expected = { groupIds: [groupIdOne, groupIdTwo] };
const actual = getSelectedIdFromUrl(groupIdsUrl);
expect(actual).toStrictEqual(expected);
});

it('should get selected group id from the url', () => {
const expected = { ids: [groupIdOne], isGroup: true };
const expected = { groupIds: [groupIdOne] };
const actual = getSelectedIdFromUrl(groupIdUrl);
expect(actual).toStrictEqual(expected);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export enum TAB_IDS {
ANOMALY_DETECTION = 'jobs',
}

function getSelectedIdsUrl(tabId, settings: any): string {
function getSelectedIdsUrl(tabId: TAB_IDS, settings: { [key: string]: string | string[] }): string {
// Create url for filtering by job id or group ids for kibana management table
const encoded = rison.encode(settings);
const url = `?mlManagement=${encoded}`;
Expand All @@ -21,7 +21,7 @@ function getSelectedIdsUrl(tabId, settings: any): string {
}

// Create url for filtering by group ids for kibana management table
export function getGroupIdsUrl(tabId: string, ids: string[]): string {
export function getGroupIdsUrl(tabId: TAB_IDS, ids: string[]): string {
const settings = {
groupIds: ids,
};
Expand All @@ -30,7 +30,7 @@ export function getGroupIdsUrl(tabId: string, ids: string[]): string {
}

// Create url for filtering by job id for kibana management table
export function getJobIdUrl(tabId: string, id: string): string {
export function getJobIdUrl(tabId: TAB_IDS, id: string): string {
const settings = {
jobId: id,
};
Expand Down

0 comments on commit e4d47f1

Please sign in to comment.