Dashboard: handle the case where refresh_intervals could be null (#35511) (#35579)

* handle the case where refresh_intervals === null + add unit test

* have a clean _dashboard for each test

* modify check to see if refresh_intervals is an array

(cherry picked from commit 60f79a3548)

Co-authored-by: Ashley Harrison <ashharrison90@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2021-06-11 17:45:32 +02:00
committed by GitHub
co-authored by Ashley Harrison
parent 906af3bf4b
commit b4e30f1bd3
2 changed files with 21 additions and 8 deletions
@@ -11,17 +11,17 @@ jest.mock('app/core/core', () => ({
describe('timeSrv', () => {
let timeSrv: TimeSrv;
const _dashboard: any = {
time: { from: 'now-6h', to: 'now' },
getTimezone: jest.fn(() => 'browser'),
timeRangeUpdated: jest.fn(() => {}),
};
let _dashboard: any;
beforeEach(() => {
_dashboard = {
time: { from: 'now-6h', to: 'now' },
getTimezone: jest.fn(() => 'browser'),
refresh: false,
timeRangeUpdated: jest.fn(() => {}),
};
timeSrv = new TimeSrv(new ContextSrvStub() as any);
timeSrv.init(_dashboard);
_dashboard.refresh = false;
});
describe('timeRange', () => {
@@ -130,6 +130,17 @@ describe('timeSrv', () => {
expect(timeSrv.time.to).toEqual('now');
});
it('should handle refresh_intervals=null when refresh is enabled', () => {
locationService.push('/d/id?refresh=30s');
timeSrv = new TimeSrv(new ContextSrvStub() as any);
_dashboard.timepicker = {
refresh_intervals: null,
};
expect(() => timeSrv.init(_dashboard)).not.toThrow();
});
describe('data point windowing', () => {
it('handles time window specfied as interval string', () => {
locationService.push('/d/id?time=1410337645000&time.window=10s');
@@ -156,7 +156,9 @@ export class TimeSrv {
this.refresh = getRefreshFromUrl({
params: paramsJSON,
currentRefresh: this.refresh,
refreshIntervals: this.dashboard?.timepicker?.refresh_intervals,
refreshIntervals: Array.isArray(this.dashboard?.timepicker?.refresh_intervals)
? this.dashboard?.timepicker?.refresh_intervals
: undefined,
isAllowedIntervalFn: this.contextSrv.isAllowedInterval,
minRefreshInterval: config.minRefreshInterval,
});