Make zoom and time shift work after emmitter change (#22051)

This commit is contained in:
Dominik Prokop 2020-02-09 19:19:44 +01:00 committed by GitHub
parent 34b52cb835
commit 31101d54a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 4 deletions

View File

@ -2,6 +2,12 @@ import { TimeSrv } from './TimeSrv';
import { ContextSrvStub } from 'test/specs/helpers';
import { isDateTime, dateTime } from '@grafana/data';
jest.mock('app/core/core', () => ({
appEvents: {
on: () => {},
},
}));
describe('timeSrv', () => {
const rootScope = {
$on: jest.fn(),

View File

@ -19,6 +19,8 @@ import { ContextSrv } from 'app/core/services/context_srv';
import { DashboardModel } from '../state/DashboardModel';
import { GrafanaRootScope } from 'app/routes/GrafanaCtrl';
import { getZoomedTimeRange, getShiftedTimeRange } from 'app/core/utils/timePicker';
import { appEvents } from '../../../core/core';
import { CoreEvents } from '../../../types';
export class TimeSrv {
time: any;
@ -40,8 +42,8 @@ export class TimeSrv {
// default time
this.time = DefaultTimeRange.raw;
$rootScope.$on('zoom-out', this.zoomOut.bind(this));
$rootScope.$on('shift-time', this.shiftTime.bind(this));
appEvents.on(CoreEvents.zoomOut, this.zoomOut.bind(this));
appEvents.on(CoreEvents.shiftTime, this.shiftTime.bind(this));
$rootScope.$on('$routeUpdate', this.routeUpdated.bind(this));
document.addEventListener('visibilitychange', () => {
@ -266,14 +268,14 @@ export class TimeSrv {
};
}
zoomOut(e: any, factor: number) {
zoomOut(factor: number) {
const range = this.timeRange();
const { from, to } = getZoomedTimeRange(range, factor);
this.setTime({ from: toUtc(from), to: toUtc(to) });
}
shiftTime(e: any, direction: number) {
shiftTime(direction: number) {
const range = this.timeRange();
const { from, to } = getShiftedTimeRange(direction, range);

View File

@ -10,6 +10,11 @@ jest.mock('angular', () => {
const AngularJSMock = require('test/mocks/angular');
return new AngularJSMock();
});
jest.mock('app/core/core', () => ({
appEvents: {
on: () => {},
},
}));
const dataPointMock = {
seriesName: 'A-series',