mirror of https://github.com/grafana/grafana
Fix problem with adhoc variable filters not handled. Fix problem with saving variables and time per default when saving a dashboard as/first time. Fix updating dashboard model after save with saving time/variables enabled so that next time you save you won't get checkboxes for save time/variables unless any values changed. Tests validating correctness if time/variable values has changed.pull/12350/head
parent
3a9a36d6cf
commit
41ac8d4cd5
@ -1,128 +1,57 @@ |
|||||||
import { SaveDashboardModalCtrl } from '../save_modal'; |
import { SaveDashboardModalCtrl } from '../save_modal'; |
||||||
|
|
||||||
jest.mock('app/core/services/context_srv', () => ({})); |
const setup = (timeChanged, variableValuesChanged, cb) => { |
||||||
|
const dash = { |
||||||
|
hasTimeChanged: jest.fn().mockReturnValue(timeChanged), |
||||||
|
hasVariableValuesChanged: jest.fn().mockReturnValue(variableValuesChanged), |
||||||
|
resetOriginalTime: jest.fn(), |
||||||
|
resetOriginalVariables: jest.fn(), |
||||||
|
getSaveModelClone: jest.fn().mockReturnValue({}), |
||||||
|
}; |
||||||
|
const dashboardSrvMock = { |
||||||
|
getCurrent: jest.fn().mockReturnValue(dash), |
||||||
|
save: jest.fn().mockReturnValue(Promise.resolve()), |
||||||
|
}; |
||||||
|
const ctrl = new SaveDashboardModalCtrl(dashboardSrvMock); |
||||||
|
ctrl.saveForm = { |
||||||
|
$valid: true, |
||||||
|
}; |
||||||
|
ctrl.dismiss = () => Promise.resolve(); |
||||||
|
cb(dash, ctrl, dashboardSrvMock); |
||||||
|
}; |
||||||
|
|
||||||
describe('SaveDashboardModal', () => { |
describe('SaveDashboardModal', () => { |
||||||
describe('save modal checkboxes', () => { |
describe('Given time and template variable values have not changed', () => { |
||||||
it('should show checkboxes', () => { |
setup(false, false, (dash, ctrl: SaveDashboardModalCtrl) => { |
||||||
let fakeDashboardSrv = { |
it('When creating ctrl should set time and template variable values changed', () => { |
||||||
dash: { |
expect(ctrl.timeChange).toBeFalsy(); |
||||||
templating: { |
expect(ctrl.variableValueChange).toBeFalsy(); |
||||||
list: [ |
}); |
||||||
{ |
|
||||||
current: { |
|
||||||
selected: true, |
|
||||||
tags: Array(0), |
|
||||||
text: 'server_001', |
|
||||||
value: 'server_001', |
|
||||||
}, |
|
||||||
name: 'Server', |
|
||||||
}, |
|
||||||
], |
|
||||||
}, |
|
||||||
originalTemplating: [ |
|
||||||
{ |
|
||||||
current: { |
|
||||||
selected: true, |
|
||||||
text: 'server_002', |
|
||||||
value: 'server_002', |
|
||||||
}, |
|
||||||
name: 'Server', |
|
||||||
}, |
|
||||||
], |
|
||||||
time: { |
|
||||||
from: 'now-3h', |
|
||||||
to: 'now', |
|
||||||
}, |
|
||||||
originalTime: { |
|
||||||
from: 'now-6h', |
|
||||||
to: 'now', |
|
||||||
}, |
|
||||||
}, |
|
||||||
}; |
|
||||||
let modal = new SaveDashboardModalCtrl(fakeDashboardSrv); |
|
||||||
|
|
||||||
expect(modal.timeChange).toBe(true); |
|
||||||
expect(modal.variableValueChange).toBe(true); |
|
||||||
}); |
}); |
||||||
|
}); |
||||||
|
|
||||||
it('should hide checkboxes', () => { |
describe('Given time and template variable values have changed', () => { |
||||||
let fakeDashboardSrv = { |
setup(true, true, (dash, ctrl: SaveDashboardModalCtrl) => { |
||||||
dash: { |
it('When creating ctrl should set time and template variable values changed', () => { |
||||||
templating: { |
expect(ctrl.timeChange).toBeTruthy(); |
||||||
list: [ |
expect(ctrl.variableValueChange).toBeTruthy(); |
||||||
{ |
}); |
||||||
current: { |
|
||||||
selected: true, |
it('When save time and variable value changes disabled and saving should reset original time and template variable values', async () => { |
||||||
text: 'server_002', |
ctrl.saveTimerange = false; |
||||||
value: 'server_002', |
ctrl.saveVariables = false; |
||||||
}, |
await ctrl.save(); |
||||||
name: 'Server', |
expect(dash.resetOriginalTime).toHaveBeenCalledTimes(0); |
||||||
}, |
expect(dash.resetOriginalVariables).toHaveBeenCalledTimes(0); |
||||||
], |
}); |
||||||
}, |
|
||||||
originalTemplating: [ |
|
||||||
{ |
|
||||||
current: { |
|
||||||
selected: true, |
|
||||||
text: 'server_002', |
|
||||||
value: 'server_002', |
|
||||||
}, |
|
||||||
name: 'Server', |
|
||||||
}, |
|
||||||
], |
|
||||||
time: { |
|
||||||
from: 'now-3h', |
|
||||||
to: 'now', |
|
||||||
}, |
|
||||||
originalTime: { |
|
||||||
from: 'now-3h', |
|
||||||
to: 'now', |
|
||||||
}, |
|
||||||
}, |
|
||||||
}; |
|
||||||
let modal = new SaveDashboardModalCtrl(fakeDashboardSrv); |
|
||||||
expect(modal.timeChange).toBe(false); |
|
||||||
expect(modal.variableValueChange).toBe(false); |
|
||||||
}); |
|
||||||
|
|
||||||
it('should hide variable checkboxes', () => { |
it('When save time and variable value changes enabled and saving should reset original time and template variable values', async () => { |
||||||
let fakeDashboardSrv = { |
ctrl.saveTimerange = true; |
||||||
dash: { |
ctrl.saveVariables = true; |
||||||
templating: { |
await ctrl.save(); |
||||||
list: [ |
expect(dash.resetOriginalTime).toHaveBeenCalledTimes(1); |
||||||
{ |
expect(dash.resetOriginalVariables).toHaveBeenCalledTimes(1); |
||||||
current: { |
}); |
||||||
selected: true, |
|
||||||
text: 'server_002', |
|
||||||
value: 'server_002', |
|
||||||
}, |
|
||||||
name: 'Server', |
|
||||||
}, |
|
||||||
{ |
|
||||||
current: { |
|
||||||
selected: true, |
|
||||||
text: 'web_002', |
|
||||||
value: 'web_002', |
|
||||||
}, |
|
||||||
name: 'Web', |
|
||||||
}, |
|
||||||
], |
|
||||||
}, |
|
||||||
originalTemplating: [ |
|
||||||
{ |
|
||||||
current: { |
|
||||||
selected: true, |
|
||||||
text: 'server_002', |
|
||||||
value: 'server_002', |
|
||||||
}, |
|
||||||
name: 'Server', |
|
||||||
}, |
|
||||||
], |
|
||||||
}, |
|
||||||
}; |
|
||||||
let modal = new SaveDashboardModalCtrl(fakeDashboardSrv); |
|
||||||
expect(modal.variableValueChange).toBe(false); |
|
||||||
}); |
}); |
||||||
}); |
}); |
||||||
}); |
}); |
||||||
|
|||||||
Loading…
Reference in new issue