test: adding some web tests (#27792)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { downloadFile, formatFileSize, formatNumber, formatTime } from './format'
|
||||
import { downloadFile, formatFileSize, formatNumber, formatNumberAbbreviated, formatTime } from './format'
|
||||
|
||||
describe('formatNumber', () => {
|
||||
test('should correctly format integers', () => {
|
||||
@@ -102,3 +102,95 @@ describe('downloadFile', () => {
|
||||
jest.restoreAllMocks()
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatNumberAbbreviated', () => {
|
||||
it('should return number as string when less than 1000', () => {
|
||||
expect(formatNumberAbbreviated(0)).toBe('0')
|
||||
expect(formatNumberAbbreviated(1)).toBe('1')
|
||||
expect(formatNumberAbbreviated(999)).toBe('999')
|
||||
})
|
||||
|
||||
it('should format thousands with k suffix', () => {
|
||||
expect(formatNumberAbbreviated(1000)).toBe('1k')
|
||||
expect(formatNumberAbbreviated(1200)).toBe('1.2k')
|
||||
expect(formatNumberAbbreviated(1500)).toBe('1.5k')
|
||||
expect(formatNumberAbbreviated(9999)).toBe('10k')
|
||||
})
|
||||
|
||||
it('should format millions with M suffix', () => {
|
||||
expect(formatNumberAbbreviated(1000000)).toBe('1M')
|
||||
expect(formatNumberAbbreviated(1500000)).toBe('1.5M')
|
||||
expect(formatNumberAbbreviated(2300000)).toBe('2.3M')
|
||||
expect(formatNumberAbbreviated(999999999)).toBe('1000M')
|
||||
})
|
||||
|
||||
it('should format billions with B suffix', () => {
|
||||
expect(formatNumberAbbreviated(1000000000)).toBe('1B')
|
||||
expect(formatNumberAbbreviated(1500000000)).toBe('1.5B')
|
||||
expect(formatNumberAbbreviated(2300000000)).toBe('2.3B')
|
||||
})
|
||||
|
||||
it('should remove .0 from whole numbers', () => {
|
||||
expect(formatNumberAbbreviated(1000)).toBe('1k')
|
||||
expect(formatNumberAbbreviated(2000000)).toBe('2M')
|
||||
expect(formatNumberAbbreviated(3000000000)).toBe('3B')
|
||||
})
|
||||
|
||||
it('should keep decimal for non-whole numbers', () => {
|
||||
expect(formatNumberAbbreviated(1100)).toBe('1.1k')
|
||||
expect(formatNumberAbbreviated(1500000)).toBe('1.5M')
|
||||
expect(formatNumberAbbreviated(2700000000)).toBe('2.7B')
|
||||
})
|
||||
|
||||
it('should handle edge cases', () => {
|
||||
expect(formatNumberAbbreviated(950)).toBe('950')
|
||||
expect(formatNumberAbbreviated(1001)).toBe('1k')
|
||||
expect(formatNumberAbbreviated(999999)).toBe('1000k')
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatNumber edge cases', () => {
|
||||
it('should handle very large numbers', () => {
|
||||
expect(formatNumber(1234567890123)).toBe('1,234,567,890,123')
|
||||
})
|
||||
|
||||
it('should handle numbers with many decimal places', () => {
|
||||
expect(formatNumber(1234.56789)).toBe('1,234.56789')
|
||||
})
|
||||
|
||||
it('should handle negative decimals', () => {
|
||||
expect(formatNumber(-1234.56)).toBe('-1,234.56')
|
||||
})
|
||||
|
||||
it('should handle string with decimals', () => {
|
||||
expect(formatNumber('9876543.21')).toBe('9,876,543.21')
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatFileSize edge cases', () => {
|
||||
it('should handle exactly 1024 bytes', () => {
|
||||
expect(formatFileSize(1024)).toBe('1.00 KB')
|
||||
})
|
||||
|
||||
it('should handle fractional bytes', () => {
|
||||
expect(formatFileSize(512.5)).toBe('512.50 bytes')
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatTime edge cases', () => {
|
||||
it('should handle exactly 60 seconds', () => {
|
||||
expect(formatTime(60)).toBe('1.00 min')
|
||||
})
|
||||
|
||||
it('should handle exactly 3600 seconds', () => {
|
||||
expect(formatTime(3600)).toBe('1.00 h')
|
||||
})
|
||||
|
||||
it('should handle fractional seconds', () => {
|
||||
expect(formatTime(45.5)).toBe('45.50 sec')
|
||||
})
|
||||
|
||||
it('should handle very large durations', () => {
|
||||
expect(formatTime(86400)).toBe('24.00 h') // 24 hours
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user