mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Addedd assertions about raw time range when panel time overriden
This commit is contained in:
parent
c3fdc1a0fb
commit
7289e6e500
@ -33,6 +33,8 @@ describe('applyPanelTimeOverrides', () => {
|
|||||||
|
|
||||||
expect(overrides.timeRange.from.toISOString()).toBe(moment([2019, 1, 11, 12]).toISOString());
|
expect(overrides.timeRange.from.toISOString()).toBe(moment([2019, 1, 11, 12]).toISOString());
|
||||||
expect(overrides.timeRange.to.toISOString()).toBe(fakeCurrentDate.toISOString());
|
expect(overrides.timeRange.to.toISOString()).toBe(fakeCurrentDate.toISOString());
|
||||||
|
expect(overrides.timeRange.raw.from).toBe('now-2h');
|
||||||
|
expect(overrides.timeRange.raw.to).toBe('now');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should apply time shift', () => {
|
it('should apply time shift', () => {
|
||||||
@ -48,6 +50,8 @@ describe('applyPanelTimeOverrides', () => {
|
|||||||
|
|
||||||
expect(overrides.timeRange.from.toISOString()).toBe(expectedFromDate.toISOString());
|
expect(overrides.timeRange.from.toISOString()).toBe(expectedFromDate.toISOString());
|
||||||
expect(overrides.timeRange.to.toISOString()).toBe(expectedToDate.toISOString());
|
expect(overrides.timeRange.to.toISOString()).toBe(expectedToDate.toISOString());
|
||||||
|
expect((overrides.timeRange.raw.from as moment.Moment).toISOString()).toEqual(expectedFromDate.toISOString());
|
||||||
|
expect((overrides.timeRange.raw.to as moment.Moment).toISOString()).toEqual(expectedToDate.toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should apply both relative time and time shift', () => {
|
it('should apply both relative time and time shift', () => {
|
||||||
@ -64,5 +68,7 @@ describe('applyPanelTimeOverrides', () => {
|
|||||||
|
|
||||||
expect(overrides.timeRange.from.toISOString()).toBe(expectedFromDate.toISOString());
|
expect(overrides.timeRange.from.toISOString()).toBe(expectedFromDate.toISOString());
|
||||||
expect(overrides.timeRange.to.toISOString()).toBe(expectedToDate.toISOString());
|
expect(overrides.timeRange.to.toISOString()).toBe(expectedToDate.toISOString());
|
||||||
|
expect((overrides.timeRange.raw.from as moment.Moment).toISOString()).toEqual(expectedFromDate.toISOString());
|
||||||
|
expect((overrides.timeRange.raw.to as moment.Moment).toISOString()).toEqual(expectedToDate.toISOString());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -142,10 +142,16 @@ export function applyPanelTimeOverrides(panel: PanelModel, timeRange: TimeRange)
|
|||||||
|
|
||||||
const timeShift = '-' + timeShiftInterpolated;
|
const timeShift = '-' + timeShiftInterpolated;
|
||||||
newTimeData.timeInfo += ' timeshift ' + timeShift;
|
newTimeData.timeInfo += ' timeshift ' + timeShift;
|
||||||
|
const from = dateMath.parseDateMath(timeShift, newTimeData.timeRange.from, false);
|
||||||
|
const to = dateMath.parseDateMath(timeShift, newTimeData.timeRange.to, true);
|
||||||
|
|
||||||
newTimeData.timeRange = {
|
newTimeData.timeRange = {
|
||||||
from: dateMath.parseDateMath(timeShift, newTimeData.timeRange.from, false),
|
from,
|
||||||
to: dateMath.parseDateMath(timeShift, newTimeData.timeRange.to, true),
|
to,
|
||||||
raw: newTimeData.timeRange.raw,
|
raw: {
|
||||||
|
from,
|
||||||
|
to,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user