feat: add 2FA, secure cookies and publishing tools
This commit is contained in:
44
tests/format.test.ts
Normal file
44
tests/format.test.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { formatMinutes, initials, lessonDuration, plural, shortDate, totalDuration } from '../lib/format';
|
||||
import { Course } from '../types';
|
||||
|
||||
const course = (duration: string): Course => ({
|
||||
id: duration,
|
||||
title: 'Curso',
|
||||
category: 'Área',
|
||||
thumbnail: '',
|
||||
duration,
|
||||
description: '',
|
||||
lessons: [],
|
||||
});
|
||||
|
||||
describe('formatting helpers', () => {
|
||||
it('pluralizes counts', () => {
|
||||
expect(plural(1, 'aula', 'aulas')).toBe('1 aula');
|
||||
expect(plural(3, 'aula', 'aulas')).toBe('3 aulas');
|
||||
});
|
||||
|
||||
it('formats minutes with and without hours', () => {
|
||||
expect(formatMinutes(0)).toBe('0min');
|
||||
expect(formatMinutes(45)).toBe('45min');
|
||||
expect(formatMinutes(60)).toBe('1h');
|
||||
expect(formatMinutes(125)).toBe('2h 05min');
|
||||
});
|
||||
|
||||
it('builds initials and lesson durations', () => {
|
||||
expect(initials('Ana Maria Silva')).toBe('AM');
|
||||
expect(lessonDuration({ id: '1', title: 'Aula', duration: '—' } as never)).toBe('');
|
||||
expect(lessonDuration({ id: '1', title: 'Aula', duration: '12min' } as never)).toBe('12min');
|
||||
});
|
||||
|
||||
it('sums course durations', () => {
|
||||
expect(totalDuration([course('1h 30min'), course('45min')])).toBe('2h 15min');
|
||||
expect(totalDuration([])).toBe('');
|
||||
});
|
||||
|
||||
it('formats short dates and rejects invalid values', () => {
|
||||
expect(shortDate('2026-11-05T12:00:00Z')).toContain('5');
|
||||
expect(shortDate('invalid')).toBe('');
|
||||
expect(shortDate(null)).toBe('');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user