opsdash-app/opsdash/test/targets.test.ts
blade34242 d7efcba67c
All checks were successful
Nextcloud Server Tests / version-consistency (push) Successful in 32s
Nextcloud Server Tests / matrix-config (push) Successful in 26s
Nextcloud Server Tests / Nextcloud stable30 / PHP 8.2 (stable30, 8.2) (push) Successful in 4m44s
Nextcloud Server Tests / Nextcloud stable31 / PHP 8.2 (stable31, 8.2) (push) Successful in 4m41s
Nextcloud Server Tests / Nextcloud stable31 / PHP 8.3 (stable31, 8.3) (push) Successful in 4m29s
Nextcloud Server Tests / Nextcloud stable32 / PHP 8.2 (stable32, 8.2) (push) Successful in 4m34s
Nextcloud Server Tests / Nextcloud stable32 / PHP 8.3 (stable32, 8.3) (push) Successful in 4m43s
Nextcloud Server Tests / Nextcloud stable33 / PHP 8.2 (stable33, 8.2) (push) Successful in 4m51s
Nextcloud Server Tests / Nextcloud stable33 / PHP 8.3 (stable33, 8.3) (push) Successful in 4m52s
Build And Publish Appstore Package / build_and_publish (push) Successful in 3m3s
fix: stabilize release notes and target progress
2026-04-28 11:51:14 +07:00

36 lines
1.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, it, expect } from 'vitest'
import { clampTarget, convertMonthToWeek, convertWeekToMonth, normalizeTargetsConfig, progressPercent } from '../src/services/targets'
describe('targets helpers', () => {
it('clamps targets to [0..10000] and rounds to 2 decimals', () => {
expect(clampTarget(-5)).toBe(0)
expect(clampTarget(2.345)).toBe(2.35)
expect(clampTarget(20000)).toBe(10000)
})
it('converts week to month (×4) with clamp', () => {
expect(convertWeekToMonth(10)).toBe(40)
expect(convertWeekToMonth(2500)).toBe(10000) // clamped
})
it('converts month to week (÷4) with rounding', () => {
expect(convertMonthToWeek(60)).toBe(15)
expect(convertMonthToWeek(2.5)).toBe(0.63)
})
it('computes progress percent with bounds', () => {
expect(progressPercent(10, 20)).toBe(50)
expect(progressPercent(0, 0)).toBe(0)
expect(progressPercent(30, 20)).toBe(150)
expect(progressPercent(-5 as unknown as number, 10)).toBe(0)
})
it('clamps all-day hours to 024 and keeps defaults', () => {
const cfg = normalizeTargetsConfig({ allDayHours: 42 } as any)
expect(cfg.allDayHours).toBe(24)
const cfgNeg = normalizeTargetsConfig({ allDayHours: -5 } as any)
expect(cfgNeg.allDayHours).toBe(0)
const cfgDefault = normalizeTargetsConfig(undefined)
expect(cfgDefault.allDayHours).toBeGreaterThan(0)
})
})