Merge pull request #609 from prymitive/fix-repack

fix(ui): don't crash on null grid
This commit is contained in:
Łukasz Mierzwa
2019-04-11 14:20:42 +01:00
committed by GitHub
2 changed files with 19 additions and 1 deletions

View File

@@ -44,7 +44,7 @@ const AlertGrid = observer(
// used to call forcePack() which will repack all grid elements
// (alert groups), this needs to be called if any group size changes
masonryRepack = action(() => {
if (this.masonryComponentReference.ref !== false) {
if (this.masonryComponentReference.ref) {
this.masonryComponentReference.ref.forcePack();
}
});

View File

@@ -104,6 +104,24 @@ describe("<AlertGrid />", () => {
expect(repackSpy).toHaveBeenCalled();
});
it("masonryRepack() doesn't crash when masonryComponentReference.ref=null`", () => {
const tree = ShallowAlertGrid();
const instance = tree.instance();
const repackSpy = jest.spyOn(instance, "masonryRepack");
instance.masonryComponentReference.ref = null;
instance.componentDidUpdate();
expect(repackSpy).toHaveBeenCalled();
});
it("masonryRepack() doesn't crash when masonryComponentReference.ref=undefined`", () => {
const tree = ShallowAlertGrid();
const instance = tree.instance();
const repackSpy = jest.spyOn(instance, "masonryRepack");
instance.masonryComponentReference.ref = undefined;
instance.componentDidUpdate();
expect(repackSpy).toHaveBeenCalled();
});
it("calling storeMasonryRef() saves the ref in local store", () => {
const tree = ShallowAlertGrid();
const instance = tree.instance();