mirror of
https://github.com/MeshCore-Beacon/beacon-web.git
synced 2026-10-16 07:10:17 +00:00
34 lines
2.4 KiB
TypeScript
34 lines
2.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { pathHours, pathLengthOption, pathTrendOption } from "../../../src/features/stats/paths";
|
|
import { readChartColors } from "../../../src/features/stats/chartTheme";
|
|
import type { PathStats } from "../../../src/features/stats/types";
|
|
|
|
const hour = 3_600_000;
|
|
const fixture: PathStats = { since: hour / 2, until: 3 * hour, receptions: 10, hashed: 6, empty: 2, trace: 1, unclassified: 1,
|
|
hashWidths: [{ bytes: 1, receptions: 2 }, { bytes: 2, receptions: 3 }, { bytes: 3, receptions: 1 }],
|
|
pathLengths: [{ entries: 0, receptions: 2 }, { entries: 2, receptions: 5 }, { entries: 63, receptions: 1 }],
|
|
hourly: [{ hour: 0, receptions: 8, oneByte: 2, twoByte: 3, threeByte: 1, empty: 1, trace: 1, unclassified: 0 }, { hour: 2 * hour, receptions: 2, oneByte: 0, twoByte: 0, threeByte: 0, empty: 1, trace: 0, unclassified: 1 }] };
|
|
|
|
describe("path analytics charts", () => {
|
|
it("keeps absent hours distinct from known zero hash-path hours and preserves response values", () => {
|
|
const before = JSON.stringify(fixture), hours = pathHours(fixture);
|
|
expect(hours.map((h) => h.hour)).toEqual([0, hour, 2 * hour]);
|
|
expect(hours.map((h) => h.oneByte)).toEqual([2, null, 0]);
|
|
expect(hours.map((h) => h.twoByte)).toEqual([3, null, 0]);
|
|
expect(JSON.stringify(fixture)).toBe(before);
|
|
expect(pathHours(undefined)).toEqual([]);
|
|
expect(pathHours({ ...fixture, until: 30 * 24 * hour + hour / 2 })).toHaveLength(721);
|
|
});
|
|
it("fills zero-count length bins while preserving empty-path counts and visible single-hour points", () => {
|
|
const c = readChartColors();
|
|
const length = pathLengthOption(fixture.pathLengths, c);
|
|
expect(length).toMatchObject({ animation: false, tooltip: { renderMode: "richText" }, aria: { enabled: true } });
|
|
const option = length as { xAxis: { data: number[] }; series: { data: { value: number }[] }[] };
|
|
expect(option.xAxis.data).toHaveLength(64);
|
|
expect(option.series[0]!.data[0]!.value).toBe(2);
|
|
expect(option.series[0]!.data[1]!.value).toBe(0);
|
|
expect(option.series[0]!.data.reduce((n, d) => n + d.value, 0)).toBe(8);
|
|
expect(pathTrendOption(pathHours(fixture), c)).toMatchObject({ animation: false, useUTC: true, legend: { top: 0 }, series: [{ connectNulls: false, showSymbol: true, data: [[0, 2], [hour, null], [2 * hour, 0]] }, { data: [[0, 3], [hour, null], [2 * hour, 0]] }, { data: [[0, 1], [hour, null], [2 * hour, 0]] }] });
|
|
});
|
|
});
|