@oslokommune/punkt-elements 13.4.2 → 13.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/dist/calendar-32W9p9uc.cjs +115 -0
- package/dist/{calendar-DevQhOup.js → calendar-CJSxvwAq.js} +353 -340
- package/dist/{card-Dtw26f7i.js → card-BDz4RWxK.js} +1 -1
- package/dist/{card-BUITGoqX.cjs → card-DBlFf1ry.cjs} +1 -1
- package/dist/{datepicker-CYOn3tRm.js → datepicker-BJKJBoy_.js} +102 -59
- package/dist/datepicker-CmTrG5GE.cjs +164 -0
- package/dist/{heading-D6jXE_Mz.js → heading-Bdh9absf.js} +22 -22
- package/dist/heading-CNycsyMj.cjs +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/pkt-calendar.cjs +1 -1
- package/dist/pkt-calendar.js +1 -1
- package/dist/pkt-card.cjs +1 -1
- package/dist/pkt-card.js +1 -1
- package/dist/pkt-datepicker.cjs +1 -1
- package/dist/pkt-datepicker.js +1 -1
- package/dist/pkt-heading.cjs +1 -1
- package/dist/pkt-heading.js +1 -1
- package/dist/pkt-index.cjs +1 -1
- package/dist/pkt-index.js +5 -5
- package/package.json +3 -3
- package/src/components/calendar/calendar.accessibility.test.ts +111 -0
- package/src/components/calendar/calendar.constraints.test.ts +110 -0
- package/src/components/calendar/calendar.core.test.ts +367 -0
- package/src/components/calendar/calendar.interaction.test.ts +139 -0
- package/src/components/calendar/calendar.selection.test.ts +273 -0
- package/src/components/calendar/calendar.ts +74 -42
- package/src/components/card/card.test.ts +19 -5
- package/src/components/consent/consent.test.ts +436 -0
- package/src/components/datepicker/datepicker.accessibility.test.ts +193 -0
- package/src/components/datepicker/datepicker.core.test.ts +322 -0
- package/src/components/datepicker/datepicker.input.test.ts +268 -0
- package/src/components/datepicker/datepicker.selection.test.ts +286 -0
- package/src/components/datepicker/datepicker.ts +121 -19
- package/src/components/datepicker/datepicker.validation.test.ts +176 -0
- package/src/components/heading/heading.test.ts +458 -0
- package/src/components/heading/heading.ts +3 -0
- package/src/components/helptext/helptext.test.ts +474 -0
- package/dist/calendar-BZe2D4Sr.cjs +0 -108
- package/dist/datepicker-B9rhz_AF.cjs +0 -154
- package/dist/heading-BRE_iFtR.cjs +0 -1
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import '@testing-library/jest-dom'
|
|
2
|
+
import { fireEvent } from '@testing-library/dom'
|
|
3
|
+
import { parseISODateString } from '@/utils/dateutils'
|
|
4
|
+
|
|
5
|
+
import './calendar'
|
|
6
|
+
import { PktCalendar } from './calendar'
|
|
7
|
+
|
|
8
|
+
const waitForCustomElements = async () => {
|
|
9
|
+
await customElements.whenDefined('pkt-calendar')
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Helper function to create calendar markup
|
|
13
|
+
const createCalendar = async (calendarProps = '') => {
|
|
14
|
+
const container = document.createElement('div')
|
|
15
|
+
container.innerHTML = `
|
|
16
|
+
<pkt-calendar ${calendarProps}></pkt-calendar>
|
|
17
|
+
`
|
|
18
|
+
document.body.appendChild(container)
|
|
19
|
+
await waitForCustomElements()
|
|
20
|
+
return container
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Cleanup after each test
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
document.body.innerHTML = ''
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
describe('PktCalendar', () => {
|
|
29
|
+
describe('Rendering and basic functionality', () => {
|
|
30
|
+
test('renders without errors', async () => {
|
|
31
|
+
const container = await createCalendar()
|
|
32
|
+
|
|
33
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
34
|
+
expect(calendar).toBeInTheDocument()
|
|
35
|
+
|
|
36
|
+
await calendar.updateComplete
|
|
37
|
+
expect(calendar).toBeTruthy()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('renders with correct structure', async () => {
|
|
41
|
+
const container = await createCalendar()
|
|
42
|
+
|
|
43
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
44
|
+
await calendar.updateComplete
|
|
45
|
+
|
|
46
|
+
const calendarElement = calendar.querySelector('.pkt-calendar')
|
|
47
|
+
const calendarTable = calendar.querySelector('.pkt-cal-days')
|
|
48
|
+
const monthNav = calendar.querySelector('.pkt-cal-month-nav')
|
|
49
|
+
|
|
50
|
+
expect(calendarElement).toBeInTheDocument()
|
|
51
|
+
expect(calendarTable).toBeInTheDocument()
|
|
52
|
+
expect(monthNav).toBeInTheDocument()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
test('renders month picker when withcontrols is true', async () => {
|
|
56
|
+
const container = await createCalendar('withcontrols')
|
|
57
|
+
|
|
58
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
59
|
+
await calendar.updateComplete
|
|
60
|
+
|
|
61
|
+
// Navigation buttons should always be present
|
|
62
|
+
const prevButton = calendar.querySelector('.pkt-calendar__prev-month')
|
|
63
|
+
const nextButton = calendar.querySelector('.pkt-calendar__next-month')
|
|
64
|
+
expect(prevButton).toBeInTheDocument()
|
|
65
|
+
expect(nextButton).toBeInTheDocument()
|
|
66
|
+
|
|
67
|
+
// Should show month picker controls, not static title
|
|
68
|
+
const monthPicker = calendar.querySelector('.pkt-cal-month-picker')
|
|
69
|
+
const monthTitle = calendar.querySelector('.pkt-calendar__month-title')
|
|
70
|
+
|
|
71
|
+
expect(monthPicker).toBeInTheDocument()
|
|
72
|
+
expect(monthTitle).not.toBeInTheDocument()
|
|
73
|
+
|
|
74
|
+
// Should have month and year inputs
|
|
75
|
+
const monthSelect = monthPicker?.querySelector('select')
|
|
76
|
+
const yearInput = monthPicker?.querySelector('input[type="number"]')
|
|
77
|
+
expect(monthSelect).toBeInTheDocument()
|
|
78
|
+
expect(yearInput).toBeInTheDocument()
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
test('renders static month title when withcontrols is false', async () => {
|
|
82
|
+
const container = await createCalendar()
|
|
83
|
+
|
|
84
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
85
|
+
await calendar.updateComplete
|
|
86
|
+
|
|
87
|
+
// Navigation buttons should always be present
|
|
88
|
+
const prevButton = calendar.querySelector('.pkt-calendar__prev-month')
|
|
89
|
+
const nextButton = calendar.querySelector('.pkt-calendar__next-month')
|
|
90
|
+
expect(prevButton).toBeInTheDocument()
|
|
91
|
+
expect(nextButton).toBeInTheDocument()
|
|
92
|
+
|
|
93
|
+
// Should show static month title, not controls
|
|
94
|
+
const monthTitle = calendar.querySelector('.pkt-calendar__month-title')
|
|
95
|
+
const monthPicker = calendar.querySelector('.pkt-cal-month-picker')
|
|
96
|
+
|
|
97
|
+
expect(monthTitle).toBeInTheDocument()
|
|
98
|
+
expect(monthPicker).not.toBeInTheDocument()
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
describe('Properties and attributes', () => {
|
|
103
|
+
test('applies default properties correctly', async () => {
|
|
104
|
+
const container = await createCalendar()
|
|
105
|
+
|
|
106
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
107
|
+
await calendar.updateComplete
|
|
108
|
+
|
|
109
|
+
expect(calendar.multiple).toBe(false)
|
|
110
|
+
expect(calendar.range).toBe(false)
|
|
111
|
+
expect(calendar.weeknumbers).toBe(false)
|
|
112
|
+
expect(calendar.withcontrols).toBe(false)
|
|
113
|
+
expect(calendar.selected).toEqual([])
|
|
114
|
+
expect(calendar.earliest).toBe(null)
|
|
115
|
+
expect(calendar.latest).toBe(null)
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
test('handles multiple property correctly', async () => {
|
|
119
|
+
const container = await createCalendar('multiple')
|
|
120
|
+
|
|
121
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
122
|
+
await calendar.updateComplete
|
|
123
|
+
|
|
124
|
+
expect(calendar.multiple).toBe(true)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
test('handles range property correctly', async () => {
|
|
128
|
+
const container = await createCalendar('range')
|
|
129
|
+
|
|
130
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
131
|
+
await calendar.updateComplete
|
|
132
|
+
|
|
133
|
+
expect(calendar.range).toBe(true)
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
test('handles weeknumbers property correctly', async () => {
|
|
137
|
+
const container = await createCalendar('weeknumbers')
|
|
138
|
+
|
|
139
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
140
|
+
await calendar.updateComplete
|
|
141
|
+
|
|
142
|
+
expect(calendar.weeknumbers).toBe(true)
|
|
143
|
+
|
|
144
|
+
const weekNumbers = calendar.querySelectorAll('.pkt-calendar__week-number')
|
|
145
|
+
expect(weekNumbers.length).toBeGreaterThan(0)
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
test('handles maxMultiple property correctly', async () => {
|
|
149
|
+
const container = await createCalendar('multiple maxMultiple="3"')
|
|
150
|
+
|
|
151
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
152
|
+
await calendar.updateComplete
|
|
153
|
+
|
|
154
|
+
expect(calendar.maxMultiple).toBe(3)
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
test('handles currentmonth property correctly', async () => {
|
|
158
|
+
const testDate = '2024-03-15'
|
|
159
|
+
const container = await createCalendar(`currentmonth="${testDate}"`)
|
|
160
|
+
|
|
161
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
162
|
+
await calendar.updateComplete
|
|
163
|
+
|
|
164
|
+
expect(calendar.currentmonth).toEqual(parseISODateString(testDate))
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
describe('Month navigation', () => {
|
|
169
|
+
it('should navigate to previous month when clicking previous button', async () => {
|
|
170
|
+
const calendar = document.createElement('pkt-calendar') as PktCalendar
|
|
171
|
+
document.body.appendChild(calendar)
|
|
172
|
+
await waitForCustomElements()
|
|
173
|
+
|
|
174
|
+
const navElement = calendar.querySelector('.pkt-cal-month-nav')
|
|
175
|
+
const prevButton = navElement?.querySelector('button')
|
|
176
|
+
|
|
177
|
+
expect(prevButton).toBeInTheDocument()
|
|
178
|
+
|
|
179
|
+
const initialMonth = calendar.currentmonth!.getMonth()
|
|
180
|
+
const initialYear = calendar.currentmonth!.getFullYear()
|
|
181
|
+
fireEvent.click(prevButton!)
|
|
182
|
+
await calendar.updateComplete
|
|
183
|
+
|
|
184
|
+
// Should go to previous month (or December of previous year if we're in January)
|
|
185
|
+
if (initialMonth === 0) {
|
|
186
|
+
expect(calendar.currentmonth!.getMonth()).toBe(11)
|
|
187
|
+
expect(calendar.currentmonth!.getFullYear()).toBe(initialYear - 1)
|
|
188
|
+
} else {
|
|
189
|
+
expect(calendar.currentmonth!.getMonth()).toBe(initialMonth - 1)
|
|
190
|
+
expect(calendar.currentmonth!.getFullYear()).toBe(initialYear)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
document.body.removeChild(calendar)
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
it('should navigate to next month when clicking next button', async () => {
|
|
197
|
+
const calendar = document.createElement('pkt-calendar') as PktCalendar
|
|
198
|
+
document.body.appendChild(calendar)
|
|
199
|
+
await waitForCustomElements()
|
|
200
|
+
|
|
201
|
+
const navElement = calendar.querySelector('.pkt-cal-month-nav')
|
|
202
|
+
const buttons = navElement?.querySelectorAll('button')
|
|
203
|
+
const nextButton = buttons?.[1] // Second button is next
|
|
204
|
+
|
|
205
|
+
expect(nextButton).toBeInTheDocument()
|
|
206
|
+
|
|
207
|
+
const initialMonth = calendar.currentmonth!.getMonth()
|
|
208
|
+
const initialYear = calendar.currentmonth!.getFullYear()
|
|
209
|
+
fireEvent.click(nextButton!)
|
|
210
|
+
await calendar.updateComplete
|
|
211
|
+
|
|
212
|
+
// Should go to next month (or January of next year if we're in December)
|
|
213
|
+
if (initialMonth === 11) {
|
|
214
|
+
expect(calendar.currentmonth!.getMonth()).toBe(0)
|
|
215
|
+
expect(calendar.currentmonth!.getFullYear()).toBe(initialYear + 1)
|
|
216
|
+
} else {
|
|
217
|
+
expect(calendar.currentmonth!.getMonth()).toBe(initialMonth + 1)
|
|
218
|
+
expect(calendar.currentmonth!.getFullYear()).toBe(initialYear)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
document.body.removeChild(calendar)
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
test('navigates to next month', async () => {
|
|
225
|
+
const container = await createCalendar('withcontrols currentmonth="2024-06-15"')
|
|
226
|
+
|
|
227
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
228
|
+
await calendar.updateComplete
|
|
229
|
+
|
|
230
|
+
const nextButton = calendar.querySelector('.pkt-calendar__next-month')
|
|
231
|
+
expect(nextButton).toBeInTheDocument()
|
|
232
|
+
|
|
233
|
+
// With controls=true, check the month select dropdown instead of title
|
|
234
|
+
const monthSelect = calendar.querySelector(
|
|
235
|
+
'.pkt-cal-month-picker select',
|
|
236
|
+
) as HTMLSelectElement
|
|
237
|
+
const initialMonth = monthSelect?.value
|
|
238
|
+
|
|
239
|
+
fireEvent.click(nextButton!)
|
|
240
|
+
await calendar.updateComplete
|
|
241
|
+
|
|
242
|
+
const newMonth = monthSelect?.value
|
|
243
|
+
expect(newMonth).not.toBe(initialMonth)
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
test('month navigation updates visible dates', async () => {
|
|
247
|
+
const container = await createCalendar('withcontrols currentmonth="2024-06-15"')
|
|
248
|
+
|
|
249
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
250
|
+
await calendar.updateComplete
|
|
251
|
+
|
|
252
|
+
const initialDates = Array.from(calendar.querySelectorAll('.pkt-calendar__date')).map(
|
|
253
|
+
(el) => el.textContent,
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
const nextButton = calendar.querySelector('.pkt-calendar__next-month')
|
|
257
|
+
fireEvent.click(nextButton!)
|
|
258
|
+
await calendar.updateComplete
|
|
259
|
+
|
|
260
|
+
const newDates = Array.from(calendar.querySelectorAll('.pkt-calendar__date')).map(
|
|
261
|
+
(el) => el.textContent,
|
|
262
|
+
)
|
|
263
|
+
expect(newDates).not.toEqual(initialDates)
|
|
264
|
+
})
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
describe('Date formatting and localization', () => {
|
|
268
|
+
test('displays day names correctly', async () => {
|
|
269
|
+
const container = await createCalendar()
|
|
270
|
+
|
|
271
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
272
|
+
await calendar.updateComplete
|
|
273
|
+
|
|
274
|
+
const dayHeaders = calendar.querySelectorAll('.pkt-calendar__day-name')
|
|
275
|
+
expect(dayHeaders.length).toBe(7)
|
|
276
|
+
|
|
277
|
+
// Check that day names are displayed
|
|
278
|
+
dayHeaders.forEach((header) => {
|
|
279
|
+
expect(header.textContent).toBeTruthy()
|
|
280
|
+
expect(header.textContent!.length).toBeGreaterThan(0)
|
|
281
|
+
})
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
test('displays month names correctly', async () => {
|
|
285
|
+
const container = await createCalendar('currentmonth="2024-06-15"')
|
|
286
|
+
|
|
287
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
288
|
+
await calendar.updateComplete
|
|
289
|
+
|
|
290
|
+
const monthTitle = calendar.querySelector('.pkt-calendar__month-title')
|
|
291
|
+
expect(monthTitle).toBeInTheDocument()
|
|
292
|
+
expect(monthTitle?.textContent).toBeTruthy()
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
test('handles custom day strings', async () => {
|
|
296
|
+
const container = await createCalendar()
|
|
297
|
+
|
|
298
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
299
|
+
|
|
300
|
+
// Set custom day strings
|
|
301
|
+
calendar.dayStrings = ['S', 'M', 'T', 'W', 'T', 'F', 'S']
|
|
302
|
+
await calendar.updateComplete
|
|
303
|
+
|
|
304
|
+
const dayHeaders = calendar.querySelectorAll('.pkt-calendar__day-name')
|
|
305
|
+
expect(dayHeaders[0].textContent?.trim()).toBe('S')
|
|
306
|
+
expect(dayHeaders[1].textContent?.trim()).toBe('M')
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
test('handles custom month strings', async () => {
|
|
310
|
+
const container = await createCalendar('withcontrols')
|
|
311
|
+
|
|
312
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
313
|
+
|
|
314
|
+
// Set custom month strings
|
|
315
|
+
calendar.monthStrings = [
|
|
316
|
+
'Jan',
|
|
317
|
+
'Feb',
|
|
318
|
+
'Mar',
|
|
319
|
+
'Apr',
|
|
320
|
+
'May',
|
|
321
|
+
'Jun',
|
|
322
|
+
'Jul',
|
|
323
|
+
'Aug',
|
|
324
|
+
'Sep',
|
|
325
|
+
'Oct',
|
|
326
|
+
'Nov',
|
|
327
|
+
'Dec',
|
|
328
|
+
]
|
|
329
|
+
await calendar.updateComplete
|
|
330
|
+
|
|
331
|
+
// When withcontrols=true, check the month select dropdown instead of title
|
|
332
|
+
const monthSelect = calendar.querySelector('.pkt-cal-month-picker select')
|
|
333
|
+
expect(monthSelect).toBeInTheDocument()
|
|
334
|
+
|
|
335
|
+
// Check that the custom month string appears in the dropdown options
|
|
336
|
+
const options = monthSelect?.querySelectorAll('option')
|
|
337
|
+
expect(options?.[0]?.textContent).toContain('Jan')
|
|
338
|
+
})
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
describe('Today highlighting', () => {
|
|
342
|
+
test('highlights today date', async () => {
|
|
343
|
+
const container = await createCalendar()
|
|
344
|
+
|
|
345
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
346
|
+
await calendar.updateComplete
|
|
347
|
+
|
|
348
|
+
const todayDate = calendar.querySelector('.pkt-calendar__date--today')
|
|
349
|
+
expect(todayDate).toBeInTheDocument()
|
|
350
|
+
})
|
|
351
|
+
|
|
352
|
+
test('today date is selectable unless excluded', async () => {
|
|
353
|
+
const container = await createCalendar()
|
|
354
|
+
|
|
355
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
356
|
+
await calendar.updateComplete
|
|
357
|
+
|
|
358
|
+
const todayDate = calendar.querySelector('.pkt-calendar__date--today')
|
|
359
|
+
|
|
360
|
+
if (todayDate && !todayDate.classList.contains('pkt-calendar__date--disabled')) {
|
|
361
|
+
fireEvent.click(todayDate)
|
|
362
|
+
await calendar.updateComplete
|
|
363
|
+
expect(todayDate).toHaveClass('pkt-calendar__date--selected')
|
|
364
|
+
}
|
|
365
|
+
})
|
|
366
|
+
})
|
|
367
|
+
})
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import '@testing-library/jest-dom'
|
|
2
|
+
import { fireEvent } from '@testing-library/dom'
|
|
3
|
+
|
|
4
|
+
import './calendar'
|
|
5
|
+
import { PktCalendar } from './calendar'
|
|
6
|
+
|
|
7
|
+
const waitForCustomElements = async () => {
|
|
8
|
+
await customElements.whenDefined('pkt-calendar')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Helper function to create calendar markup
|
|
12
|
+
const createCalendar = async (calendarProps = '') => {
|
|
13
|
+
const container = document.createElement('div')
|
|
14
|
+
container.innerHTML = `
|
|
15
|
+
<pkt-calendar ${calendarProps}></pkt-calendar>
|
|
16
|
+
`
|
|
17
|
+
document.body.appendChild(container)
|
|
18
|
+
await waitForCustomElements()
|
|
19
|
+
return container
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Cleanup after each test
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
document.body.innerHTML = ''
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
describe('PktCalendar', () => {
|
|
28
|
+
describe('Keyboard navigation', () => {
|
|
29
|
+
test('handles arrow key navigation', async () => {
|
|
30
|
+
const container = await createCalendar()
|
|
31
|
+
|
|
32
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
33
|
+
await calendar.updateComplete
|
|
34
|
+
|
|
35
|
+
const firstDate = calendar.querySelector(
|
|
36
|
+
'.pkt-calendar__date:not(.pkt-calendar__date--disabled)',
|
|
37
|
+
) as HTMLElement
|
|
38
|
+
firstDate?.focus()
|
|
39
|
+
|
|
40
|
+
// Test right arrow
|
|
41
|
+
fireEvent.keyDown(firstDate!, { key: 'ArrowRight' })
|
|
42
|
+
await calendar.updateComplete
|
|
43
|
+
|
|
44
|
+
// Check that focus moved (implementation dependent)
|
|
45
|
+
expect(document.activeElement).toBeTruthy()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('handles enter key for date selection', async () => {
|
|
49
|
+
const container = await createCalendar()
|
|
50
|
+
|
|
51
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
52
|
+
await calendar.updateComplete
|
|
53
|
+
|
|
54
|
+
const firstDate = calendar.querySelector(
|
|
55
|
+
'.pkt-calendar__date:not(.pkt-calendar__date--disabled)',
|
|
56
|
+
) as HTMLElement
|
|
57
|
+
firstDate?.focus()
|
|
58
|
+
|
|
59
|
+
fireEvent.keyDown(firstDate!, { key: 'Enter' })
|
|
60
|
+
await calendar.updateComplete
|
|
61
|
+
|
|
62
|
+
expect(firstDate).toHaveClass('pkt-calendar__date--selected')
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test('handles escape key', async () => {
|
|
66
|
+
const container = await createCalendar()
|
|
67
|
+
|
|
68
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
69
|
+
await calendar.updateComplete
|
|
70
|
+
|
|
71
|
+
fireEvent.keyDown(calendar, { key: 'Escape' })
|
|
72
|
+
await calendar.updateComplete
|
|
73
|
+
|
|
74
|
+
// Should trigger close event if inside a datepicker
|
|
75
|
+
expect(calendar).toBeInTheDocument()
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
describe('Edge cases and error handling', () => {
|
|
80
|
+
test('handles invalid date formats gracefully', async () => {
|
|
81
|
+
const container = await createCalendar('earliest="invalid-date" latest="also-invalid"')
|
|
82
|
+
|
|
83
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
84
|
+
await calendar.updateComplete
|
|
85
|
+
|
|
86
|
+
// Should not crash and render normally
|
|
87
|
+
expect(calendar).toBeInTheDocument()
|
|
88
|
+
const calendarBody = calendar.querySelector('.pkt-calendar__body')
|
|
89
|
+
expect(calendarBody).toBeInTheDocument()
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
test('handles empty selected dates array', async () => {
|
|
93
|
+
const container = await createCalendar('selected=""')
|
|
94
|
+
|
|
95
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
96
|
+
await calendar.updateComplete
|
|
97
|
+
|
|
98
|
+
expect(calendar.selected).toEqual([])
|
|
99
|
+
const selectedDates = calendar.querySelectorAll('.pkt-calendar__date--selected')
|
|
100
|
+
expect(selectedDates.length).toBe(0)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
test('handles conflicting properties gracefully', async () => {
|
|
104
|
+
// Both multiple and range shouldn't typically be used together
|
|
105
|
+
const container = await createCalendar('multiple range')
|
|
106
|
+
|
|
107
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
108
|
+
await calendar.updateComplete
|
|
109
|
+
|
|
110
|
+
expect(calendar.multiple).toBe(true)
|
|
111
|
+
expect(calendar.range).toBe(true)
|
|
112
|
+
|
|
113
|
+
// Should still render without errors
|
|
114
|
+
expect(calendar).toBeInTheDocument()
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
test('handles very early dates', async () => {
|
|
118
|
+
const container = await createCalendar('currentmonth="1900-01-01"')
|
|
119
|
+
|
|
120
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
121
|
+
await calendar.updateComplete
|
|
122
|
+
|
|
123
|
+
expect(calendar).toBeInTheDocument()
|
|
124
|
+
const calendarBody = calendar.querySelector('.pkt-calendar__body')
|
|
125
|
+
expect(calendarBody).toBeInTheDocument()
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
test('handles far future dates', async () => {
|
|
129
|
+
const container = await createCalendar('currentmonth="2100-12-31"')
|
|
130
|
+
|
|
131
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
132
|
+
await calendar.updateComplete
|
|
133
|
+
|
|
134
|
+
expect(calendar).toBeInTheDocument()
|
|
135
|
+
const calendarBody = calendar.querySelector('.pkt-calendar__body')
|
|
136
|
+
expect(calendarBody).toBeInTheDocument()
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
})
|