|
8 | 8 | import * as apiRequests from './api/request';
|
9 | 9 | import {
|
10 | 10 | formatForDisplay,
|
| 11 | + formatNotificationUpdatedAt, |
11 | 12 | generateGitHubWebUrl,
|
12 | 13 | generateNotificationReferrerId,
|
13 | 14 | isEnterpriseHost,
|
@@ -534,5 +535,47 @@ describe('utils/helpers.ts', () => {
|
534 | 535 | 'Not Planned Issue',
|
535 | 536 | );
|
536 | 537 | });
|
| 538 | + |
| 539 | + describe('formatNotificationUpdatedAt', () => { |
| 540 | + it('should use last_read_at if available', () => { |
| 541 | + const notification = { |
| 542 | + ...mockSingleNotification, |
| 543 | + last_read_at: '2021-06-23T16:00:00Z', |
| 544 | + updated_at: '2021-06-23T17:00:00Z', |
| 545 | + }; |
| 546 | + |
| 547 | + expect(formatNotificationUpdatedAt(notification)).toContain('ago'); |
| 548 | + }); |
| 549 | + |
| 550 | + it('should use updated_at if last_read_at is null', () => { |
| 551 | + const notification = { |
| 552 | + ...mockSingleNotification, |
| 553 | + last_read_at: null, |
| 554 | + updated_at: '2021-06-23T17:00:00Z', |
| 555 | + }; |
| 556 | + |
| 557 | + expect(formatNotificationUpdatedAt(notification)).toContain('ago'); |
| 558 | + }); |
| 559 | + |
| 560 | + it('should return empty if all dates are null', () => { |
| 561 | + const notification = { |
| 562 | + ...mockSingleNotification, |
| 563 | + last_read_at: null, |
| 564 | + updated_at: null, |
| 565 | + }; |
| 566 | + |
| 567 | + expect(formatNotificationUpdatedAt(notification)).toBe(''); |
| 568 | + }); |
| 569 | + |
| 570 | + it('should return empty if unable to parse dates', () => { |
| 571 | + const notification = { |
| 572 | + ...mockSingleNotification, |
| 573 | + last_read_at: 'not an iso date', |
| 574 | + updated_at: 'not an iso date', |
| 575 | + }; |
| 576 | + |
| 577 | + expect(formatNotificationUpdatedAt(notification)).toBe(''); |
| 578 | + }); |
| 579 | + }); |
537 | 580 | });
|
538 | 581 | });
|
0 commit comments