mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
add tests for api urls (#54116)
Create function for generating api urls and add tests
This commit is contained in:
@@ -5,6 +5,8 @@ import {
|
|||||||
dashboardHasTemplateVariables,
|
dashboardHasTemplateVariables,
|
||||||
generatePublicDashboardUrl,
|
generatePublicDashboardUrl,
|
||||||
publicDashboardPersisted,
|
publicDashboardPersisted,
|
||||||
|
getPublicDashboardConfigUrl,
|
||||||
|
savePublicDashboardConfigUrl,
|
||||||
} from './SharePublicDashboardUtils';
|
} from './SharePublicDashboardUtils';
|
||||||
|
|
||||||
describe('dashboardHasTemplateVariables', () => {
|
describe('dashboardHasTemplateVariables', () => {
|
||||||
@@ -40,3 +42,15 @@ describe('publicDashboardPersisted', () => {
|
|||||||
expect(publicDashboardPersisted(pubdash)).toBe(false);
|
expect(publicDashboardPersisted(pubdash)).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getPublicDashboardConfigUrl', () => {
|
||||||
|
it('builds the correct url', () => {
|
||||||
|
expect(getPublicDashboardConfigUrl('abc1234')).toEqual('/api/dashboards/uid/abc1234/public-config');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('savePublicDashboardConfigUrl', () => {
|
||||||
|
it('builds the correct url', () => {
|
||||||
|
expect(savePublicDashboardConfigUrl('abc1234')).toEqual('/api/dashboards/uid/abc1234/public-config');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ export const getPublicDashboardConfig = async (
|
|||||||
dashboardUid: string,
|
dashboardUid: string,
|
||||||
setPublicDashboard: React.Dispatch<React.SetStateAction<PublicDashboard>>
|
setPublicDashboard: React.Dispatch<React.SetStateAction<PublicDashboard>>
|
||||||
) => {
|
) => {
|
||||||
const url = `/api/dashboards/uid/${dashboardUid}/public-config`;
|
const pdResp: PublicDashboard = await getBackendSrv().get(getPublicDashboardConfigUrl(dashboardUid));
|
||||||
const pdResp: PublicDashboard = await getBackendSrv().get(url);
|
|
||||||
setPublicDashboard(pdResp);
|
setPublicDashboard(pdResp);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -32,8 +31,10 @@ export const savePublicDashboardConfig = async (
|
|||||||
publicDashboardConfig: PublicDashboard,
|
publicDashboardConfig: PublicDashboard,
|
||||||
setPublicDashboard: React.Dispatch<React.SetStateAction<PublicDashboard>>
|
setPublicDashboard: React.Dispatch<React.SetStateAction<PublicDashboard>>
|
||||||
) => {
|
) => {
|
||||||
const url = `/api/dashboards/uid/${dashboardUid}/public-config`;
|
const pdResp: PublicDashboard = await getBackendSrv().post(
|
||||||
const pdResp: PublicDashboard = await getBackendSrv().post(url, publicDashboardConfig);
|
savePublicDashboardConfigUrl(dashboardUid),
|
||||||
|
publicDashboardConfig
|
||||||
|
);
|
||||||
|
|
||||||
// Never allow a user to send the orgId
|
// Never allow a user to send the orgId
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -43,6 +44,14 @@ export const savePublicDashboardConfig = async (
|
|||||||
setPublicDashboard(pdResp);
|
setPublicDashboard(pdResp);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getPublicDashboardConfigUrl = (dashboardUid: string) => {
|
||||||
|
return `/api/dashboards/uid/${dashboardUid}/public-config`;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const savePublicDashboardConfigUrl = (dashboardUid: string) => {
|
||||||
|
return `/api/dashboards/uid/${dashboardUid}/public-config`;
|
||||||
|
};
|
||||||
|
|
||||||
// Instance methods
|
// Instance methods
|
||||||
export const dashboardHasTemplateVariables = (variables: VariableModel[]): boolean => {
|
export const dashboardHasTemplateVariables = (variables: VariableModel[]): boolean => {
|
||||||
return variables.length > 0;
|
return variables.length > 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user