Add unit tests for utils and module pure functions
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
46
tests/unit/module/abbreviateNumber.test.js
Normal file
46
tests/unit/module/abbreviateNumber.test.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import abbreviateNumber from '@/module/abbreviateNumber.js';
|
||||
|
||||
describe('abbreviateNumber', () => {
|
||||
it('returns "0" for 0 seconds', () => {
|
||||
expect(abbreviateNumber(0)).toBe('0');
|
||||
});
|
||||
|
||||
it('returns seconds only when < 60', () => {
|
||||
expect(abbreviateNumber(45).trim()).toBe('45s');
|
||||
});
|
||||
|
||||
it('returns minutes and seconds', () => {
|
||||
// 2m 30s = 150s
|
||||
expect(abbreviateNumber(150).trim()).toBe('2m 30s');
|
||||
});
|
||||
|
||||
it('returns hours, minutes, and seconds', () => {
|
||||
// 1h 1m 1s = 3661s
|
||||
expect(abbreviateNumber(3661).trim()).toBe('1h 1m 1s');
|
||||
});
|
||||
|
||||
it('returns days, hours, minutes, and seconds', () => {
|
||||
// 1d 2h 3m 4s = 93784s
|
||||
expect(abbreviateNumber(93784).trim())
|
||||
.toBe('1d 2h 3m 4s');
|
||||
});
|
||||
|
||||
it('handles exact day boundary', () => {
|
||||
// 1d = 86400s
|
||||
expect(abbreviateNumber(86400).trim()).toBe('1d');
|
||||
});
|
||||
|
||||
it('handles exact hour boundary', () => {
|
||||
// 1h = 3600s
|
||||
expect(abbreviateNumber(3600).trim()).toBe('1h');
|
||||
});
|
||||
|
||||
it('handles string input by parsing as int', () => {
|
||||
expect(abbreviateNumber('150').trim()).toBe('2m 30s');
|
||||
});
|
||||
|
||||
it('handles NaN input', () => {
|
||||
expect(abbreviateNumber('abc').trim()).toBe('');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user