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

* 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
This commit is contained in:
Ashley Harrison 2021-06-11 16:20:18 +01:00 committed by GitHub
parent 7109285ac9
commit 60f79a3548
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 8 deletions

View File

@ -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');

View File

@ -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,
});