mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Make zoom and time shift work after emmitter change (#22051)
This commit is contained in:
parent
34b52cb835
commit
31101d54a4
@ -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(),
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user