formatter tests
Some checks failed
Some checks failed
This commit is contained in:
80
apps/website/lib/formatters/AchievementFormatter.test.ts
Normal file
80
apps/website/lib/formatters/AchievementFormatter.test.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { AchievementFormatter } from './AchievementFormatter';
|
||||
|
||||
describe('AchievementFormatter', () => {
|
||||
describe('getRarityVariant', () => {
|
||||
it('should format common rarity correctly', () => {
|
||||
const result = AchievementFormatter.getRarityVariant('common');
|
||||
expect(result).toEqual({
|
||||
text: 'low',
|
||||
surface: 'rarity-common',
|
||||
iconIntent: 'low',
|
||||
});
|
||||
});
|
||||
|
||||
it('should format rare rarity correctly', () => {
|
||||
const result = AchievementFormatter.getRarityVariant('rare');
|
||||
expect(result).toEqual({
|
||||
text: 'primary',
|
||||
surface: 'rarity-rare',
|
||||
iconIntent: 'primary',
|
||||
});
|
||||
});
|
||||
|
||||
it('should format epic rarity correctly', () => {
|
||||
const result = AchievementFormatter.getRarityVariant('epic');
|
||||
expect(result).toEqual({
|
||||
text: 'primary',
|
||||
surface: 'rarity-epic',
|
||||
iconIntent: 'primary',
|
||||
});
|
||||
});
|
||||
|
||||
it('should format legendary rarity correctly', () => {
|
||||
const result = AchievementFormatter.getRarityVariant('legendary');
|
||||
expect(result).toEqual({
|
||||
text: 'warning',
|
||||
surface: 'rarity-legendary',
|
||||
iconIntent: 'warning',
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle case-insensitive rarity', () => {
|
||||
const result = AchievementFormatter.getRarityVariant('COMMON');
|
||||
expect(result).toEqual({
|
||||
text: 'low',
|
||||
surface: 'rarity-common',
|
||||
iconIntent: 'low',
|
||||
});
|
||||
});
|
||||
|
||||
it('should default to common for unknown rarity', () => {
|
||||
const result = AchievementFormatter.getRarityVariant('unknown');
|
||||
expect(result).toEqual({
|
||||
text: 'low',
|
||||
surface: 'rarity-common',
|
||||
iconIntent: 'low',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatDate', () => {
|
||||
it('should format date correctly', () => {
|
||||
const date = new Date('2026-01-15');
|
||||
const result = AchievementFormatter.formatDate(date);
|
||||
expect(result).toBe('Jan 15, 2026');
|
||||
});
|
||||
|
||||
it('should format date with different months', () => {
|
||||
const date = new Date('2026-12-25');
|
||||
const result = AchievementFormatter.formatDate(date);
|
||||
expect(result).toBe('Dec 25, 2026');
|
||||
});
|
||||
|
||||
it('should handle single digit days', () => {
|
||||
const date = new Date('2026-01-05');
|
||||
const result = AchievementFormatter.formatDate(date);
|
||||
expect(result).toBe('Jan 5, 2026');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user