grafana/public/app/core/services/NewFrontendAssetsChecker.test.ts
Torkel Ödegaard e924627659
Frontend: Reload the browser when backend configuration/assets change (#79057)
* Detect frontend asset changes

* Update

* merge main

* Frontend: Detect new assets / versions / config changes (#79258)

* avoid first check

* Updates and add tests

* Update

* Update

* Updated code

* refine

* use context

---------

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2024-01-04 08:00:07 +01:00

50 lines
1.4 KiB
TypeScript

import { locationService, setBackendSrv, BackendSrv } from '@grafana/runtime';
import { NewFrontendAssetsChecker } from './NewFrontendAssetsChecker';
describe('NewFrontendAssetsChecker', () => {
const backendApiGet = jest.fn().mockReturnValue(Promise.resolve({}));
const locationReload = jest.fn();
const originalLocation = window.location;
beforeAll(() => {
Object.defineProperty(window, 'location', {
configurable: true,
value: { reload: locationReload },
});
});
afterAll(() => {
Object.defineProperty(window, 'location', { configurable: true, value: originalLocation });
});
setBackendSrv({
get: backendApiGet,
} as unknown as BackendSrv);
it('Should skip update checks if below interval', () => {
const checker = new NewFrontendAssetsChecker();
checker.start();
locationService.push('/d/123');
expect(backendApiGet).toHaveBeenCalledTimes(0);
});
it('Should do update check when changing dashboard or going home', async () => {
const checker = new NewFrontendAssetsChecker(0);
checker.start();
locationService.push('/d/asd');
locationService.push('/d/other');
locationService.push('/d/other?viewPanel=2');
locationService.push('/ignored');
locationService.push('/ignored?asd');
locationService.push('/ignored/sub');
locationService.push('/home');
expect(backendApiGet).toHaveBeenCalledTimes(2);
});
});