|
|
|
@ -8,7 +8,8 @@ import { afterEach, beforeEach } from '../../../../test/lib/common'; |
|
|
|
|
function getTestContext({ |
|
|
|
|
usePanelInEdit, |
|
|
|
|
usePanelInView, |
|
|
|
|
}: { usePanelInEdit?: boolean; usePanelInView?: boolean } = {}) { |
|
|
|
|
refreshAll = false, |
|
|
|
|
}: { usePanelInEdit?: boolean; usePanelInView?: boolean; refreshAll?: boolean } = {}) { |
|
|
|
|
jest.clearAllMocks(); |
|
|
|
|
|
|
|
|
|
const dashboard = new DashboardModel({}); |
|
|
|
@ -26,7 +27,7 @@ function getTestContext({ |
|
|
|
|
panelIds.push(panelInView.id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
appEvents.publish(new VariablesChanged({ panelIds })); |
|
|
|
|
appEvents.publish(new VariablesChanged({ panelIds, refreshAll })); |
|
|
|
|
|
|
|
|
|
return { dashboard, startRefreshMock, panelInEdit, panelInView }; |
|
|
|
|
} |
|
|
|
@ -37,7 +38,16 @@ describe('Strict panel refresh', () => { |
|
|
|
|
const { startRefreshMock } = getTestContext(); |
|
|
|
|
|
|
|
|
|
expect(startRefreshMock).toHaveBeenCalledTimes(1); |
|
|
|
|
expect(startRefreshMock).toHaveBeenLastCalledWith([1, 2, 3]); |
|
|
|
|
expect(startRefreshMock).toHaveBeenLastCalledWith({ panelIds: [1, 2, 3], refreshAll: false }); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('when there is no panel in full view or panel in panel edit during variable change but refreshAll is true', () => { |
|
|
|
|
it('then all affected panels should be refreshed', () => { |
|
|
|
|
const { startRefreshMock } = getTestContext({ refreshAll: true }); |
|
|
|
|
|
|
|
|
|
expect(startRefreshMock).toHaveBeenCalledTimes(1); |
|
|
|
|
expect(startRefreshMock).toHaveBeenLastCalledWith({ panelIds: [], refreshAll: true }); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -61,7 +71,7 @@ describe('Strict panel refresh', () => { |
|
|
|
|
const { startRefreshMock } = getTestContext(); |
|
|
|
|
|
|
|
|
|
expect(startRefreshMock).toHaveBeenCalledTimes(1); |
|
|
|
|
expect(startRefreshMock).toHaveBeenLastCalledWith(undefined); |
|
|
|
|
expect(startRefreshMock).toHaveBeenLastCalledWith({ panelIds: [], refreshAll: true }); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -71,7 +81,17 @@ describe('Strict panel refresh', () => { |
|
|
|
|
const { startRefreshMock } = getTestContext(); |
|
|
|
|
|
|
|
|
|
expect(startRefreshMock).toHaveBeenCalledTimes(1); |
|
|
|
|
expect(startRefreshMock).toHaveBeenLastCalledWith([1, 2, 3]); |
|
|
|
|
expect(startRefreshMock).toHaveBeenLastCalledWith({ panelIds: [1, 2, 3], refreshAll: false }); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('when the dashboard has been refreshed within the threshold but refreshAll is true', () => { |
|
|
|
|
it('then all affected panels should be refreshed', () => { |
|
|
|
|
isRefreshOutsideThreshold = false; |
|
|
|
|
const { startRefreshMock } = getTestContext({ refreshAll: true }); |
|
|
|
|
|
|
|
|
|
expect(startRefreshMock).toHaveBeenCalledTimes(1); |
|
|
|
|
expect(startRefreshMock).toHaveBeenLastCalledWith({ panelIds: [], refreshAll: true }); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
@ -81,7 +101,7 @@ describe('Strict panel refresh', () => { |
|
|
|
|
const { panelInView, startRefreshMock } = getTestContext({ usePanelInView: true }); |
|
|
|
|
|
|
|
|
|
expect(startRefreshMock).toHaveBeenCalledTimes(1); |
|
|
|
|
expect(startRefreshMock).toHaveBeenLastCalledWith([1, 2, 3, panelInView.id]); |
|
|
|
|
expect(startRefreshMock).toHaveBeenLastCalledWith({ panelIds: [1, 2, 3, panelInView.id], refreshAll: false }); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('and when exitViewPanel is called', () => { |
|
|
|
@ -92,7 +112,7 @@ describe('Strict panel refresh', () => { |
|
|
|
|
dashboard.exitViewPanel(panelInView); |
|
|
|
|
|
|
|
|
|
expect(startRefreshMock).toHaveBeenCalledTimes(1); |
|
|
|
|
expect(startRefreshMock).toHaveBeenLastCalledWith([1, 2, 3]); |
|
|
|
|
expect(startRefreshMock).toHaveBeenLastCalledWith({ panelIds: [1, 2, 3], refreshAll: false }); |
|
|
|
|
expect(dashboard['panelsAffectedByVariableChange']).toBeNull(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
@ -102,7 +122,7 @@ describe('Strict panel refresh', () => { |
|
|
|
|
it('then all affected panels should be refreshed', () => { |
|
|
|
|
const { panelInEdit, startRefreshMock } = getTestContext({ usePanelInEdit: true }); |
|
|
|
|
expect(startRefreshMock).toHaveBeenCalledTimes(1); |
|
|
|
|
expect(startRefreshMock).toHaveBeenLastCalledWith([1, 2, 3, panelInEdit.id]); |
|
|
|
|
expect(startRefreshMock).toHaveBeenLastCalledWith({ panelIds: [1, 2, 3, panelInEdit.id], refreshAll: false }); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('and when exitViewPanel is called', () => { |
|
|
|
@ -113,7 +133,7 @@ describe('Strict panel refresh', () => { |
|
|
|
|
dashboard.exitPanelEditor(); |
|
|
|
|
|
|
|
|
|
expect(startRefreshMock).toHaveBeenCalledTimes(1); |
|
|
|
|
expect(startRefreshMock).toHaveBeenLastCalledWith([1, 2, 3]); |
|
|
|
|
expect(startRefreshMock).toHaveBeenLastCalledWith({ panelIds: [1, 2, 3], refreshAll: false }); |
|
|
|
|
expect(dashboard['panelsAffectedByVariableChange']).toBeNull(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|