TimeSrv: Refactor service to have no dependency on angular (#32562)

* TimeSrv: Refactor service to have no dependency on angular

* Fixing reference to function that does not exist

* fixing tests

* Worked around the strange error
This commit is contained in:
Torkel Ödegaard
2021-04-01 06:33:11 +02:00
committed by GitHub
parent 1399b49c16
commit 6fa7c6b206
18 changed files with 93 additions and 112 deletions

View File

@@ -24,7 +24,7 @@ import {
VariableSuggestion,
VariableSuggestionsScope,
} from '@grafana/data';
import { getAllVariableValuesForUrl } from '../../variables/getAllVariableValuesForUrl';
import { getVariablesUrlParams } from '../../variables/getAllVariableValuesForUrl';
const timeRangeVars = [
{
@@ -280,7 +280,7 @@ export class LinkSrv implements LinkService {
if (link.includeVars) {
params = {
...params,
...getAllVariableValuesForUrl(),
...getVariablesUrlParams(),
};
}

View File

@@ -19,19 +19,13 @@ describe('linkSrv', () => {
let templateSrv: TemplateSrv;
function initLinkSrv() {
const timer = {
register: jest.fn(),
cancel: jest.fn(),
cancelAll: jest.fn(),
};
const _dashboard: any = {
time: { from: 'now-6h', to: 'now' },
getTimezone: jest.fn(() => 'browser'),
timeRangeUpdated: () => {},
};
const timeSrv = new TimeSrv(jest.fn() as any, timer, {} as any);
const timeSrv = new TimeSrv({} as any);
timeSrv.init(_dashboard);
timeSrv.setTime({ from: 'now-1h', to: 'now' });
_dashboard.refresh = false;
@@ -126,10 +120,8 @@ describe('linkSrv', () => {
({ url, appSubUrl, expected }) => {
locationUtil.initialize({
config: { appSubUrl } as any,
// @ts-ignore
buildParamsFromVariables: () => {},
// @ts-ignore
getTimeRangeForUrl: () => {},
getVariablesUrlParams: (() => {}) as any,
getTimeRangeForUrl: (() => {}) as any,
});
const link = linkSrv.getDataLinkUIModel(