mirror of
https://github.com/henrygd/beszel.git
synced 2026-09-27 20:07:48 +02:00
fix(site): round network monitor res_avg and loss to two decimals
plus formatting in utils.ts
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import { getMonitorStats } from "../src/lib/network-monitor-utils"
|
||||
import { describe, expect, mock, test } from "bun:test"
|
||||
|
||||
mock.module("@lingui/core/macro", () => ({
|
||||
t: (strings: string | TemplateStringsArray) => (typeof strings === "string" ? strings : (strings?.[0] ?? "")),
|
||||
plural: (_count: number, forms: { other?: string }) => forms.other ?? "",
|
||||
}))
|
||||
|
||||
const { getMonitorStats } = await import("../src/lib/network-monitor-utils")
|
||||
|
||||
describe("monitor stats derived from stored counts", () => {
|
||||
test("retains probe weights and response precision", () => {
|
||||
@@ -12,12 +18,26 @@ describe("monitor stats derived from stored counts", () => {
|
||||
success_count: 6,
|
||||
res_sum: 61,
|
||||
})
|
||||
expect(stats.res_avg).toBeCloseTo(10.1666667)
|
||||
expect(stats.loss).toBeCloseTo(14.2857143)
|
||||
expect(stats.res_avg).toBe(10.17)
|
||||
expect(stats.loss).toBe(14.29)
|
||||
expect(stats.res_min).toBe(5)
|
||||
expect(stats.res_max).toBe(20)
|
||||
})
|
||||
|
||||
test("limits average response and loss to two decimals", () => {
|
||||
const stats = getMonitorStats({
|
||||
monitor: "monitor1",
|
||||
created: 1000,
|
||||
res_min: 3,
|
||||
res_max: 4,
|
||||
total_count: 9,
|
||||
success_count: 3,
|
||||
res_sum: 10,
|
||||
})
|
||||
expect(stats.res_avg).toBe(3.33)
|
||||
expect(stats.loss).toBe(66.67)
|
||||
})
|
||||
|
||||
test.each([
|
||||
{ total_count: 3, success_count: 0, loss: 100 },
|
||||
{ total_count: 0, success_count: 0, loss: 0 },
|
||||
|
||||
Reference in New Issue
Block a user