|
1 | | -import { getTimeLeftForTokenExpiration } from './date'; |
| 1 | +import { getTimeLeftForTokenExpiration, displayFormattedDate } from './date'; |
| 2 | + |
| 3 | +describe('displayFormattedDate', () => { |
| 4 | + test('returns empty string for null', () => { |
| 5 | + expect(displayFormattedDate(null as unknown as string)).toBe(''); |
| 6 | + }); |
| 7 | + |
| 8 | + test('returns empty string for undefined', () => { |
| 9 | + expect(displayFormattedDate(undefined as unknown as string)).toBe(''); |
| 10 | + }); |
| 11 | + |
| 12 | + test('returns empty string for empty string', () => { |
| 13 | + expect(displayFormattedDate('')).toBe(''); |
| 14 | + }); |
| 15 | + |
| 16 | + test('returns empty string for invalid date string', () => { |
| 17 | + expect(displayFormattedDate('not-a-date')).toBe(''); |
| 18 | + }); |
| 19 | + |
| 20 | + test('returns formatted string for valid ISO date', () => { |
| 21 | + const result = displayFormattedDate('2023-01-01T12:00:00Z'); |
| 22 | + // Format manually to match expected UTC time |
| 23 | + expect(result).toBe( |
| 24 | + new Intl.DateTimeFormat('en-US', { |
| 25 | + dateStyle: 'medium', |
| 26 | + timeStyle: 'short', |
| 27 | + timeZone: 'UTC', |
| 28 | + }).format(new Date('2023-01-01T12:00:00Z')), |
| 29 | + ); |
| 30 | + }); |
| 31 | + |
| 32 | + test('returns formatted string for valid date-only string', () => { |
| 33 | + const result = displayFormattedDate('2023-01-01'); |
| 34 | + expect(result).toBe( |
| 35 | + new Intl.DateTimeFormat('en-US', { |
| 36 | + dateStyle: 'medium', |
| 37 | + timeStyle: 'short', |
| 38 | + timeZone: 'UTC', |
| 39 | + }).format(new Date('2023-01-01')), |
| 40 | + ); |
| 41 | + }); |
| 42 | + |
| 43 | + test('returns formatted string for ISO with timezone offset', () => { |
| 44 | + const result = displayFormattedDate('2023-01-01T12:00:00-05:00'); |
| 45 | + expect(result).toBe( |
| 46 | + new Intl.DateTimeFormat('en-US', { |
| 47 | + dateStyle: 'medium', |
| 48 | + timeStyle: 'short', |
| 49 | + timeZone: 'UTC', |
| 50 | + }).format(new Date('2023-01-01T12:00:00-05:00')), |
| 51 | + ); |
| 52 | + }); |
| 53 | +}); |
2 | 54 |
|
3 | 55 | describe('getTimeLeftForTokenExpiration', () => { |
4 | 56 | const nowHours = 12; |
|
0 commit comments