Skip to content

Commit

Permalink
Update text displayed on Status Bar Item (#458)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan Luker <[email protected]>
  • Loading branch information
mattseddon and ryanluker authored Nov 17, 2024
1 parent 94d91b2 commit 29a8850
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 24 deletions.
34 changes: 24 additions & 10 deletions src/extension/statusbartoggler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ import { Disposable, StatusBarItem, window } from "vscode";
import { Config } from "./config";

export class StatusBarToggler implements Disposable {
private static readonly coverageText = "Coverage";

private static readonly loadingText = ["$(loading~spin)", StatusBarToggler.coverageText].join(" ");
private static readonly loadingText = ["$(loading~spin)", "Coverage"].join(
" "
);

private static readonly idleIcon = "$(circle-large-outline)";

private static readonly watchCommand = "coverage-gutters.watchCoverageAndVisibleEditors";
private static readonly watchText = [StatusBarToggler.idleIcon, "Watch"].join(" ");
private static readonly watchToolTip = "Coverage Gutters: Click to watch workspace.";
private static readonly watchCommand =
"coverage-gutters.watchCoverageAndVisibleEditors";
private static readonly watchText = [
StatusBarToggler.idleIcon,
"Watch",
].join(" ");
private static readonly watchToolTip =
"Coverage Gutters: Click to watch workspace.";

private static readonly removeCommand = "coverage-gutters.removeWatch";
private static readonly removeWatchToolTip = "Coverage Gutters: Click to remove watch from workspace.";
private static readonly removeWatchToolTip =
"Coverage Gutters: Click to remove watch from workspace.";

public isActive: boolean | undefined;
public isLoading: boolean;
Expand All @@ -30,7 +36,9 @@ export class StatusBarToggler implements Disposable {
this.isLoading = false;
this.lineCoverage = undefined;

if (this.configStore.showStatusBarToggler) { this.statusBarItem.show(); }
if (this.configStore.showStatusBarToggler) {
this.statusBarItem.show();
}
}

public get statusText() {
Expand All @@ -51,7 +59,7 @@ export class StatusBarToggler implements Disposable {
this.update();
}

public setCoverage(linePercentage: number | undefined ) {
public setCoverage(linePercentage: number | undefined) {
if (Number.isFinite(linePercentage)) {
this.lineCoverage = `${linePercentage}%`;
} else {
Expand All @@ -72,7 +80,13 @@ export class StatusBarToggler implements Disposable {
return StatusBarToggler.loadingText;
}
if (this.isActive) {
return [StatusBarToggler.idleIcon, this.lineCoverage || "No", StatusBarToggler.coverageText].join(" ");
const activeText = [StatusBarToggler.idleIcon, "File"];
if (this.lineCoverage && this.lineCoverage !== "0%") {
activeText.push(this.lineCoverage, "Covered");
} else {
activeText.push("Uncovered");
}
return activeText.join(" ");
}
return StatusBarToggler.watchText;
}
Expand Down
54 changes: 40 additions & 14 deletions test/extension/statusbartoggler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,74 @@ suite("Status Bar Toggler Tests", () => {
test("Should toggle showStatusBarToggler command and message @unit", () => {
const statusBarToggler = new StatusBarToggler(stubConfig);
statusBarToggler.toggle(true);
expect(statusBarToggler.statusText).to.equal("$(circle-large-outline) No Coverage");
expect(statusBarToggler.statusText).to.equal(
"$(circle-large-outline) File Uncovered"
);
});

test("Should not toggle twice showStatusBarToggler command and message @unit", () => {
const statusBarToggler = new StatusBarToggler(stubConfig);
statusBarToggler.toggle(true);
expect(statusBarToggler.statusText).to.equal("$(circle-large-outline) No Coverage");
expect(statusBarToggler.statusText).to.equal(
"$(circle-large-outline) File Uncovered"
);
statusBarToggler.toggle(true);
expect(statusBarToggler.statusText).to.equal("$(circle-large-outline) No Coverage");
expect(statusBarToggler.statusText).to.equal(
"$(circle-large-outline) File Uncovered"
);
});

test("Should toggle showStatusBarToggler command and message back to \"Watch\" @unit", () => {
test('Should toggle showStatusBarToggler command and message back to "Watch" @unit', () => {
const statusBarToggler = new StatusBarToggler(stubConfig);
statusBarToggler.toggle(true);
expect(statusBarToggler.statusText).to.equal("$(circle-large-outline) No Coverage");
expect(statusBarToggler.statusText).to.equal(
"$(circle-large-outline) File Uncovered"
);
statusBarToggler.toggle(false);
expect(statusBarToggler.statusText).to.equal("$(circle-large-outline) Watch");
expect(statusBarToggler.statusText).to.equal(
"$(circle-large-outline) Watch"
);
});

test("Should show the spinner when setting the `isLoading` status @unit", () => {
const statusBarToggler = new StatusBarToggler(stubConfig);
statusBarToggler.setLoading(true);
expect(statusBarToggler.statusText).to.equal("$(loading~spin) Coverage");
expect(statusBarToggler.statusText).to.equal(
"$(loading~spin) Coverage"
);
statusBarToggler.toggle(true);
expect(statusBarToggler.statusText).to.equal("$(loading~spin) Coverage");
expect(statusBarToggler.statusText).to.equal(
"$(loading~spin) Coverage"
);
statusBarToggler.setLoading(false);
expect(statusBarToggler.statusText).to.equal("$(circle-large-outline) No Coverage");
expect(statusBarToggler.statusText).to.equal(
"$(circle-large-outline) File Uncovered"
);
});

test("Should show coverage when a number is set @unit", () => {
const statusBarToggler = new StatusBarToggler(stubConfig);
statusBarToggler.toggle(true);
statusBarToggler.setLoading(false);
expect(statusBarToggler.statusText).to.equal("$(circle-large-outline) No Coverage");
expect(statusBarToggler.statusText).to.equal(
"$(circle-large-outline) File Uncovered"
);
statusBarToggler.setCoverage(84);
expect(statusBarToggler.statusText).to.equal("$(circle-large-outline) 84% Coverage");
expect(statusBarToggler.statusText).to.equal(
"$(circle-large-outline) File 84% Covered"
);
statusBarToggler.setCoverage(undefined);
expect(statusBarToggler.statusText).to.equal("$(circle-large-outline) No Coverage");
expect(statusBarToggler.statusText).to.equal(
"$(circle-large-outline) File Uncovered"
);
statusBarToggler.setCoverage(50);
expect(statusBarToggler.statusText).to.equal("$(circle-large-outline) 50% Coverage");
expect(statusBarToggler.statusText).to.equal(
"$(circle-large-outline) File 50% Covered"
);
statusBarToggler.setCoverage(0);
expect(statusBarToggler.statusText).to.equal("$(circle-large-outline) 0% Coverage");
expect(statusBarToggler.statusText).to.equal(
"$(circle-large-outline) File Uncovered"
);
});

test("Should dispose when asked @unit", () => {
Expand Down

0 comments on commit 29a8850

Please sign in to comment.