|
| 1 | +import {getNextDeprecationDate, setNextDeprecationDate} from './deprecations-store.js' |
| 2 | +import {describe, test, expect} from 'vitest' |
| 3 | + |
| 4 | +describe('deprecations-store', () => { |
| 5 | + test('getNextDeprecationDate returns undefined by default', () => { |
| 6 | + expect(getNextDeprecationDate()).toBeUndefined() |
| 7 | + }) |
| 8 | + |
| 9 | + test('setNextDeprecationDate does not update store when given empty dates list', () => { |
| 10 | + setNextDeprecationDate([]) |
| 11 | + expect(getNextDeprecationDate()).toBeUndefined() |
| 12 | + }) |
| 13 | + |
| 14 | + test('setNextDeprecationDate does not update store when dates are in the past', () => { |
| 15 | + const pastDate = new Date(Date.now() - 100000) |
| 16 | + setNextDeprecationDate([pastDate]) |
| 17 | + expect(getNextDeprecationDate()).toBeUndefined() |
| 18 | + }) |
| 19 | + |
| 20 | + test('setNextDeprecationDate sets earliest future deprecation date', () => { |
| 21 | + const futureDate1 = new Date(Date.now() + 500000) |
| 22 | + const futureDate2 = new Date(Date.now() + 600000) |
| 23 | + |
| 24 | + setNextDeprecationDate([futureDate2, futureDate1]) |
| 25 | + |
| 26 | + expect(getNextDeprecationDate()).toEqual(futureDate1) |
| 27 | + }) |
| 28 | + |
| 29 | + test('setNextDeprecationDate updates store if a newer date is earlier than existing nextDeprecationDate', () => { |
| 30 | + const initialFutureDate = new Date(Date.now() + 400000) |
| 31 | + setNextDeprecationDate([initialFutureDate]) |
| 32 | + |
| 33 | + const earlierFutureDate = new Date(Date.now() + 300000) |
| 34 | + setNextDeprecationDate([earlierFutureDate]) |
| 35 | + |
| 36 | + expect(getNextDeprecationDate()).toEqual(earlierFutureDate) |
| 37 | + }) |
| 38 | + |
| 39 | + test('setNextDeprecationDate keeps existing date if new future dates are later', () => { |
| 40 | + const initialFutureDate = new Date(Date.now() + 100000) |
| 41 | + setNextDeprecationDate([initialFutureDate]) |
| 42 | + |
| 43 | + const laterFutureDate = new Date(Date.now() + 200000) |
| 44 | + setNextDeprecationDate([laterFutureDate]) |
| 45 | + |
| 46 | + expect(getNextDeprecationDate()).toEqual(initialFutureDate) |
| 47 | + }) |
| 48 | +}) |
0 commit comments