datatrails: detect if current trail state is bookmarked (#83283)

* fix: detect if current trail state is bookmarked
This commit is contained in:
Darren Janeczek
2024-02-23 10:00:10 -05:00
committed by GitHub
parent 604e02be15
commit 83c01f9711
5 changed files with 108 additions and 10 deletions

View File

@@ -167,7 +167,7 @@ describe('TrailStore', () => {
});
});
describe('Initialize store with one bookmark trail', () => {
beforeAll(() => {
beforeEach(() => {
localStorage.clear();
localStorage.setItem(
BOOKMARKED_TRAILS_KEY,
@@ -225,6 +225,35 @@ describe('TrailStore', () => {
expect(store.recent.length).toBe(1);
});
it('should be able to obtain index of bookmark', () => {
const trail = store.bookmarks[0].resolve();
const index = store.getBookmarkIndex(trail);
expect(index).toBe(0);
});
it('index should be undefined for removed bookmarks', () => {
const trail = store.bookmarks[0].resolve();
store.removeBookmark(0);
const index = store.getBookmarkIndex(trail);
expect(index).toBe(undefined);
});
it('index should be undefined for a trail that has changed since it was bookmarked', () => {
const trail = store.bookmarks[0].resolve();
trail.setState({ metric: 'something_completely_different' });
const index = store.getBookmarkIndex(trail);
expect(index).toBe(undefined);
});
it('should be able to obtain index of a bookmark for a trail that changed back to bookmarked state', () => {
const trail = store.bookmarks[0].resolve();
const bookmarkedMetric = trail.state.metric;
trail.setState({ metric: 'something_completely_different' });
trail.setState({ metric: bookmarkedMetric });
const index = store.getBookmarkIndex(trail);
expect(index).toBe(0);
});
it('should remove a bookmark', () => {
expect(store.bookmarks.length).toBe(1);
store.removeBookmark(0);