Skip to content

Commit e43d327

Browse files
authored
Merge pull request #24 from buggregator/issue/#23-large-peaks-stat-borad
Issue/#23 large peaks stat borad
2 parents d3e6f36 + dcd8d81 commit e43d327

File tree

5 files changed

+301
-11
lines changed

5 files changed

+301
-11
lines changed

components/StatBoard/StatBoard.stories.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Meta, Story } from "@storybook/vue3";
22
import { normalizeProfilerEvent } from "~/utils/normalize-event";
3-
import StatBoard from '~/components/StatBoard/StatBoard.vue';
4-
import profilerEventMock from '~/mocks/profiler.json'
5-
import type { Profiler } from '~/config/types'
3+
import StatBoard from "~/components/StatBoard/StatBoard.vue";
4+
import profilerEventMock from "~/mocks/profiler.json";
5+
import type { Profiler } from "~/config/types";
66

77
export default {
88
title: "Components/StatBoard",
9-
component: StatBoard
9+
component: StatBoard,
1010
} as Meta<typeof StatBoard>;
1111

1212
const Template: Story = (args) => ({
@@ -24,3 +24,15 @@ export const Default = Template.bind({});
2424
Default.args = {
2525
cost: (normalizeProfilerEvent(profilerEventMock).payload as Profiler)?.peaks,
2626
};
27+
28+
export const LargePeaks = Template.bind({});
29+
30+
LargePeaks.args = {
31+
cost: {
32+
ct: 1,
33+
wt: 2062700000,
34+
cpu: 447500000,
35+
mu: 31121760000,
36+
pmu: 30014160000,
37+
},
38+
};

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"preview": "nuxi preview",
99
"postinstall": "nuxi prepare",
1010
"prepare": "npx husky install",
11-
"lint": "eslint . --fix"
11+
"lint": "eslint . --fix",
12+
"test": "vitest"
1213
},
1314
"type": "module",
1415
"lint-staged": {
@@ -52,13 +53,13 @@
5253
"sass": "^1.57.1",
5354
"storybook-addon-themes": "^6.1.0",
5455
"typescript": "^4.9.4",
56+
"vitest": "^0.34.2",
5557
"vue-eslint-parser": "^9.1.0"
5658
},
5759
"dependencies": {
5860
"@highlightjs/vue-plugin": "^2.1.2",
5961
"@hpcc-js/wasm": "^2.8.0",
6062
"@pinia/nuxt": "^0.4.6",
61-
"nuxt": "3.3.3",
6263
"@storybook/addon-actions": "^6.5.15",
6364
"@storybook/vue3": "^6.5.16",
6465
"@vue/shared": "^3.2.45",
@@ -70,6 +71,7 @@
7071
"highlight.js": "^11.7.0",
7172
"html-to-image": "^1.11.4",
7273
"moment": "^2.29.4",
74+
"nuxt": "3.3.3",
7375
"pinia": "^2.0.30",
7476
"tailwindcss": "^3.2.4",
7577
"vue": "^3.2.45",

utils/formats.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { expect, test, describe } from "vitest";
2+
import { formatDuration } from "./formats";
3+
4+
describe("formatDuration", () => {
5+
test("should return correct string for milliseconds", () => {
6+
expect(formatDuration(1)).toBe("0.0010 ms");
7+
expect(formatDuration(1000)).toBe("1 ms");
8+
});
9+
10+
test("should return correct string for milliseconds negative", () => {
11+
expect(formatDuration(-1)).toBe("0.0010 ms");
12+
expect(formatDuration(-1000)).toBe("1 ms");
13+
});
14+
15+
test("should return correct string for seconds", () => {
16+
expect(formatDuration(1000 * 1000)).toBe("1 s");
17+
expect(formatDuration(1000 * 1000 * 59.9999)).toBe("59 s, 999.9000 ms");
18+
});
19+
20+
test("should return correct string for minutes", () => {
21+
expect(formatDuration(1000 * 1000 * 60)).toBe("1 m");
22+
expect(formatDuration(1000 * 1000 * 60 * 59.9999)).toBe("59 m, 59 s, 994 ms");
23+
});
24+
25+
test("should return correct string for hours", () => {
26+
expect(formatDuration(1000 * 1000 * 60 * 60)).toBe("1 h");
27+
expect(formatDuration(1000 * 1000 * 60 * 60 * 23.9999)).toBe("23 h, 59 m, 59 s, 640 ms");
28+
});
29+
30+
test("should return correct string for days", () => {
31+
expect(formatDuration(1000 * 1000 * 60 * 60 * 24)).toBe("1 d");
32+
expect(formatDuration(1000 * 1000 * 60 * 60 * 24 * 364.9999)).toBe("364 d, 23 h, 59 m, 51 s, 360 ms");
33+
});
34+
});

utils/formats.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@ export const formatDuration = (inputMs: number) => {
1515
};
1616

1717
return Object.entries(time)
18-
.filter((val) => val[1] !== 0)
19-
.map((val) => `${val[1].toFixed(4)} ${val[1] !== 1 ? val[0] : val[0]}`)
18+
.filter(([_, val]) => val !== 0)
19+
.map(
20+
([key, val]) =>
21+
`${
22+
key === "ms" && Number(val.toFixed(4)) % 1 !== 0
23+
? val.toFixed(4)
24+
: val.toFixed(0)
25+
} ${key}`
26+
)
2027
.join(", ");
21-
}
28+
};
2229

2330
export const humanFileSize = (inputBytes: number) => {
2431
let bytes = inputBytes;
@@ -38,7 +45,7 @@ export const humanFileSize = (inputBytes: number) => {
3845
} while (
3946
Math.round(Math.abs(bytes) * r) / r >= thresh &&
4047
u < units.length - 1
41-
);
48+
);
4249

4350
return `${bytes.toFixed(1)} ${units[u]}`;
44-
}
51+
};

0 commit comments

Comments
 (0)