Skip to content

Commit b114db9

Browse files
authored
impr: add total tests to test activity chart (@fehmer) (#5586)
1 parent d70bb66 commit b114db9

6 files changed

Lines changed: 36 additions & 3 deletions

File tree

frontend/__tests__/elements/test-activity-calendar.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,23 @@ describe("test-activity-calendar.ts", () => {
814814
expect(days[370]).toBeFiller();
815815
});
816816
});
817+
describe("getTotalTests", () => {
818+
it("gets amount of tests", () => {
819+
//GIVEN
820+
const lastDate = getDate("2024-01-02");
821+
const calendar = new ModifiableTestActivityCalendar(
822+
[1, 2, 3, 4],
823+
lastDate
824+
);
825+
826+
//THEN
827+
expect(calendar.getTotalTests()).toEqual(1 + 2 + 3 + 4);
828+
829+
//WHEN
830+
const fullYear = calendar.getFullYearCalendar();
831+
expect(fullYear.getTotalTests()).toEqual(3 + 4);
832+
});
833+
});
817834
});
818835

819836
function getDate(date: string): Date {

frontend/src/html/pages/account.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@
304304
<div class="wrapper">
305305
<div class="top">
306306
<div class="year"><select class="yearSelect"></select></div>
307-
<!-- <div class="title">test activity</div> -->
307+
<div class="title"></div>
308308
<div class="legend">
309309
<span>less</span>
310310
<div data-level="0"></div>

frontend/src/styles/account.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,8 @@
531531

532532
.title {
533533
grid-area: title;
534-
text-align: center;
535-
// font-size: 1.5em;
534+
text-align: left;
535+
font-size: var(--font-size);
536536
color: var(--sub-color);
537537
align-self: center;
538538
}

frontend/src/ts/elements/test-activity-calendar.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ export class TestActivityCalendar implements MonkeyTypes.TestActivityCalendar {
145145
return result;
146146
}
147147

148+
getTotalTests(): number {
149+
const days = differenceInDays(this.endDay, this.startDay);
150+
return (
151+
this.data.slice(0, days).reduce((a, c) => {
152+
return (a ?? 0) + (c ?? 0);
153+
}, 0) ?? 0
154+
);
155+
}
156+
148157
private getBuckets(): number[] {
149158
const filtered = this.data.filter(
150159
(it) => it !== null && it !== undefined

frontend/src/ts/elements/test-activity.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ function update(calendar?: MonkeyTypes.TestActivityCalendar): void {
3838

3939
updateMonths(calendar.getMonths());
4040
$("#testActivity .nodata").addClass("hidden");
41+
const title = document.querySelector("#testActivity .title");
42+
{
43+
if (title !== null) {
44+
title.innerHTML = calendar.getTotalTests() + " tests";
45+
}
46+
}
4147

4248
for (const day of calendar.getDays()) {
4349
const elem = document.createElement("div");

frontend/src/ts/types/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ declare namespace MonkeyTypes {
454454
type TestActivityCalendar = {
455455
getMonths: () => TestActivityMonth[];
456456
getDays: () => TestActivityDay[];
457+
getTotalTests: () => number;
457458
};
458459

459460
type ModifiableTestActivityCalendar = TestActivityCalendar & {

0 commit comments

Comments
 (0)