From 7245d89a9958d01052a104a20ca3f9cc34684307 Mon Sep 17 00:00:00 2001 From: Melissa Alvarez Date: Thu, 6 Aug 2020 12:02:01 -0400 Subject: [PATCH] add tests for getSelectedIdFromUrl and getGroupQueryText --- .../jobs/jobs_list/components/utils.test.ts | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 x-pack/plugins/ml/public/application/jobs/jobs_list/components/utils.test.ts diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/utils.test.ts b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/utils.test.ts new file mode 100644 index 000000000000000..7671928ec1eaad5 --- /dev/null +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/utils.test.ts @@ -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})`); + }); + }); +});