mirror of
https://github.com/misenhower/splatoon3.ink.git
synced 2026-09-10 17:45:36 -05:00
Add unit tests for getDurationParts
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useTimeStore } from '@/stores/time';
|
||||
|
||||
function getDurationParts(value) {
|
||||
export function getDurationParts(value) {
|
||||
let negative = (value < 0) ? '-' : '';
|
||||
value = Math.abs(value);
|
||||
|
||||
|
||||
63
src/common/time.test.js
Normal file
63
src/common/time.test.js
Normal file
@@ -0,0 +1,63 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { getDurationParts } from './time.js';
|
||||
|
||||
describe('getDurationParts', () => {
|
||||
it('returns all zeros for zero', () => {
|
||||
expect(getDurationParts(0)).toEqual({
|
||||
negative: '',
|
||||
days: 0,
|
||||
hours: 0,
|
||||
minutes: 0,
|
||||
seconds: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it('computes 1d 1h 1m 1s for 90061', () => {
|
||||
expect(getDurationParts(90061)).toEqual({
|
||||
negative: '',
|
||||
days: 1,
|
||||
hours: 1,
|
||||
minutes: 1,
|
||||
seconds: 1,
|
||||
});
|
||||
});
|
||||
|
||||
it('sets negative flag for negative values', () => {
|
||||
const result = getDurationParts(-90061);
|
||||
expect(result.negative).toBe('-');
|
||||
expect(result.days).toBe(1);
|
||||
expect(result.hours).toBe(1);
|
||||
expect(result.minutes).toBe(1);
|
||||
expect(result.seconds).toBe(1);
|
||||
});
|
||||
|
||||
it('computes exactly 1 day for 86400', () => {
|
||||
expect(getDurationParts(86400)).toEqual({
|
||||
negative: '',
|
||||
days: 1,
|
||||
hours: 0,
|
||||
minutes: 0,
|
||||
seconds: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it('computes only seconds for 59', () => {
|
||||
expect(getDurationParts(59)).toEqual({
|
||||
negative: '',
|
||||
days: 0,
|
||||
hours: 0,
|
||||
minutes: 0,
|
||||
seconds: 59,
|
||||
});
|
||||
});
|
||||
|
||||
it('computes hours and minutes without days', () => {
|
||||
expect(getDurationParts(3661)).toEqual({
|
||||
negative: '',
|
||||
days: 0,
|
||||
hours: 1,
|
||||
minutes: 1,
|
||||
seconds: 1,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user