grafana/public/app/features/datasource-drawer/DataSourceDrawer.test.ts
Oscar Kilhed dc1600ff14
DataSourcePicker: Add new style of data source picker. (#63736)
* MVP of a new datasource picker

* Add datasource select history, naming DatasourceSelect -> DataSourceDrawer

* refactor cards

* Cleanup and fixing sort order for recents

* add feature flag

* fix feature flag name and use it

* Highlight selected

* Move new ds picker to core

* Restore original datasource picker

* Remove unused property

* update yarn.lock

* Rename folder, update codeowners

* add test for util functions

* Remove es-lint exception

* Change feature toggle description

* remove unnecessary if

Co-authored-by: Ivan Ortega Alba <ivanortegaalba@gmail.com>

* Make test a bit more clear

Co-authored-by: Ivan Ortega Alba <ivanortegaalba@gmail.com>

* Clean up api, filter once and before maps, minor code cleanup

* Fix prettier issue

---------

Co-authored-by: Ivan Ortega Alba <ivanortegaalba@gmail.com>
2023-03-01 11:26:19 +01:00

38 lines
1.6 KiB
TypeScript

import { DataSourceInstanceSettings } from '@grafana/data';
import { DataSourceJsonData, DataSourceRef } from '@grafana/schema';
import { isDataSourceMatch } from './DataSourceDrawer';
describe('DataSourceDrawer', () => {
describe('isDataSourceMatch', () => {
const dataSourceInstanceSettings = { uid: 'a' } as DataSourceInstanceSettings<DataSourceJsonData>;
it('matches a string with the uid', () => {
expect(isDataSourceMatch(dataSourceInstanceSettings, 'a')).toBeTruthy();
});
it('matches a datasource with a datasource by the uid', () => {
expect(
isDataSourceMatch(dataSourceInstanceSettings, { uid: 'a' } as DataSourceInstanceSettings<DataSourceJsonData>)
).toBeTruthy();
});
it('matches a datasource ref with a datasource by the uid', () => {
expect(isDataSourceMatch(dataSourceInstanceSettings, { uid: 'a' } as DataSourceRef)).toBeTruthy();
});
it('doesnt match with null', () => {
expect(isDataSourceMatch(dataSourceInstanceSettings, null)).toBeFalsy();
});
it('doesnt match a datasource to a non matching string', () => {
expect(isDataSourceMatch(dataSourceInstanceSettings, 'b')).toBeFalsy();
});
it('doesnt match a datasource with a different datasource uid', () => {
expect(
isDataSourceMatch(dataSourceInstanceSettings, { uid: 'b' } as DataSourceInstanceSettings<DataSourceJsonData>)
).toBeFalsy();
});
it('doesnt match a datasource with a datasource ref with a different uid', () => {
expect(isDataSourceMatch(dataSourceInstanceSettings, { uid: 'b' } as DataSourceRef)).toBeFalsy();
});
});
});