| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- import config from 'app/core/config';
- import { LinkSrv } from 'app/features/panel/panellinks/link_srv';
- import { ShareModalCtrl } from './ShareModalCtrl';
- import { TemplateSrv } from 'app/features/templating/template_srv';
- describe('ShareModalCtrl', () => {
- const ctx = {
- timeSrv: {
- timeRange: () => {
- return { from: new Date(1000), to: new Date(2000) };
- },
- },
- $location: {
- absUrl: () => 'http://server/#!/test',
- search: () => {
- return { from: '', to: '' };
- },
- },
- scope: {
- dashboard: {
- meta: {
- isSnapshot: true,
- },
- },
- },
- templateSrv: {
- fillVariableValuesForUrl: () => {},
- },
- } as any;
- (window as any).Intl.DateTimeFormat = () => {
- return {
- resolvedOptions: () => {
- return { timeZone: 'UTC' };
- },
- };
- };
- beforeEach(() => {
- config.bootData = {
- user: {
- orgId: 1,
- },
- };
- // @ts-ignore
- ctx.ctrl = new ShareModalCtrl(
- ctx.scope,
- {},
- ctx.$location,
- {},
- ctx.timeSrv,
- ctx.templateSrv,
- new LinkSrv({} as TemplateSrv, ctx.stimeSrv)
- );
- });
- describe('shareUrl with current time range and panel', () => {
- it('should generate share url absolute time', () => {
- ctx.scope.panel = { id: 22 };
- ctx.scope.init();
- expect(ctx.scope.shareUrl).toBe('http://server/#!/test?from=1000&to=2000&orgId=1&panelId=22&fullscreen');
- });
- it('should generate render url', () => {
- ctx.$location.absUrl = () => 'http://dashboards.grafana.com/d/abcdefghi/my-dash';
- ctx.scope.panel = { id: 22 };
- ctx.scope.init();
- const base = 'http://dashboards.grafana.com/render/d-solo/abcdefghi/my-dash';
- const params = '?from=1000&to=2000&orgId=1&panelId=22&width=1000&height=500&tz=UTC';
- expect(ctx.scope.imageUrl).toContain(base + params);
- });
- it('should generate render url for scripted dashboard', () => {
- ctx.$location.absUrl = () => 'http://dashboards.grafana.com/dashboard/script/my-dash.js';
- ctx.scope.panel = { id: 22 };
- ctx.scope.init();
- const base = 'http://dashboards.grafana.com/render/dashboard-solo/script/my-dash.js';
- const params = '?from=1000&to=2000&orgId=1&panelId=22&width=1000&height=500&tz=UTC';
- expect(ctx.scope.imageUrl).toContain(base + params);
- });
- it('should remove panel id when no panel in scope', () => {
- ctx.$location.absUrl = () => 'http://server/#!/test';
- ctx.scope.options.forCurrent = true;
- ctx.scope.panel = null;
- ctx.scope.init();
- expect(ctx.scope.shareUrl).toBe('http://server/#!/test?from=1000&to=2000&orgId=1');
- });
- it('should add theme when specified', () => {
- ctx.scope.options.theme = 'light';
- ctx.scope.panel = null;
- ctx.scope.init();
- expect(ctx.scope.shareUrl).toBe('http://server/#!/test?from=1000&to=2000&orgId=1&theme=light');
- });
- it('should remove fullscreen from image url when is first param in querystring and modeSharePanel is true', () => {
- ctx.$location.search = () => {
- return { fullscreen: true, edit: true };
- };
- ctx.$location.absUrl = () => 'http://server/#!/test?fullscreen&edit';
- ctx.scope.modeSharePanel = true;
- ctx.scope.panel = { id: 1 };
- ctx.scope.buildUrl();
- expect(ctx.scope.shareUrl).toContain('?fullscreen&edit&from=1000&to=2000&orgId=1&panelId=1');
- expect(ctx.scope.imageUrl).toContain('?from=1000&to=2000&orgId=1&panelId=1&width=1000&height=500&tz=UTC');
- });
- it('should remove edit from image url when is first param in querystring and modeSharePanel is true', () => {
- ctx.$location.search = () => {
- return { edit: true, fullscreen: true };
- };
- ctx.$location.absUrl = () => 'http://server/#!/test?edit&fullscreen';
- ctx.scope.modeSharePanel = true;
- ctx.scope.panel = { id: 1 };
- ctx.scope.buildUrl();
- expect(ctx.scope.shareUrl).toContain('?edit&fullscreen&from=1000&to=2000&orgId=1&panelId=1');
- expect(ctx.scope.imageUrl).toContain('?from=1000&to=2000&orgId=1&panelId=1&width=1000&height=500&tz=UTC');
- });
- it('should include template variables in url', () => {
- ctx.$location.search = () => {
- return {};
- };
- ctx.$location.absUrl = () => 'http://server/#!/test';
- ctx.scope.options.includeTemplateVars = true;
- ctx.templateSrv.fillVariableValuesForUrl = (params: any) => {
- params['var-app'] = 'mupp';
- params['var-server'] = 'srv-01';
- };
- ctx.scope.buildUrl();
- expect(ctx.scope.shareUrl).toContain(
- 'http://server/#!/test?from=1000&to=2000&orgId=1&var-app=mupp&var-server=srv-01'
- );
- });
- });
- });
|