mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-22 20:57:45 +00:00
* feat(quota): add database-backed resource quota system * feat(webui): add resource quota management in team settings (#319) * feat(webui): add resource quota settings in team management * refactor(webui): update quotas list to full row layout and restrict skill/mcp to select list * feat(quota): refactor quota system to 2-level rules and records * fix(webui): fix overflow and scroll area in quota usage records dialog * fix(webui): ensure quota records scroll area has explicit max height * feat(webui): improve quota cards interaction and restrict editable fields in edit mode * fix(quota): serialize initial records, validate merged updates, and reset on dimension changes (#320) * feat(quota): replace network quota with agent tools quota (#321) * feat(webui): show remaining time until next refresh in quota usage records * fix(webui): rename bash quota resource to Agent Bash Calls * refactor(quota): remove unused reserved field from quota records * refactor(quota): remove quota rule cache (#322)
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { formatRemainingTime } from './time'
|
|
|
|
describe('formatRemainingTime', () => {
|
|
const baseNow = new Date('2026-08-17T12:00:00Z')
|
|
|
|
it('formats hours and minutes', () => {
|
|
const target = new Date('2026-08-17T15:18:00Z')
|
|
expect(formatRemainingTime(target, baseNow)).toBe('3h 18m')
|
|
})
|
|
|
|
it('formats exact hours', () => {
|
|
const target = new Date('2026-08-17T15:00:00Z')
|
|
expect(formatRemainingTime(target, baseNow)).toBe('3h')
|
|
})
|
|
|
|
it('formats minutes only', () => {
|
|
const target = new Date('2026-08-17T12:45:00Z')
|
|
expect(formatRemainingTime(target, baseNow)).toBe('45m')
|
|
})
|
|
|
|
it('formats days and hours', () => {
|
|
const target = new Date('2026-08-19T16:00:00Z')
|
|
expect(formatRemainingTime(target, baseNow)).toBe('2d 4h')
|
|
})
|
|
|
|
it('formats days only', () => {
|
|
const target = new Date('2026-08-19T12:00:00Z')
|
|
expect(formatRemainingTime(target, baseNow)).toBe('2d')
|
|
})
|
|
|
|
it('handles less than 1 minute', () => {
|
|
const target = new Date('2026-08-17T12:00:30Z')
|
|
expect(formatRemainingTime(target, baseNow)).toBe('< 1m')
|
|
})
|
|
|
|
it('handles past or equal dates', () => {
|
|
const past = new Date('2026-08-17T11:00:00Z')
|
|
expect(formatRemainingTime(past, baseNow)).toBe('< 1m')
|
|
expect(formatRemainingTime(baseNow, baseNow)).toBe('< 1m')
|
|
})
|
|
|
|
it('accepts ISO strings', () => {
|
|
expect(formatRemainingTime('2026-08-17T15:18:00Z', baseNow)).toBe('3h 18m')
|
|
})
|
|
})
|