Improve false negative on AlteredSliceTag (#6578)

The "altered" tag in the explore view shows up more often than it
should. By treating null, [] {}, undefined as identical will help reporting
only the differences that matter.
This commit is contained in:
Maxime Beauchemin
2019-01-08 12:23:12 -08:00
committed by GitHub
parent 49e3638eee
commit accc754a87
2 changed files with 47 additions and 1 deletions

View File

@@ -284,4 +284,28 @@ describe('AlteredSliceTag', () => {
expect(wrapper.instance().formatValue(filters, 'adhoc_filters')).toBe(expected);
});
});
describe('isEqualish', () => {
it('considers null, undefined, {} and [] as equal', () => {
const inst = wrapper.instance();
expect(inst.isEqualish(null, undefined)).toBe(true);
expect(inst.isEqualish(null, [])).toBe(true);
expect(inst.isEqualish(null, {})).toBe(true);
expect(inst.isEqualish(undefined, {})).toBe(true);
});
it('considers empty strings are the same as null', () => {
const inst = wrapper.instance();
expect(inst.isEqualish(undefined, '')).toBe(true);
expect(inst.isEqualish(null, '')).toBe(true);
});
it('considers deeply equal objects as equal', () => {
const inst = wrapper.instance();
expect(inst.isEqualish('', '')).toBe(true);
expect(inst.isEqualish({ a: 1, b: 2, c: 3 }, { a: 1, b: 2, c: 3 })).toBe(true);
// Out of order
expect(inst.isEqualish({ a: 1, b: 2, c: 3 }, { b: 2, a: 1, c: 3 })).toBe(true);
// Actually not equal
expect(inst.isEqualish({ a: 1, b: 2, z: 9 }, { a: 1, b: 2, c: 3 })).toBe(false);
});
});
});