Skip to content

Commit

Permalink
add tests for getSelectedIdFromUrl and getGroupQueryText
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarezmelissa87 committed Aug 10, 2020
1 parent 148ab2a commit 3e9c17b
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

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 groupIdOne = 'test_group_id_1';
const groupIdTwo = 'test_group_id_2';
const groupIdsUrl = `http://localhost:5601/aql/app/ml#/jobs?mlManagement=(groupIds:!(${groupIdOne},${groupIdTwo}))`;
const groupIdUrl = `http://localhost:5601/aql/app/ml#/jobs?mlManagement=(groupIds:!(${groupIdOne}))`;

describe('getSelectedIdFromUrl', () => {
it('should get selected job id from the url', () => {
const actual = getSelectedIdFromUrl(jobIdUrl);
expect(actual).toStrictEqual({ ids: [jobId], isGroup: false });
});

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

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

describe('getGroupQueryText', () => {
it('should get query string for selected group ids', () => {
const actual = getGroupQueryText([groupIdOne, groupIdTwo]);
expect(actual).toBe(`groups:(${groupIdOne} or ${groupIdTwo})`);
});

it('should get query string for selected group id', () => {
const actual = getGroupQueryText([groupIdOne]);
expect(actual).toBe(`groups:(${groupIdOne})`);
});
});
});

0 comments on commit 3e9c17b

Please sign in to comment.