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-scene/utils/getDashboardUrl.test.ts

68 lines
1.8 KiB

import { getDashboardUrl } from './getDashboardUrl';
describe('dashboard utils', () => {
it('Can getUrl', () => {
const url = getDashboardUrl({ uid: 'dash-1', currentQueryParams: '?orgId=1&filter=A' });
expect(url).toBe('/d/dash-1?orgId=1&filter=A');
});
it('Can getUrl with subpath', () => {
const url = getDashboardUrl({
uid: 'dash-1',
subPath: '/panel-edit/2',
currentQueryParams: '?orgId=1&filter=A',
});
expect(url).toBe('/d/dash-1/panel-edit/2?orgId=1&filter=A');
});
it('Can getUrl for a snapshot', () => {
const url = getDashboardUrl({
uid: 'dash-1',
isSnapshot: true,
currentQueryParams: '?orgId=1&filter=A',
});
expect(url).toBe('/dashboard/snapshot/dash-1?orgId=1&filter=A');
});
it('Can getUrl with slug', () => {
const url = getDashboardUrl({
uid: 'dash-1',
slug: 'dash-1-slug',
subPath: '/panel-edit/2',
currentQueryParams: '?orgId=1&filter=A',
});
expect(url).toBe('/d/dash-1/dash-1-slug/panel-edit/2?orgId=1&filter=A');
});
it('Can getURL without shareView param', async () => {
const url = getDashboardUrl({
uid: 'dash-1',
currentQueryParams: '?orgId=1&filter=A&shareView=link',
});
expect(url).toBe('/d/dash-1?orgId=1&filter=A');
});
it('Can getUrl with params removed and added', () => {
const url = getDashboardUrl({
uid: 'dash-1',
currentQueryParams: '?orgId=1&filter=A',
updateQuery: { filter: null, new: 'A' },
});
expect(url).toBe('/d/dash-1?orgId=1&new=A');
});
it('Empty uid should be treated as a new dashboard', () => {
const url = getDashboardUrl({
uid: '',
currentQueryParams: '?orgId=1&filter=A',
});
expect(url).toBe('/dashboard/new?orgId=1&filter=A');
});
});