From 04f3d6791c6d38586df0de9348a17807b79b2aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Thu, 11 Apr 2019 12:50:56 +0100 Subject: [PATCH] fix(ui): don't crash on null grid --- ui/src/Components/Grid/AlertGrid/index.js | 2 +- ui/src/Components/Grid/AlertGrid/index.test.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ui/src/Components/Grid/AlertGrid/index.js b/ui/src/Components/Grid/AlertGrid/index.js index 6d2e498ae..7827e0b44 100644 --- a/ui/src/Components/Grid/AlertGrid/index.js +++ b/ui/src/Components/Grid/AlertGrid/index.js @@ -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(); } }); diff --git a/ui/src/Components/Grid/AlertGrid/index.test.js b/ui/src/Components/Grid/AlertGrid/index.test.js index f9d765d24..60d3c36ac 100644 --- a/ui/src/Components/Grid/AlertGrid/index.test.js +++ b/ui/src/Components/Grid/AlertGrid/index.test.js @@ -104,6 +104,24 @@ describe("", () => { 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();