You've already forked tf2wikipricing
refactor: split currency and key/metal formatting into separate units
this simplifies functions and tests, and will make currency optional/variable later
This commit is contained in:
@@ -16,34 +16,34 @@ describe('formatPrice', () => {
|
||||
});
|
||||
|
||||
test('formats price with keys and metal', () => {
|
||||
expect(formatPrice(2, 10, 50)).toBe('2.2 keys (US$5.50)');
|
||||
expect(formatPrice(2, 10, 50)).toBe('2.2 keys');
|
||||
expect($T).toHaveBeenCalledWith('%@ keys');
|
||||
});
|
||||
|
||||
test('formats price with metal only', () => {
|
||||
expect(formatPrice(0, 15.75, 50)).toBe('15.75 ref (US$0.79)');
|
||||
expect(formatPrice(0, 15.75, 50)).toBe('15.75 ref');
|
||||
});
|
||||
|
||||
test('formats price with metal only and whole number', () => {
|
||||
expect(formatPrice(0, 3, 50)).toBe('3 ref (US$0.16)');
|
||||
expect(formatPrice(0, 3, 50)).toBe('3 ref');
|
||||
});
|
||||
|
||||
test('uses singular key form', () => {
|
||||
expect(formatPrice(1, 0, 50)).toBe('1 key (US$2.50)');
|
||||
expect(formatPrice(1, 0, 50)).toBe('1 key');
|
||||
expect($T).toHaveBeenCalledWith('%@ key');
|
||||
});
|
||||
|
||||
test('rounds USD up to nearest cent', () => {
|
||||
expect(formatPrice(3, 7.33, 35)).toBe('3.21 keys (US$5.62)'); // (3 * 35 + 7.33) * 0.05 = 5.6165 → 5.62
|
||||
expect(formatPrice(3, 7.33, 35)).toBe('3.21 keys'); // (3 * 35 + 7.33) * 0.05 = 5.6165 → 5.62
|
||||
});
|
||||
|
||||
test('handles different locale formatting', () => {
|
||||
expect(formatPrice(2, 10, 50, 'de')).toMatch(/2,2 keys \(US\$5,50\)/);
|
||||
expect(formatPrice(0, 15.75, 50, 'de')).toMatch(/15,75 ref \(US\$0,79\)/);
|
||||
expect(formatPrice(2, 10, 50, 'de')).toMatch(/2,2 keys/);
|
||||
expect(formatPrice(0, 15.75, 50, 'de')).toMatch(/15,75 ref/);
|
||||
});
|
||||
|
||||
test('handles zero values', () => {
|
||||
expect(formatPrice(0, 0, 50)).toBe('0 ref (US$0.00)');
|
||||
expect(formatPrice(0, 0, 50, 'de')).toMatch(/0 ref \(US\$0,00\)/);
|
||||
expect(formatPrice(0, 0, 50)).toBe('0 ref');
|
||||
expect(formatPrice(0, 0, 50, 'de')).toMatch(/0 ref/);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user