mirror of
https://github.com/CorentinTh/it-tools.git
synced 2026-10-21 21:31:21 +00:00
test(eta-calculator): cover formatMsDuration
The ETA calculator service exported formatMsDuration without any unit coverage; these tests pin its current behaviour (hour/minute/second breakdown, appended truncated milliseconds, and the empty string for zero or negative durations) so future refactors cannot silently change the displayed duration.
This commit is contained in:
parent
f512d09227
commit
428ef71732
1 changed files with 31 additions and 0 deletions
31
src/tools/eta-calculator/eta-calculator.service.test.ts
Normal file
31
src/tools/eta-calculator/eta-calculator.service.test.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { formatMsDuration } from './eta-calculator.service';
|
||||
|
||||
describe('eta-calculator', () => {
|
||||
describe('formatMsDuration', () => {
|
||||
it('should return an empty string for zero or negative durations', () => {
|
||||
expect(formatMsDuration(0)).toEqual('');
|
||||
expect(formatMsDuration(-1)).toEqual('');
|
||||
});
|
||||
|
||||
it('should format durations shorter than an hour', () => {
|
||||
expect(formatMsDuration(1000)).toEqual('1 second');
|
||||
expect(formatMsDuration(42000)).toEqual('42 seconds');
|
||||
expect(formatMsDuration(3599000)).toEqual('59 minutes 59 seconds');
|
||||
});
|
||||
|
||||
it('should format durations with hours', () => {
|
||||
expect(formatMsDuration(3600000)).toEqual('1 hour');
|
||||
expect(formatMsDuration(3660000)).toEqual('1 hour 1 minute');
|
||||
expect(formatMsDuration(3661000)).toEqual('1 hour 1 minute 1 second');
|
||||
expect(formatMsDuration(5400000)).toEqual('1 hour 30 minutes');
|
||||
expect(formatMsDuration(86399000)).toEqual('23 hours 59 minutes 59 seconds');
|
||||
});
|
||||
|
||||
it('should append the truncated milliseconds when some are left', () => {
|
||||
expect(formatMsDuration(1500)).toEqual('1 second 500 ms');
|
||||
expect(formatMsDuration(3661500)).toEqual('1 hour 1 minute 1 second 500 ms');
|
||||
expect(formatMsDuration(1500.9)).toEqual('1 second 500 ms');
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue