grafana/public/app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboardUtils.test.tsx
juanicabanas c7419de2e5
PublicDashboard: Add RTK Query with loading and error state. Add MSW dependency for testing. (#55518)
PublicDashboard: Add RTK Query with loading and error state. Add MSW dependency for testing.
2022-09-22 09:35:04 -03:00

48 lines
1.4 KiB
TypeScript

import { updateConfig } from 'app/core/config';
import { VariableModel } from 'app/features/variables/types';
import {
PublicDashboard,
dashboardHasTemplateVariables,
generatePublicDashboardUrl,
publicDashboardPersisted,
} from './SharePublicDashboardUtils';
describe('dashboardHasTemplateVariables', () => {
it('false', () => {
let variables: VariableModel[] = [];
expect(dashboardHasTemplateVariables(variables)).toBe(false);
});
it('true', () => {
//@ts-ignore
let variables: VariableModel[] = ['a'];
expect(dashboardHasTemplateVariables(variables)).toBe(true);
});
});
describe('generatePublicDashboardUrl', () => {
it('uses the grafana config appUrl to generate the url', () => {
const appUrl = 'http://localhost/';
const accessToken = 'abcd1234';
updateConfig({ appUrl });
let pubdash = { accessToken } as PublicDashboard;
expect(generatePublicDashboardUrl(pubdash)).toEqual(`${appUrl}public-dashboards/${accessToken}`);
});
});
describe('publicDashboardPersisted', () => {
it('true', () => {
let pubdash = { uid: 'abcd1234' } as PublicDashboard;
expect(publicDashboardPersisted(pubdash)).toBe(true);
});
it('false', () => {
let pubdash = { uid: '' } as PublicDashboard;
expect(publicDashboardPersisted(pubdash)).toBe(false);
pubdash = {} as PublicDashboard;
expect(publicDashboardPersisted(pubdash)).toBe(false);
});
});