grafana/public/app/features/datasource-drawer/DataSourcePickerWithHistory.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

28 lines
1.1 KiB
TypeScript

import { updateHistory } from './DataSourcePickerWithHistory';
describe('DataSourcePickerWithHistory', () => {
describe('updateHistory', () => {
const early = { uid: 'b', lastUse: '2023-02-27T13:39:08.318Z' };
const later = { uid: 'a', lastUse: '2023-02-28T13:39:08.318Z' };
it('should add an item to the history', () => {
expect(updateHistory([], early)).toEqual([early]);
});
it('should sort later entries first', () => {
expect(updateHistory([early], later)).toEqual([later, early]);
});
it('should update an already existing history item with the new lastUsed date', () => {
const laterB = { uid: early.uid, lastUse: later.lastUse };
expect(updateHistory([early], laterB)).toEqual([laterB]);
});
it('should keep the three latest items in history', () => {
const evenLater = { uid: 'c', lastUse: '2023-03-01T13:39:08.318Z' };
const latest = { uid: 'd', lastUse: '2023-03-02T13:39:08.318Z' };
expect(updateHistory([early, later, evenLater], latest)).toEqual([latest, evenLater, later]);
});
});
});