mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboard scenes: Allow undefined filter prop in adhoc variable when comparing two adhoc variables. (#88993)
* Allow undefined filter prop in adhoc variable when comparing two adhoc variables * set mock implementation before each test * mock console.warn in each test
This commit is contained in:
parent
cdbc9d801f
commit
558aaf22bd
@ -57,6 +57,35 @@ describe('adHocVariableFiltersEqual', () => {
|
|||||||
)
|
)
|
||||||
).toBeFalsy();
|
).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when filter property is undefined', () => {
|
||||||
|
afterAll(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should compare two adhoc variables where both are missing the filter property and return true', () => {
|
||||||
|
const warnSpy = jest.spyOn(console, 'warn').mockImplementationOnce(() => {});
|
||||||
|
expect(
|
||||||
|
adHocVariableFiltersEqual({} as unknown as AdHocVariableModel, {} as unknown as AdHocVariableModel)
|
||||||
|
).toBeTruthy();
|
||||||
|
|
||||||
|
expect(warnSpy).toHaveBeenCalledWith('Adhoc variable filter property is undefined');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should compare two adhoc variables where one has no filter property and return false', () => {
|
||||||
|
const warnSpy = jest.spyOn(console, 'warn').mockImplementationOnce(() => {});
|
||||||
|
expect(
|
||||||
|
adHocVariableFiltersEqual(
|
||||||
|
{} as unknown as AdHocVariableModel,
|
||||||
|
{
|
||||||
|
filters: [{ value: 'asdio', key: 'qwe', operator: 'wer' }],
|
||||||
|
} as unknown as AdHocVariableModel
|
||||||
|
)
|
||||||
|
).toBeFalsy();
|
||||||
|
|
||||||
|
expect(warnSpy).toHaveBeenCalledWith('Adhoc variable filter property is undefined');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getDashboardChanges', () => {
|
describe('getDashboardChanges', () => {
|
||||||
@ -85,6 +114,7 @@ describe('getDashboardChanges', () => {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
it('should return the correct result when no changes', () => {
|
it('should return the correct result when no changes', () => {
|
||||||
const changed = { ...initial };
|
const changed = { ...initial };
|
||||||
|
|
||||||
|
@ -72,8 +72,14 @@ export function getHasTimeChanged(saveModel: Dashboard, originalSaveModel: Dashb
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function adHocVariableFiltersEqual(a: AdHocVariableModel, b: AdHocVariableModel) {
|
export function adHocVariableFiltersEqual(a: AdHocVariableModel, b: AdHocVariableModel) {
|
||||||
if (a.filters === undefined || b.filters === undefined) {
|
if (a.filters === undefined && b.filters === undefined) {
|
||||||
throw new Error('AdHoc variable missing filter property');
|
console.warn('Adhoc variable filter property is undefined');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((a.filters === undefined && b.filters !== undefined) || (b.filters === undefined && a.filters !== undefined)) {
|
||||||
|
console.warn('Adhoc variable filter property is undefined');
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a.filters.length !== b.filters.length) {
|
if (a.filters.length !== b.filters.length) {
|
||||||
|
Loading…
Reference in New Issue
Block a user