|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
import { keys as _keys } from 'lodash'; |
|
|
|
|
|
|
|
|
|
import { VariableHide } from '@grafana/data'; |
|
|
|
|
import { dateTime, TimeRange, VariableHide } from '@grafana/data'; |
|
|
|
|
import { defaultVariableModel } from '@grafana/schema'; |
|
|
|
|
import { contextSrv } from 'app/core/services/context_srv'; |
|
|
|
|
|
|
|
|
@ -1158,8 +1158,35 @@ describe('exitViewPanel', () => { |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('exitPanelEditor', () => { |
|
|
|
|
function getTestContext(pauseAutoRefresh = false) { |
|
|
|
|
describe('when initEditPanel is called', () => { |
|
|
|
|
function getTestContext() { |
|
|
|
|
const dashboard = createDashboardModelFixture(); |
|
|
|
|
const timeSrvMock = { |
|
|
|
|
pauseAutoRefresh: jest.fn(), |
|
|
|
|
resumeAutoRefresh: jest.fn(), |
|
|
|
|
stopAutoRefresh: jest.fn(), |
|
|
|
|
} as unknown as TimeSrv; |
|
|
|
|
setTimeSrv(timeSrvMock); |
|
|
|
|
return { dashboard, timeSrvMock }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
it('should set panelInEdit', () => { |
|
|
|
|
const { dashboard } = getTestContext(); |
|
|
|
|
dashboard.addPanel({ type: 'timeseries' }); |
|
|
|
|
dashboard.initEditPanel(dashboard.panels[0]); |
|
|
|
|
expect(dashboard.panelInEdit).not.toBeUndefined(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should stop auto-refresh', () => { |
|
|
|
|
const { dashboard, timeSrvMock } = getTestContext(); |
|
|
|
|
dashboard.addPanel({ type: 'timeseries' }); |
|
|
|
|
dashboard.initEditPanel(dashboard.panels[0]); |
|
|
|
|
expect(timeSrvMock.stopAutoRefresh).toHaveBeenCalled(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('when exitPanelEditor is called', () => { |
|
|
|
|
function getTestContext() { |
|
|
|
|
const panel = new PanelModel({ destroy: jest.fn() }); |
|
|
|
|
const dashboard = createDashboardModelFixture(); |
|
|
|
|
const timeSrvMock = { |
|
|
|
@ -1169,70 +1196,54 @@ describe('exitPanelEditor', () => { |
|
|
|
|
} as unknown as TimeSrv; |
|
|
|
|
dashboard.startRefresh = jest.fn(); |
|
|
|
|
dashboard.panelInEdit = panel; |
|
|
|
|
if (pauseAutoRefresh) { |
|
|
|
|
timeSrvMock.autoRefreshPaused = true; |
|
|
|
|
} |
|
|
|
|
setTimeSrv(timeSrvMock); |
|
|
|
|
return { dashboard, panel, timeSrvMock }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
describe('when called', () => { |
|
|
|
|
it('then panelInEdit is set to undefined', () => { |
|
|
|
|
const { dashboard } = getTestContext(); |
|
|
|
|
|
|
|
|
|
dashboard.exitPanelEditor(); |
|
|
|
|
it('should set panelInEdit to undefined', () => { |
|
|
|
|
const { dashboard } = getTestContext(); |
|
|
|
|
|
|
|
|
|
expect(dashboard.panelInEdit).toBeUndefined(); |
|
|
|
|
}); |
|
|
|
|
dashboard.exitPanelEditor(); |
|
|
|
|
|
|
|
|
|
it('then destroy is called on panel', () => { |
|
|
|
|
const { dashboard, panel } = getTestContext(); |
|
|
|
|
expect(dashboard.panelInEdit).toBeUndefined(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
dashboard.exitPanelEditor(); |
|
|
|
|
it('should destroy panel', () => { |
|
|
|
|
const { dashboard, panel } = getTestContext(); |
|
|
|
|
|
|
|
|
|
expect(panel.destroy).toHaveBeenCalled(); |
|
|
|
|
}); |
|
|
|
|
dashboard.exitPanelEditor(); |
|
|
|
|
|
|
|
|
|
it('then startRefresh is not called', () => { |
|
|
|
|
const { dashboard } = getTestContext(); |
|
|
|
|
expect(panel.destroy).toHaveBeenCalled(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
dashboard.exitPanelEditor(); |
|
|
|
|
it('should not call startRefresh', () => { |
|
|
|
|
const { dashboard } = getTestContext(); |
|
|
|
|
|
|
|
|
|
expect(dashboard.startRefresh).not.toHaveBeenCalled(); |
|
|
|
|
}); |
|
|
|
|
dashboard.exitPanelEditor(); |
|
|
|
|
|
|
|
|
|
it('then auto refresh property is resumed', () => { |
|
|
|
|
const { dashboard, timeSrvMock } = getTestContext(true); |
|
|
|
|
dashboard.exitPanelEditor(); |
|
|
|
|
expect(timeSrvMock.resumeAutoRefresh).toHaveBeenCalled(); |
|
|
|
|
}); |
|
|
|
|
expect(dashboard.startRefresh).not.toHaveBeenCalled(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('initEditPanel', () => { |
|
|
|
|
function getTestContext() { |
|
|
|
|
const dashboard = createDashboardModelFixture(); |
|
|
|
|
const timeSrvMock = { |
|
|
|
|
pauseAutoRefresh: jest.fn(), |
|
|
|
|
resumeAutoRefresh: jest.fn(), |
|
|
|
|
} as unknown as TimeSrv; |
|
|
|
|
setTimeSrv(timeSrvMock); |
|
|
|
|
return { dashboard, timeSrvMock }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
describe('when called', () => { |
|
|
|
|
it('then panelInEdit is not undefined', () => { |
|
|
|
|
const { dashboard } = getTestContext(); |
|
|
|
|
dashboard.addPanel({ type: 'timeseries' }); |
|
|
|
|
dashboard.initEditPanel(dashboard.panels[0]); |
|
|
|
|
expect(dashboard.panelInEdit).not.toBeUndefined(); |
|
|
|
|
}); |
|
|
|
|
it('should call startRefresh if time range changed during edit', () => { |
|
|
|
|
const { dashboard } = getTestContext(); |
|
|
|
|
|
|
|
|
|
const range: TimeRange = { |
|
|
|
|
from: dateTime(new Date().getTime()).subtract(1, 'minutes'), |
|
|
|
|
to: dateTime(new Date().getTime()), |
|
|
|
|
raw: { |
|
|
|
|
from: 'now-1m', |
|
|
|
|
to: 'now', |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
dashboard.timeRangeUpdated(range); |
|
|
|
|
dashboard.exitPanelEditor(); |
|
|
|
|
|
|
|
|
|
expect(dashboard.startRefresh).toHaveBeenCalled(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('then auto-refresh is paused', () => { |
|
|
|
|
const { dashboard, timeSrvMock } = getTestContext(); |
|
|
|
|
dashboard.addPanel({ type: 'timeseries' }); |
|
|
|
|
dashboard.initEditPanel(dashboard.panels[0]); |
|
|
|
|
expect(timeSrvMock.pauseAutoRefresh).toHaveBeenCalled(); |
|
|
|
|
}); |
|
|
|
|
it('then auto refresh property is resumed', () => { |
|
|
|
|
const { dashboard, timeSrvMock } = getTestContext(); |
|
|
|
|
dashboard.exitPanelEditor(); |
|
|
|
|
expect(timeSrvMock.resumeAutoRefresh).toHaveBeenCalled(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|