Skip to content

Commit

Permalink
Clarified code and added test
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Eriksson committed Dec 9, 2020
1 parent dc3f418 commit 30c947e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions flow-client/src/test/frontend/FlowTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 30c947e

Please sign in to comment.