diff --git a/www/__tests__/metricsHelper.test.ts b/www/__tests__/metricsHelper.test.ts index 075a9000f..07fe64736 100644 --- a/www/__tests__/metricsHelper.test.ts +++ b/www/__tests__/metricsHelper.test.ts @@ -6,41 +6,25 @@ import { getUniqueLabelsForDays, segmentDaysByWeeks, } from '../js/metrics/metricsHelper'; -import { - DayOfClientMetricData, - DayOfMetricData, - DayOfServerMetricData, -} from '../js/metrics/metricsTypes'; +import { DayOfMetricData } from '../js/metrics/metricsTypes'; describe('metricsHelper', () => { describe('getUniqueLabelsForDays', () => { const days1 = [ - { label_a: 1, label_b: 2 }, - { label_c: 1, label_d: 3 }, - ] as any as DayOfServerMetricData[]; - it("should return unique labels for days with 'label_*'", () => { + { mode_confirm_a: 1, mode_confirm_b: 2 }, + { mode_confirm_b: 1, mode_confirm_c: 3 }, + { mode_confirm_c: 1, mode_confirm_d: 3 }, + ] as any as DayOfMetricData[]; + it("should return unique labels for days with 'mode_confirm_*'", () => { expect(getUniqueLabelsForDays(days1)).toEqual(['a', 'b', 'c', 'd']); }); - - const days2 = [ - { mode_a: 1, mode_b: 2 }, - { mode_c: 1, mode_d: 3 }, - ] as any as DayOfClientMetricData[]; - it("should return unique labels for days with 'mode_*'", () => { - expect(getUniqueLabelsForDays(days2)).toEqual(['a', 'b', 'c', 'd']); - }); }); describe('getLabelsForDay', () => { - const day1 = { label_a: 1, label_b: 2 } as any as DayOfServerMetricData; - it("should return labels for a day with 'label_*'", () => { + const day1 = { mode_confirm_a: 1, mode_confirm_b: 2 } as any as DayOfMetricData; + it("should return labels for a day with 'mode_confirm_*'", () => { expect(getLabelsForDay(day1)).toEqual(['a', 'b']); }); - - const day2 = { mode_a: 1, mode_b: 2 } as any as DayOfClientMetricData; - it("should return labels for a day with 'mode_*'", () => { - expect(getLabelsForDay(day2)).toEqual(['a', 'b']); - }); }); // secondsToMinutes @@ -55,7 +39,7 @@ describe('metricsHelper', () => { { date: '2021-01-08' }, { date: '2021-01-09' }, { date: '2021-01-10' }, - ] as any as DayOfClientMetricData[]; + ] as any as DayOfMetricData[]; it("should segment days with 'date' into weeks", () => { expect(segmentDaysByWeeks(days1, '2021-01-10')).toEqual([ @@ -70,40 +54,13 @@ describe('metricsHelper', () => { [{ date: '2021-01-01' }, { date: '2021-01-02' }], ]); }); - - const days2 = [ - { fmt_time: '2021-01-01T00:00:00Z' }, - { fmt_time: '2021-01-02T00:00:00Z' }, - { fmt_time: '2021-01-04T00:00:00Z' }, - { fmt_time: '2021-01-08T00:00:00Z' }, - { fmt_time: '2021-01-09T00:00:00Z' }, - { fmt_time: '2021-01-10T00:00:00Z' }, - ] as any as DayOfServerMetricData[]; - it("should segment days with 'fmt_time' into weeks", () => { - expect(segmentDaysByWeeks(days2, '2021-01-10')).toEqual([ - // most recent week - [ - { fmt_time: '2021-01-04T00:00:00Z' }, - { fmt_time: '2021-01-08T00:00:00Z' }, - { fmt_time: '2021-01-09T00:00:00Z' }, - { fmt_time: '2021-01-10T00:00:00Z' }, - ], - // prior week - [{ fmt_time: '2021-01-01T00:00:00Z' }, { fmt_time: '2021-01-02T00:00:00Z' }], - ]); - }); }); describe('formatDate', () => { - const day1 = { date: '2021-01-01' } as any as DayOfClientMetricData; + const day1 = { date: '2021-01-01' } as any as DayOfMetricData; it('should format date', () => { expect(formatDate(day1)).toEqual('1/1'); }); - - const day2 = { fmt_time: '2021-01-01T00:00:00Z' } as any as DayOfServerMetricData; - it('should format date', () => { - expect(formatDate(day2)).toEqual('1/1'); - }); }); describe('formatDateRangeOfDays', () => { @@ -111,18 +68,9 @@ describe('metricsHelper', () => { { date: '2021-01-01' }, { date: '2021-01-02' }, { date: '2021-01-04' }, - ] as any as DayOfClientMetricData[]; + ] as any as DayOfMetricData[]; it('should format date range for days with date', () => { expect(formatDateRangeOfDays(days1)).toEqual('1/1 - 1/4'); }); - - const days2 = [ - { fmt_time: '2021-01-01T00:00:00Z' }, - { fmt_time: '2021-01-02T00:00:00Z' }, - { fmt_time: '2021-01-04T00:00:00Z' }, - ] as any as DayOfServerMetricData[]; - it('should format date range for days with fmt_time', () => { - expect(formatDateRangeOfDays(days2)).toEqual('1/1 - 1/4'); - }); }); });