-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c57185
commit bd6f100
Showing
4 changed files
with
82 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...tend/src/features/PriorNotification/components/shared/EditHistory/__tests__/utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { isDateCloseTo } from '@features/PriorNotification/components/shared/EditHistory/utils' | ||
import { describe, expect, it } from '@jest/globals' | ||
import dayjs from 'dayjs' | ||
|
||
describe('features/PriorNotificationList/shared/EditHistory/utils', () => { | ||
it('isDateCloseTo() should return true when dates are within the threshold', () => { | ||
// Given | ||
const leftDate = dayjs('2024-01-01T10:00:00') | ||
const rightDate = dayjs('2024-01-01T10:00:10') | ||
const thresholdInSeconds = 10 | ||
|
||
// When Then | ||
expect(isDateCloseTo(leftDate, rightDate, thresholdInSeconds)).toBe(true) | ||
}) | ||
|
||
it('isDateCloseTo() should return false when dates exceed the threshold', () => { | ||
// Given | ||
const leftDate = dayjs('2024-01-01T10:00:00') | ||
const rightDate = dayjs('2024-01-01T10:01:00') | ||
const thresholdInSeconds = 30 | ||
|
||
// When Then | ||
expect(isDateCloseTo(leftDate, rightDate, thresholdInSeconds)).toBe(false) | ||
}) | ||
|
||
it('isDateCloseTo() should handle different date formats (string, Date, Dayjs) and return true for close dates', () => { | ||
// Given | ||
const leftDate = '2024-01-01T10:00:00' | ||
const rightDate = new Date('2024-01-01T10:00:05') | ||
const thresholdInSeconds = 10 | ||
|
||
// When Then | ||
expect(isDateCloseTo(leftDate, rightDate, thresholdInSeconds)).toBe(true) | ||
}) | ||
|
||
it('isDateCloseTo() should handle different date formats (string, Date, Dayjs) and return false for far dates', () => { | ||
// Given | ||
const leftDate = new Date('2024-01-01T10:00:00') | ||
const rightDate = dayjs('2024-01-01T10:01:00') | ||
const thresholdInSeconds = 30 | ||
|
||
// When Then | ||
expect(isDateCloseTo(leftDate, rightDate, thresholdInSeconds)).toBe(false) | ||
}) | ||
|
||
it('isDateCloseTo() should return true when dates are exactly at the threshold limit', () => { | ||
// Given | ||
const leftDate = dayjs('2024-01-01T10:00:00') | ||
const rightDate = dayjs('2024-01-01T10:01:00') | ||
const thresholdInSeconds = 60 | ||
|
||
// When Then | ||
expect(isDateCloseTo(leftDate, rightDate, thresholdInSeconds)).toBe(true) | ||
}) | ||
|
||
it('isDateCloseTo() should return true for identical dates with any threshold', () => { | ||
// Given | ||
const date = dayjs('2024-01-01T10:00:00') | ||
const thresholdInSeconds = 0 | ||
|
||
// When Then | ||
expect(isDateCloseTo(date, date, thresholdInSeconds)).toBe(true) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters