From d05ff2faa0856355b4770092964ae874c142463c Mon Sep 17 00:00:00 2001 From: Rufo123 Date: Fri, 11 Aug 2023 15:19:12 +0200 Subject: [PATCH] Adjusted unstable unit Tests -- Fetch Data Component and Fetch Graph Component -- Removed checking for miliseconds match in adjusted unit tests --- .../app/fetch-data/fetch-data.component.spec.ts | 10 ++++++++++ .../fetch-graphs/fetch-graph.component.spec.ts | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/TeamspeakStatsNew/TeamspeakStatsNew/ClientApp/src/app/fetch-data/fetch-data.component.spec.ts b/TeamspeakStatsNew/TeamspeakStatsNew/ClientApp/src/app/fetch-data/fetch-data.component.spec.ts index fd4275c..d1040e6 100644 --- a/TeamspeakStatsNew/TeamspeakStatsNew/ClientApp/src/app/fetch-data/fetch-data.component.spec.ts +++ b/TeamspeakStatsNew/TeamspeakStatsNew/ClientApp/src/app/fetch-data/fetch-data.component.spec.ts @@ -231,6 +231,8 @@ describe("FetchDataComponent", () => { component.sortData(SortTime.AllTime); const date = new Date(); date.setFullYear(1); + date.setMilliseconds(0); + component.dateToCountHoursFrom.setMilliseconds(0); expect(component.dateToCountHoursFrom).toEqual(date); }); @@ -429,6 +431,14 @@ describe("FetchDataComponent", () => { expect(component.sortDirection).toBe(1); }); + function removeMsFromISOString(ISOstring: string): string { + const indexOfDot = ISOstring.indexOf("."); + if (indexOfDot !== -1) { + return ISOstring.substring(0, indexOfDot) + "Z"; + } + return ISOstring; + } + interface Stats { id: number; latestName: string; diff --git a/TeamspeakStatsNew/TeamspeakStatsNew/ClientApp/src/app/fetch-graphs/fetch-graph.component.spec.ts b/TeamspeakStatsNew/TeamspeakStatsNew/ClientApp/src/app/fetch-graphs/fetch-graph.component.spec.ts index 2673af1..7f57d15 100644 --- a/TeamspeakStatsNew/TeamspeakStatsNew/ClientApp/src/app/fetch-graphs/fetch-graph.component.spec.ts +++ b/TeamspeakStatsNew/TeamspeakStatsNew/ClientApp/src/app/fetch-graphs/fetch-graph.component.spec.ts @@ -61,8 +61,12 @@ describe("VymazatComponent", () => { it("should get current time as ISO string", () => { const currentDate: Date = new Date(); - const currentDateISO = currentDate.toISOString(); - expect(component.getCurrentTimeAsIsoString()).toBe(currentDateISO); + const currentDateISO = removeMsFromISOString(currentDate.toISOString()); + const returnedISOString = removeMsFromISOString( + component.getCurrentTimeAsIsoString() + ); + + expect(returnedISOString).toBe(currentDateISO); }); it("should get graph data latest sorted by month", () => { @@ -177,6 +181,14 @@ describe("VymazatComponent", () => { expect(localStorageMock["stats-etag"]).toBe("new-etag"); }); + function removeMsFromISOString(ISOstring: string): string { + const indexOfDot = ISOstring.indexOf("."); + if (indexOfDot !== -1) { + return ISOstring.substring(0, indexOfDot) + "Z"; + } + return ISOstring; + } + enum SortTime { Year = "year", Month = "month",