The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/dashboard/api/v0.test.ts

65 lines
1.6 KiB

import { backendSrv } from 'app/core/services/backend_srv';
import { AnnoKeyFolder } from 'app/features/apiserver/types';
import { DashboardDataDTO } from 'app/types';
import { DashboardWithAccessInfo } from './types';
import { K8sDashboardAPI } from './v0';
const mockDashboardDto: DashboardWithAccessInfo<DashboardDataDTO> = {
kind: 'DashboardWithAccessInfo',
apiVersion: 'v0alpha1',
metadata: {
name: 'dash-uid',
resourceVersion: '1',
creationTimestamp: '1',
annotations: {
[AnnoKeyFolder]: 'new-folder',
},
},
spec: {
title: 'test',
uid: 'test',
schemaVersion: 0,
},
access: {},
};
jest.mock('@grafana/runtime', () => ({
getBackendSrv: () => ({
get: () => mockDashboardDto,
}),
config: {},
}));
jest.mock('app/features/live/dashboard/dashboardWatcher', () => ({
ignoreNextSave: jest.fn(),
}));
describe('v0 dashboard API', () => {
it('should provide folder annotations', async () => {
jest.spyOn(backendSrv, 'getFolderByUid').mockResolvedValue({
id: 1,
uid: 'new-folder',
title: 'New Folder',
url: '/folder/url',
canAdmin: true,
canDelete: true,
canEdit: true,
canSave: true,
created: '',
createdBy: '',
hasAcl: false,
updated: '',
updatedBy: '',
});
const api = new K8sDashboardAPI();
const result = await api.getDashboardDTO('test');
expect(result.meta.isFolder).toBe(false);
expect(result.meta.folderId).toBe(1);
expect(result.meta.folderTitle).toBe('New Folder');
expect(result.meta.folderUrl).toBe('/folder/url');
expect(result.meta.folderUid).toBe('new-folder');
});
});