Files
gridpilot.gg/apps/website/lib/formatters/ProfileFormatter.test.ts
Marc Mintel 3db2209d2a
Some checks failed
CI / lint-typecheck (push) Failing after 4m52s
CI / tests (push) Has been skipped
CI / contract-tests (push) Has been skipped
CI / e2e-tests (push) Has been skipped
CI / comment-pr (push) Has been skipped
CI / commit-types (push) Has been skipped
formatter tests
2026-01-25 11:17:47 +01:00

360 lines
11 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { ProfileFormatter } from './ProfileFormatter';
describe('ProfileFormatter', () => {
describe('getCountryFlag', () => {
it('should return correct flag for US', () => {
const result = ProfileFormatter.getCountryFlag('US');
expect(result).toEqual({
flag: '🇺🇸',
label: 'United States',
});
});
it('should return correct flag for GB', () => {
const result = ProfileFormatter.getCountryFlag('GB');
expect(result).toEqual({
flag: '🇬🇧',
label: 'United Kingdom',
});
});
it('should return correct flag for DE', () => {
const result = ProfileFormatter.getCountryFlag('DE');
expect(result).toEqual({
flag: '🇩🇪',
label: 'Germany',
});
});
it('should handle lowercase country codes', () => {
const result = ProfileFormatter.getCountryFlag('us');
expect(result).toEqual({
flag: '🇺🇸',
label: 'United States',
});
});
it('should return default flag for unknown country code', () => {
const result = ProfileFormatter.getCountryFlag('XX');
expect(result).toEqual({
flag: '🏁',
label: 'Unknown',
});
});
});
describe('getAchievementRarity', () => {
it('should return correct display data for common rarity', () => {
const result = ProfileFormatter.getAchievementRarity('common');
expect(result).toEqual({
text: 'Common',
badgeClasses: 'bg-gray-400/10 text-gray-400',
borderClasses: 'border-gray-400/30',
});
});
it('should return correct display data for rare rarity', () => {
const result = ProfileFormatter.getAchievementRarity('rare');
expect(result).toEqual({
text: 'Rare',
badgeClasses: 'bg-primary-blue/10 text-primary-blue',
borderClasses: 'border-primary-blue/30',
});
});
it('should return correct display data for epic rarity', () => {
const result = ProfileFormatter.getAchievementRarity('epic');
expect(result).toEqual({
text: 'Epic',
badgeClasses: 'bg-purple-400/10 text-purple-400',
borderClasses: 'border-purple-400/30',
});
});
it('should return correct display data for legendary rarity', () => {
const result = ProfileFormatter.getAchievementRarity('legendary');
expect(result).toEqual({
text: 'Legendary',
badgeClasses: 'bg-yellow-400/10 text-yellow-400',
borderClasses: 'border-yellow-400/30',
});
});
it('should default to common for unknown rarity', () => {
const result = ProfileFormatter.getAchievementRarity('unknown');
expect(result).toEqual({
text: 'Common',
badgeClasses: 'bg-gray-400/10 text-gray-400',
borderClasses: 'border-gray-400/30',
});
});
});
describe('getAchievementIcon', () => {
it('should return correct display data for trophy icon', () => {
const result = ProfileFormatter.getAchievementIcon('trophy');
expect(result).toEqual({
name: 'Trophy',
});
});
it('should return correct display data for medal icon', () => {
const result = ProfileFormatter.getAchievementIcon('medal');
expect(result).toEqual({
name: 'Medal',
});
});
it('should return correct display data for star icon', () => {
const result = ProfileFormatter.getAchievementIcon('star');
expect(result).toEqual({
name: 'Star',
});
});
it('should return correct display data for crown icon', () => {
const result = ProfileFormatter.getAchievementIcon('crown');
expect(result).toEqual({
name: 'Crown',
});
});
it('should return correct display data for target icon', () => {
const result = ProfileFormatter.getAchievementIcon('target');
expect(result).toEqual({
name: 'Target',
});
});
it('should return correct display data for zap icon', () => {
const result = ProfileFormatter.getAchievementIcon('zap');
expect(result).toEqual({
name: 'Zap',
});
});
it('should default to trophy for unknown icon', () => {
const result = ProfileFormatter.getAchievementIcon('unknown');
expect(result).toEqual({
name: 'Trophy',
});
});
});
describe('getSocialPlatform', () => {
it('should return correct display data for twitter', () => {
const result = ProfileFormatter.getSocialPlatform('twitter');
expect(result).toEqual({
name: 'Twitter',
hoverClasses: 'hover:text-sky-400 hover:bg-sky-400/10',
});
});
it('should return correct display data for youtube', () => {
const result = ProfileFormatter.getSocialPlatform('youtube');
expect(result).toEqual({
name: 'YouTube',
hoverClasses: 'hover:text-red-500 hover:bg-red-500/10',
});
});
it('should return correct display data for twitch', () => {
const result = ProfileFormatter.getSocialPlatform('twitch');
expect(result).toEqual({
name: 'Twitch',
hoverClasses: 'hover:text-purple-400 hover:bg-purple-400/10',
});
});
it('should return correct display data for discord', () => {
const result = ProfileFormatter.getSocialPlatform('discord');
expect(result).toEqual({
name: 'Discord',
hoverClasses: 'hover:text-indigo-400 hover:bg-indigo-400/10',
});
});
it('should default to discord for unknown platform', () => {
const result = ProfileFormatter.getSocialPlatform('unknown');
expect(result).toEqual({
name: 'Discord',
hoverClasses: 'hover:text-indigo-400 hover:bg-indigo-400/10',
});
});
});
describe('formatMonthYear', () => {
it('should format date as "Jan 2026"', () => {
expect(ProfileFormatter.formatMonthYear('2026-01-15')).toBe('Jan 2026');
});
it('should format different months correctly', () => {
expect(ProfileFormatter.formatMonthYear('2026-02-15')).toBe('Feb 2026');
expect(ProfileFormatter.formatMonthYear('2026-12-25')).toBe('Dec 2026');
});
});
describe('formatMonthDayYear', () => {
it('should format date as "Jan 15, 2026"', () => {
expect(ProfileFormatter.formatMonthDayYear('2026-01-15')).toBe('Jan 15, 2026');
});
it('should format different dates correctly', () => {
expect(ProfileFormatter.formatMonthDayYear('2026-02-15')).toBe('Feb 15, 2026');
expect(ProfileFormatter.formatMonthDayYear('2026-12-25')).toBe('Dec 25, 2026');
});
});
describe('formatPercentage', () => {
it('should format decimal value as percentage with 1 decimal place', () => {
expect(ProfileFormatter.formatPercentage(0.1234)).toBe('12.3%');
expect(ProfileFormatter.formatPercentage(0.5)).toBe('50.0%');
expect(ProfileFormatter.formatPercentage(1.0)).toBe('100.0%');
});
it('should handle zero', () => {
expect(ProfileFormatter.formatPercentage(0)).toBe('0.0%');
});
it('should handle null', () => {
expect(ProfileFormatter.formatPercentage(null)).toBe('0.0%');
});
it('should handle undefined', () => {
expect(ProfileFormatter.formatPercentage(undefined)).toBe('0.0%');
});
});
describe('formatFinishPosition', () => {
it('should format position as "P1"', () => {
expect(ProfileFormatter.formatFinishPosition(1)).toBe('P1');
});
it('should format position as "P10"', () => {
expect(ProfileFormatter.formatFinishPosition(10)).toBe('P10');
});
it('should handle null value', () => {
expect(ProfileFormatter.formatFinishPosition(null)).toBe('P-');
});
it('should handle undefined value', () => {
expect(ProfileFormatter.formatFinishPosition(undefined)).toBe('P-');
});
});
describe('formatAvgFinish', () => {
it('should format average as "P5.4"', () => {
expect(ProfileFormatter.formatAvgFinish(5.4)).toBe('P5.4');
});
it('should format average as "P10.0"', () => {
expect(ProfileFormatter.formatAvgFinish(10.0)).toBe('P10.0');
});
it('should handle null value', () => {
expect(ProfileFormatter.formatAvgFinish(null)).toBe('P-');
});
it('should handle undefined value', () => {
expect(ProfileFormatter.formatAvgFinish(undefined)).toBe('P-');
});
});
describe('formatRating', () => {
it('should format rating as rounded number', () => {
expect(ProfileFormatter.formatRating(1234.56)).toBe('1235');
expect(ProfileFormatter.formatRating(1234.4)).toBe('1234');
});
it('should handle null value', () => {
expect(ProfileFormatter.formatRating(null)).toBe('0');
});
it('should handle undefined value', () => {
expect(ProfileFormatter.formatRating(undefined)).toBe('0');
});
});
describe('formatConsistency', () => {
it('should format consistency as percentage', () => {
expect(ProfileFormatter.formatConsistency(85)).toBe('85%');
expect(ProfileFormatter.formatConsistency(99.5)).toBe('100%');
});
it('should handle null value', () => {
expect(ProfileFormatter.formatConsistency(null)).toBe('0%');
});
it('should handle undefined value', () => {
expect(ProfileFormatter.formatConsistency(undefined)).toBe('0%');
});
});
describe('formatPercentile', () => {
it('should format percentile as "Top X%"', () => {
expect(ProfileFormatter.formatPercentile(5)).toBe('Top 5%');
expect(ProfileFormatter.formatPercentile(10)).toBe('Top 10%');
});
it('should handle null value', () => {
expect(ProfileFormatter.formatPercentile(null)).toBe('Top -%');
});
it('should handle undefined value', () => {
expect(ProfileFormatter.formatPercentile(undefined)).toBe('Top -%');
});
});
describe('getTeamRole', () => {
it('should return correct display data for owner role', () => {
const result = ProfileFormatter.getTeamRole('owner');
expect(result).toEqual({
text: 'Owner',
badgeClasses: 'bg-yellow-500/10 text-yellow-500 border-yellow-500/30',
});
});
it('should return correct display data for manager role', () => {
const result = ProfileFormatter.getTeamRole('manager');
expect(result).toEqual({
text: 'Manager',
badgeClasses: 'bg-blue-500/10 text-blue-400 border-blue-500/30',
});
});
it('should return correct display data for admin role', () => {
const result = ProfileFormatter.getTeamRole('admin');
expect(result).toEqual({
text: 'Admin',
badgeClasses: 'bg-purple-500/10 text-purple-400 border-purple-500/30',
});
});
it('should return correct display data for steward role', () => {
const result = ProfileFormatter.getTeamRole('steward');
expect(result).toEqual({
text: 'Steward',
badgeClasses: 'bg-blue-500/10 text-blue-400 border-blue-500/30',
});
});
it('should return correct display data for member role', () => {
const result = ProfileFormatter.getTeamRole('member');
expect(result).toEqual({
text: 'Member',
badgeClasses: 'bg-primary-blue/10 text-primary-blue border-primary-blue/30',
});
});
it('should default to member for unknown role', () => {
const result = ProfileFormatter.getTeamRole('unknown');
expect(result).toEqual({
text: 'Member',
badgeClasses: 'bg-primary-blue/10 text-primary-blue border-primary-blue/30',
});
});
});
});