Skip to content

Commit

Permalink
update metricsHelper.test.ts to use the unified DayOfMetricData type
Browse files Browse the repository at this point in the history
There is no discrepancy between DayOfClientMetricData and DayOfServerMetricData anymore, so this test file gets stripped down a lot
  • Loading branch information
JGreenlee committed May 24, 2024
1 parent b3e80df commit 663f86c
Showing 1 changed file with 11 additions and 63 deletions.
74 changes: 11 additions & 63 deletions www/__tests__/metricsHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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([
Expand All @@ -70,59 +54,23 @@ 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', () => {
const days1 = [
{ 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');
});
});
});

0 comments on commit 663f86c

Please sign in to comment.