From 77ea39afccf39aeb9b9204b1e5f74988072337c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Wed, 18 Sep 2019 12:12:19 +0100 Subject: [PATCH] chore(ui): pass upgrade screen reload timer as props Makes it easier to test --- ui/src/Components/Grid/UpgradeNeeded/index.js | 6 ++++-- ui/src/Components/Grid/UpgradeNeeded/index.test.js | 10 +++++++--- ui/src/Components/Grid/index.js | 7 ++++++- ui/src/Components/Grid/index.stories.js | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/ui/src/Components/Grid/UpgradeNeeded/index.js b/ui/src/Components/Grid/UpgradeNeeded/index.js index dcd8d898f..be6f0eadf 100644 --- a/ui/src/Components/Grid/UpgradeNeeded/index.js +++ b/ui/src/Components/Grid/UpgradeNeeded/index.js @@ -9,7 +9,8 @@ import "csshake/scss/csshake-slow.scss"; class UpgradeNeeded extends Component { static propTypes = { - newVersion: PropTypes.string.isRequired + newVersion: PropTypes.string.isRequired, + reloadAfter: PropTypes.number.isRequired }; reloadApp = () => { @@ -17,7 +18,8 @@ class UpgradeNeeded extends Component { }; componentDidMount() { - this.timer = setTimeout(this.reloadApp, 3000); + const { reloadAfter } = this.props; + this.timer = setTimeout(this.reloadApp, reloadAfter); } componentWillUnmount() { diff --git a/ui/src/Components/Grid/UpgradeNeeded/index.test.js b/ui/src/Components/Grid/UpgradeNeeded/index.test.js index 1a4691faf..3b97c90c5 100644 --- a/ui/src/Components/Grid/UpgradeNeeded/index.test.js +++ b/ui/src/Components/Grid/UpgradeNeeded/index.test.js @@ -18,7 +18,9 @@ afterEach(() => { describe("", () => { it("matches snapshot", () => { - const tree = shallow(); + const tree = shallow( + + ); expect(toDiffableHtml(tree.html())).toMatchSnapshot(); }); @@ -26,13 +28,15 @@ describe("", () => { const reloadSpy = jest .spyOn(global.window.location, "reload") .mockImplementation(() => {}); - mount(); + mount(); jest.runOnlyPendingTimers(); expect(reloadSpy).toBeCalled(); }); it("timer is cleared on unmount", () => { - const tree = mount(); + const tree = mount( + + ); const instance = tree.instance(); instance.componentWillUnmount(); diff --git a/ui/src/Components/Grid/index.js b/ui/src/Components/Grid/index.js index 67f71e16f..4ca1de28f 100644 --- a/ui/src/Components/Grid/index.js +++ b/ui/src/Components/Grid/index.js @@ -27,7 +27,12 @@ const Grid = observer( } if (alertStore.info.upgradeNeeded) { - return ; + return ( + + ); } if ( diff --git a/ui/src/Components/Grid/index.stories.js b/ui/src/Components/Grid/index.stories.js index eff27cdcf..769a6d1db 100644 --- a/ui/src/Components/Grid/index.stories.js +++ b/ui/src/Components/Grid/index.stories.js @@ -81,7 +81,7 @@ storiesOf("Grid", module) return ; }) .add("UpgradeNeeded", () => { - return ; + return ; }) .add("AlertGrid", () => { const alertStore = new AlertStore([]);