formatter tests
Some checks failed
Some checks failed
This commit is contained in:
62
apps/website/lib/formatters/RatingTrendFormatter.test.ts
Normal file
62
apps/website/lib/formatters/RatingTrendFormatter.test.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user