-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathAbsenceForm.spec.js
More file actions
67 lines (53 loc) · 1.8 KB
/
Copy pathAbsenceForm.spec.js
File metadata and controls
67 lines (53 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { mount } from '@vue/test-utils'
import { afterEach, describe, expect, it, vi } from 'vitest'
import AbsenceForm from './AbsenceForm.vue'
let davAbsence
vi.mock('@nextcloud/initial-state', () => ({
loadState(app, key, fallback) {
if (app === 'dav' && key === 'absence' && davAbsence !== undefined) {
return davAbsence
}
if (fallback !== undefined) {
return fallback
}
console.error('Unexpected loadState call without fallback', { app, key })
throw new Error()
},
}))
afterEach(() => {
vi.unstubAllEnvs()
davAbsence = undefined
vi.resetModules()
})
function getInputs(wrapper) {
const lables = wrapper.findAll('label')
const firstDayLabel = lables.find((l) => l.text() === 'First day')
const firstDayInput = wrapper.get(`#${firstDayLabel.attributes('for')}`)
const lastDayLabel = lables.find((l) => l.text() === 'Last day (inclusive)')
const lastDayInput = wrapper.get(`#${lastDayLabel.attributes('for')}`)
return { firstDayInput, lastDayInput }
}
describe('AbsenceForm', () => {
it('displays default state when browser timezone is set', async () => {
vi.setSystemTime(new Date(2026, 5, 29, 5, 0))
vi.stubEnv('TZ', 'US/Pacific')
const wrapper = mount(AbsenceForm)
const { firstDayInput } = getInputs(wrapper)
expect(firstDayInput.element.value).toBe('2026-06-29')
})
it('displays state when browser timezone is set', async () => {
vi.stubEnv('TZ', 'US/Pacific')
davAbsence = {
firstDay: '2026-06-29',
lastDay: '2026-06-30',
}
const wrapper = mount(AbsenceForm)
const { firstDayInput, lastDayInput } = getInputs(wrapper)
expect(firstDayInput.element.value).toBe('2026-06-29')
expect(lastDayInput.element.value).toBe('2026-06-30')
})
})