From 30c947e0396bce26c9093548c48c44484f2dfbe9 Mon Sep 17 00:00:00 2001 From: Johannes Eriksson Date: Wed, 9 Dec 2020 09:35:43 +0200 Subject: [PATCH] Clarified code and added test --- .../resources/META-INF/resources/frontend/Flow.ts | 6 +++++- flow-client/src/test/frontend/FlowTests.ts | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/flow-client/src/main/resources/META-INF/resources/frontend/Flow.ts b/flow-client/src/main/resources/META-INF/resources/frontend/Flow.ts index 2b08e1b6f2d..fc287bcfaf8 100644 --- a/flow-client/src/main/resources/META-INF/resources/frontend/Flow.ts +++ b/flow-client/src/main/resources/META-INF/resources/frontend/Flow.ts @@ -390,7 +390,11 @@ export class Flow { $wnd.Vaadin.Flow.loading = (action: boolean) => { const show = action && this.isActiveCount === 0; const hide = !action && this.isActiveCount === 1; - this.isActiveCount = Math.max(0, this.isActiveCount + (action ? 1 : -1)); + if (action) { + this.isActiveCount++; + } else if (this.isActiveCount > 0) { + this.isActiveCount--; + } if (show || hide) { clearTimeout(timeout2nd); clearTimeout(timeout3rd); diff --git a/flow-client/src/test/frontend/FlowTests.ts b/flow-client/src/test/frontend/FlowTests.ts index 5512b5bc100..a85608b9c36 100644 --- a/flow-client/src/test/frontend/FlowTests.ts +++ b/flow-client/src/test/frontend/FlowTests.ts @@ -153,6 +153,20 @@ suite("Flow", () => { assert.isFalse(indicator.classList.contains('third')); }); + test("loading should stack isActive", async () => { + const flow = new Flow({imports: () => {}}); + assert.isFalse(flow.isActive); + $wnd.Vaadin.Flow.loading(true); + assert.isTrue(flow.isActive); + $wnd.Vaadin.Flow.loading(true); + assert.isTrue(flow.isActive); + $wnd.Vaadin.Flow.loading(false); + assert.isTrue(flow.isActive); + $wnd.Vaadin.Flow.loading(false); + assert.isFalse(flow.isActive); + + }); + test("should initialize Flow server navigation when calling flowInit(true)", () => { assert.isUndefined($wnd.Vaadin);