fix(tests): Adjust tests to also mock Date contructor

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2024-02-03 21:40:07 +01:00
Родитель ff5b9c3731
Коммит 6d5754985a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 45FAE7268762B400
1 изменённых файлов: 4 добавлений и 6 удалений

Просмотреть файл

@ -33,8 +33,8 @@ const realDateNow = Date.now
beforeAll(() => {
vi.useFakeTimers()
vi.setSystemTime(currentDate)
window.document.head.setAttribute('data-user', 'admin')
window.Date.now = vi.fn(() => currentDate.getTime())
})
afterAll(() => {
@ -51,18 +51,16 @@ const expectLinkWithText = (wrapper, text) => {
test('Display relative date gets updated every minutes', async () => {
const wrapper = mount(Activity, { propsData: { activity: new ActivityModel(wsData.ocs.data[1]), showPreviews: true } })
expect(wrapper.text()).toContain('You renamed Test file - renamed.md to Test file - renamed - looooooooong.md')
await nextTick()
expect(wrapper.text()).toContain('You renamed Test file - renamed.md to Test file - renamed - looooooooong.md')
expect(wrapper.find('[data-testid="activity-date"]').text()).toContain('3 days ago')
const currentDatePlusOneDay = new Date('2021-05-03T12:00:00+00:00')
window.Date.now = vi.fn(() => currentDatePlusOneDay.getTime())
vi.setSystemTime(currentDatePlusOneDay)
vi.advanceTimersByTime(60 * 1000)
await nextTick()
expect(wrapper.find('[data-testid="activity-date"]').text()).toContain('4 days ago')
window.Date.now = vi.fn(() => currentDate.getTime())
})
test('Display correct information for renames', async () => {