Skip to content

Commit

Permalink
Fix visualize() to return empty string if data is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
yykamei committed Apr 10, 2024
1 parent 8852b09 commit 82c110c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
3 changes: 3 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29675,6 +29675,9 @@ class MermaidXYChart {
}
return m;
}, new Map());
if (map.size === 0) {
return "";
}
const aggregates = new Map();
for (const [date, seconds] of map.entries()) {
switch (this.input.aggregate) {
Expand Down
3 changes: 3 additions & 0 deletions src/MermaidXYChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export class MermaidXYChart {
}
return m;
}, new Map());
if (map.size === 0) {
return "";
}
const aggregates: Map<string, number> = new Map();
for (const [date, seconds] of map.entries()) {
switch (this.input.aggregate) {
Expand Down
27 changes: 26 additions & 1 deletion tests/MermaidXYChart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Input } from "../src/Input";
import { MermaidXYChart } from "../src/MermaidXYChart";

describe("DateTime", () => {
it("should initialize", () => {
it("should visualize", () => {
const context = new Context();
vi.spyOn(context, "repo", "get").mockReturnValue({
owner: "yykamei",
Expand Down Expand Up @@ -243,4 +243,29 @@ xychart-beta
\`\`\`
`);
});

it("should return empty string with visualize()", () => {
const context = new Context();
vi.spyOn(context, "repo", "get").mockReturnValue({
owner: "yykamei",
repo: "test-repo",
});
const getInput = vi.fn((key: string) => {
switch (key) {
case "status":
return "";
case "aggregate":
return "average";
default:
throw new Error("Unsupported key");
}
});
const input = new Input(context, getInput);
const mermaidXYChart = new MermaidXYChart(
new GitHubWorkflow(88, "ABC", "abc.yml"),
[],
input,
);
expect(mermaidXYChart.visualize()).toEqual("");
});
});

0 comments on commit 82c110c

Please sign in to comment.