grafana/public/app/core/components/AppChrome/AppChromeService.test.tsx
Ashley Harrison 0741f47876
Navigation: Move SectionNav to AppChrome (#64391)
* move section nav to app chrome

* unit tests

* Move SectionNav to AppChrome folder

* fix duplicate variable rendering

---------

Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2023-04-18 14:58:00 +01:00

49 lines
1.7 KiB
TypeScript

import { AppChromeService } from './AppChromeService';
describe('AppChromeService', () => {
it('onToggleKioskMode should set chromeless to true when searchbar is hidden', () => {
const chromeService = new AppChromeService();
chromeService.onToggleSearchBar();
chromeService.onToggleKioskMode();
expect(chromeService.state.getValue().chromeless).toBe(true);
});
it('Ignore state updates when sectionNav and pageNav have new instance but same text, url or active child', () => {
const chromeService = new AppChromeService();
let stateChanges = 0;
chromeService.state.subscribe(() => stateChanges++);
chromeService.update({
sectionNav: { node: { text: 'hello' }, main: { text: '' } },
pageNav: { text: 'test', url: 'A' },
});
chromeService.update({
sectionNav: { node: { text: 'hello' }, main: { text: '' } },
pageNav: { text: 'test', url: 'A' },
});
expect(stateChanges).toBe(2);
// if url change we should update
chromeService.update({
sectionNav: { node: { text: 'hello' }, main: { text: '' } },
pageNav: { text: 'test', url: 'new/url' },
});
expect(stateChanges).toBe(3);
// if active child changed should update state
chromeService.update({
sectionNav: { node: { text: 'hello' }, main: { text: '' } },
pageNav: { text: 'test', url: 'A', children: [{ text: 'child', active: true }] },
});
expect(stateChanges).toBe(4);
// If active child is the same we should not update state
chromeService.update({
sectionNav: { node: { text: 'hello' }, main: { text: '' } },
pageNav: { text: 'test', url: 'A', children: [{ text: 'child', active: true }] },
});
expect(stateChanges).toBe(4);
});
});