From 7a26e9f30d7dfe90d8dd00f9de0cd360217264af Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Sat, 11 May 2024 19:52:43 -0400 Subject: [PATCH] Adds couple more unit tests Signed-off-by: Darshit Chanpura --- public/utils/datasource-utils.ts | 1 - public/utils/test/datasource-utils.test.ts | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/public/utils/datasource-utils.ts b/public/utils/datasource-utils.ts index 80a137a55..638c515eb 100644 --- a/public/utils/datasource-utils.ts +++ b/public/utils/datasource-utils.ts @@ -31,7 +31,6 @@ export function getDataSourceFromUrl(): DataSourceOption { try { return JSON.parse(dataSourceParam); } catch (e) { - console.error('Failed to parse dataSourceParam:', dataSourceParam); return JSON.parse('{}'); // Return an empty object or some default value if parsing fails } } diff --git a/public/utils/test/datasource-utils.test.ts b/public/utils/test/datasource-utils.test.ts index 040166ec8..33aef7905 100644 --- a/public/utils/test/datasource-utils.test.ts +++ b/public/utils/test/datasource-utils.test.ts @@ -69,4 +69,13 @@ describe('Tests datasource utils', () => { 'http://localhost:5601/app/security-dashboards-plugin?dataSource=%7B%22id%22%3A%22%22%2C%22label%22%3A%22Local+cluster%22%7D#/auth' ); }); + + it('Tests getting the datasource from the url with undefined dataSource', () => { + const mockSearchUndefinedDataSource = '?dataSource=undefined'; + Object.defineProperty(window, 'location', { + value: { search: mockSearchUndefinedDataSource }, + writable: true, + }); + expect(getDataSourceFromUrl()).toEqual({}); + }); });