Skip to content

Commit

Permalink
Adds couple more unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed May 11, 2024
1 parent 2b37fa5 commit 7a26e9f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 0 additions & 1 deletion public/utils/datasource-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
9 changes: 9 additions & 0 deletions public/utils/test/datasource-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({});
});
});

0 comments on commit 7a26e9f

Please sign in to comment.