Files
Dominik Prokop ae62b3817b Dashboards: Change the way dashboard not found error is handled (#98950)
* Get rid of _dashboardLoadFailed

* Get rid of dashboardNotFound meta

* Update public dashboards tests

* Fix DashboardPage tests

* DashboardPageProxy tests

* DashboardScenePageStateManager test fix

* Beterer

* Fix merge

* Nits

* Fix test

* remove debugger

* Update get folder to throw

* translate error title

* Update public/app/features/apiserver/types.ts

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

* Update public/app/features/dashboard/services/DashboardLoaderSrv.ts

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

* Update public/app/features/dashboard/services/DashboardLoaderSrv.ts

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

* Update public/app/features/dashboard/services/DashboardLoaderSrv.ts

Co-authored-by: Haris Rozajac <58232930+harisrozajac@users.noreply.github.com>

* Betterer

* Update test cases

* More test updates

* More translations

---------

Co-authored-by: Ivan Ortega Alba <ivanortegaalba@gmail.com>
Co-authored-by: Haris Rozajac <58232930+harisrozajac@users.noreply.github.com>
2025-01-27 15:54:10 +01:00

61 lines
1.5 KiB
TypeScript

import { UrlQueryMap } from '@grafana/data';
import { DashboardDTO } from 'app/types';
import { LegacyDashboardAPI } from './legacy';
const mockDashboardDto: DashboardDTO = {
meta: {
isFolder: false,
},
dashboard: {
title: 'test',
uid: 'test',
schemaVersion: 0,
},
};
const backendSrvGetSpy = jest.fn();
jest.mock('@grafana/runtime', () => ({
getBackendSrv: () => ({
get: (dashUrl: string, params: Object) => {
backendSrvGetSpy(dashUrl, params);
const uid = dashUrl.split('/').pop();
if (uid === 'folderUid') {
return Promise.resolve({
meta: {
isFolder: true,
},
});
}
return mockDashboardDto;
},
}),
}));
jest.mock('app/features/live/dashboard/dashboardWatcher', () => ({
ignoreNextSave: jest.fn(),
}));
describe('Legacy dashboard API', () => {
it('should throw an error if requesting a folder', async () => {
const api = new LegacyDashboardAPI();
await expect(api.getDashboardDTO('folderUid')).rejects.toMatchObject({
status: 404,
config: { url: `/api/dashboards/uid/folderUid` },
data: { message: 'Dashboard not found' },
});
});
it('should return a valid dashboard', async () => {
const api = new LegacyDashboardAPI();
const params: UrlQueryMap = {
param: 1,
};
const result = await api.getDashboardDTO('validUid', params);
expect(result).toEqual(mockDashboardDto);
expect(backendSrvGetSpy).toHaveBeenLastCalledWith('/api/dashboards/uid/validUid', params);
});
});