Files
gridpilot.gg/apps/website/lib/formatters/RatingTrendFormatter.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

63 lines
2.5 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { RatingTrendFormatter } from './RatingTrendFormatter';
describe('RatingTrendFormatter', () => {
describe('getTrend', () => {
it('should return "up" when current rating is higher than previous', () => {
expect(RatingTrendFormatter.getTrend(1200, 1100)).toBe('up');
expect(RatingTrendFormatter.getTrend(1500, 1400)).toBe('up');
});
it('should return "down" when current rating is lower than previous', () => {
expect(RatingTrendFormatter.getTrend(1100, 1200)).toBe('down');
expect(RatingTrendFormatter.getTrend(1400, 1500)).toBe('down');
});
it('should return "same" when current rating equals previous', () => {
expect(RatingTrendFormatter.getTrend(1200, 1200)).toBe('same');
});
it('should return "same" when previous rating is undefined', () => {
expect(RatingTrendFormatter.getTrend(1200, undefined)).toBe('same');
});
it('should return "same" when previous rating is null', () => {
expect(RatingTrendFormatter.getTrend(1200, null)).toBe('same');
});
});
describe('getChangeIndicator', () => {
it('should return "+X" when current rating is higher than previous', () => {
expect(RatingTrendFormatter.getChangeIndicator(1200, 1100)).toBe('+100');
expect(RatingTrendFormatter.getChangeIndicator(1500, 1400)).toBe('+100');
});
it('should return "-X" when current rating is lower than previous', () => {
expect(RatingTrendFormatter.getChangeIndicator(1100, 1200)).toBe('-100');
expect(RatingTrendFormatter.getChangeIndicator(1400, 1500)).toBe('-100');
});
it('should return "0" when current rating equals previous', () => {
expect(RatingTrendFormatter.getChangeIndicator(1200, 1200)).toBe('0');
});
it('should return "0" when previous rating is undefined', () => {
expect(RatingTrendFormatter.getChangeIndicator(1200, undefined)).toBe('0');
});
it('should return "0" when previous rating is null', () => {
expect(RatingTrendFormatter.getChangeIndicator(1200, null)).toBe('0');
});
it('should handle small changes', () => {
expect(RatingTrendFormatter.getChangeIndicator(1201, 1200)).toBe('+1');
expect(RatingTrendFormatter.getChangeIndicator(1199, 1200)).toBe('-1');
});
it('should handle large changes', () => {
expect(RatingTrendFormatter.getChangeIndicator(2000, 1000)).toBe('+1000');
expect(RatingTrendFormatter.getChangeIndicator(1000, 2000)).toBe('-1000');
});
});
});