@oslokommune/punkt-elements 13.5.2 → 13.5.4

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/{alert-DQNBDKjT.cjs → alert-7rUOhlNi.cjs} +2 -1
  3. package/dist/{alert-B07oUpkq.js → alert-cUBtwi2k.js} +12 -11
  4. package/dist/{loader-CHPxY9c6.cjs → loader-DNidjwH-.cjs} +6 -1
  5. package/dist/{loader-Da4IOk_T.js → loader-h3d-3D7s.js} +6 -1
  6. package/dist/{messagebox-DwGdcdm7.js → messagebox-C8KQgCl_.js} +14 -13
  7. package/dist/{messagebox-CqUBJs_D.cjs → messagebox-CjPtPPrW.cjs} +1 -0
  8. package/dist/pkt-alert.cjs +1 -1
  9. package/dist/pkt-alert.js +1 -1
  10. package/dist/pkt-index.cjs +1 -1
  11. package/dist/pkt-index.js +3 -3
  12. package/dist/pkt-loader.cjs +1 -1
  13. package/dist/pkt-loader.js +1 -1
  14. package/dist/pkt-messagebox.cjs +1 -1
  15. package/dist/pkt-messagebox.js +1 -1
  16. package/package.json +6 -2
  17. package/src/components/alert/alert.test.ts +64 -79
  18. package/src/components/alert/alert.ts +1 -0
  19. package/src/components/backlink/backlink.test.ts +50 -96
  20. package/src/components/button/button.test.ts +211 -249
  21. package/src/components/calendar/calendar.accessibility.test.ts +30 -43
  22. package/src/components/card/card.test.ts +71 -121
  23. package/src/components/checkbox/checkbox.test.ts +231 -156
  24. package/src/components/consent/consent.test.ts +87 -91
  25. package/src/components/icon/icon.test.ts +368 -0
  26. package/src/components/input-wrapper/input-wrapper.test.ts +505 -0
  27. package/src/components/link/link.test.ts +224 -0
  28. package/src/components/linkcard/linkcard.test.ts +14 -12
  29. package/src/components/listbox/listbox.test.ts +225 -0
  30. package/src/components/loader/loader.test.ts +257 -0
  31. package/src/components/loader/loader.ts +6 -1
  32. package/src/components/messagebox/messagebox.test.ts +241 -0
  33. package/src/components/messagebox/messagebox.ts +1 -0
@@ -1,40 +1,55 @@
1
1
  import '@testing-library/jest-dom'
2
2
  import { axe, toHaveNoViolations } from 'jest-axe'
3
3
  import { fireEvent } from '@testing-library/dom'
4
+ import { createElementTest, BaseTestConfig } from '../../tests/test-framework'
5
+ import { CustomElementFor } from '../../tests/component-registry'
6
+ import './checkbox'
4
7
 
5
8
  expect.extend(toHaveNoViolations)
6
9
 
7
- import './checkbox'
8
- import { PktCheckbox } from './checkbox'
9
-
10
- const waitForCustomElements = async () => {
11
- await customElements.whenDefined('pkt-checkbox')
10
+ export interface CheckboxTestConfig extends BaseTestConfig {
11
+ id?: string
12
+ name?: string
13
+ label?: string
14
+ checked?: boolean
15
+ disabled?: boolean
16
+ required?: boolean
17
+ value?: string
18
+ checkHelptext?: string
19
+ hasTile?: boolean
20
+ hasError?: boolean
21
+ errorMessage?: string
22
+ optionalTag?: boolean
23
+ requiredTag?: boolean
24
+ tagText?: string
25
+ labelPosition?: string
26
+ hideLabel?: boolean
27
+ isSwitch?: boolean
12
28
  }
13
29
 
14
- // Helper function to create checkbox markup
15
- const createCheckbox = async (checkboxProps = '') => {
16
- const container = document.createElement('div')
17
- container.innerHTML = `
18
- <pkt-checkbox ${checkboxProps}></pkt-checkbox>
19
- `
20
- document.body.appendChild(container)
21
- await waitForCustomElements()
22
- return container
30
+ // Use shared framework
31
+ export const createCheckboxTest = async (config: CheckboxTestConfig = {}) => {
32
+ const { container, element } = await createElementTest<
33
+ CustomElementFor<'pkt-checkbox'>,
34
+ CheckboxTestConfig
35
+ >('pkt-checkbox', config)
36
+
37
+ return {
38
+ container,
39
+ checkbox: element,
40
+ }
23
41
  }
24
42
 
25
- // Cleanup after each test
26
- afterEach(() => {
27
- document.body.innerHTML = ''
28
- })
29
-
30
43
  describe('PktCheckbox', () => {
31
44
  describe('Rendering and basic functionality', () => {
32
45
  test('renders without errors', async () => {
33
- const container = await createCheckbox('id="test-checkbox" name="test" label="Test Checkbox"')
46
+ const { checkbox } = await createCheckboxTest({
47
+ id: 'test-checkbox',
48
+ name: 'test',
49
+ label: 'Test Checkbox',
50
+ })
34
51
 
35
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
36
52
  expect(checkbox).toBeInTheDocument()
37
-
38
53
  await checkbox.updateComplete
39
54
  expect(checkbox).toBeTruthy()
40
55
 
@@ -42,28 +57,44 @@ describe('PktCheckbox', () => {
42
57
  expect(inputElement).toBeInTheDocument()
43
58
  })
44
59
 
45
- test('renders with correct structure', async () => {
46
- const container = await createCheckbox('id="test" name="test" label="Test Label"')
47
-
48
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
60
+ test('renders proper structure', async () => {
61
+ const { checkbox } = await createCheckboxTest({
62
+ id: 'test',
63
+ name: 'test',
64
+ label: 'Test Label',
65
+ })
49
66
  await checkbox.updateComplete
50
67
 
51
- const wrapper = checkbox.querySelector('.pkt-input-check')
52
- const inputDiv = wrapper?.querySelector('.pkt-input-check__input')
53
- const input = inputDiv?.querySelector('.pkt-input-check__input-checkbox')
54
- const label = inputDiv?.querySelector('.pkt-input-check__input-label')
68
+ expect(checkbox).toBeInTheDocument()
69
+
70
+ // Check basic structure exists
71
+ const input = checkbox.querySelector('input[type="checkbox"]')
72
+ const label = checkbox.querySelector('label')
55
73
 
56
- expect(wrapper).toBeInTheDocument()
57
- expect(inputDiv).toBeInTheDocument()
58
74
  expect(input).toBeInTheDocument()
59
75
  expect(label).toBeInTheDocument()
60
- expect(label?.textContent?.trim()).toBe('Test Label')
76
+ expect(label).toHaveTextContent('Test Label')
61
77
  })
62
78
 
63
- test('renders input with correct attributes', async () => {
64
- const container = await createCheckbox('id="test-id" name="test-name" value="test-value"')
79
+ test('applies ids and names correctly', async () => {
80
+ const { checkbox } = await createCheckboxTest({
81
+ id: 'test-id',
82
+ name: 'test-name',
83
+ value: 'test-value',
84
+ })
85
+ await checkbox.updateComplete
86
+
87
+ expect(checkbox.id).toBe('test-id')
88
+ expect(checkbox.name).toBe('test-name')
89
+ expect(checkbox.value).toBe('test-value')
90
+ })
65
91
 
66
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
92
+ test('renders input with correct attributes', async () => {
93
+ const { checkbox } = await createCheckboxTest({
94
+ id: 'test-id',
95
+ name: 'test-name',
96
+ value: 'test-value',
97
+ })
67
98
  await checkbox.updateComplete
68
99
 
69
100
  const input = checkbox.querySelector('input[type="checkbox"]')
@@ -75,9 +106,10 @@ describe('PktCheckbox', () => {
75
106
 
76
107
  describe('Properties and attributes', () => {
77
108
  test('applies default properties correctly', async () => {
78
- const container = await createCheckbox('id="test" name="test"')
79
-
80
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
109
+ const { checkbox } = await createCheckboxTest({
110
+ id: 'test',
111
+ name: 'test',
112
+ })
81
113
  await checkbox.updateComplete
82
114
 
83
115
  expect(checkbox.value).toBe('')
@@ -96,10 +128,11 @@ describe('PktCheckbox', () => {
96
128
  })
97
129
 
98
130
  test('handles value property correctly', async () => {
99
- const container = await createCheckbox('id="test" name="test" value="test-value"')
100
-
101
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
102
- await checkbox.updateComplete
131
+ const { checkbox } = await createCheckboxTest({
132
+ id: 'test',
133
+ name: 'test',
134
+ value: 'test-value',
135
+ })
103
136
 
104
137
  expect(checkbox.value).toBe('test-value')
105
138
  expect(checkbox.getAttribute('value')).toBe('test-value')
@@ -111,60 +144,58 @@ describe('PktCheckbox', () => {
111
144
  expect(checkbox.value).toBe('updated-value')
112
145
  })
113
146
 
114
- test('handles checked property correctly', async () => {
115
- const container = await createCheckbox('id="test" name="test" checked')
116
-
117
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
147
+ test('handles checked state correctly', async () => {
148
+ const { checkbox } = await createCheckboxTest({
149
+ id: 'test',
150
+ name: 'test',
151
+ checked: true,
152
+ })
118
153
  await checkbox.updateComplete
119
154
 
120
155
  expect(checkbox.checked).toBe(true)
121
156
 
122
157
  const input = checkbox.querySelector('input[type="checkbox"]') as HTMLInputElement
123
158
  expect(input?.checked).toBe(true)
124
-
125
- // Test unchecked
126
- checkbox.checked = false
127
- await checkbox.updateComplete
128
-
129
- expect(input?.checked).toBe(false)
130
159
  })
131
160
 
132
- test('handles defaultChecked property correctly', async () => {
133
- const container = await createCheckbox('id="test" name="test"')
134
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
135
-
136
- // Set defaultChecked before checked is set
137
- checkbox.defaultChecked = true
161
+ test('handles checked property changes', async () => {
162
+ const { checkbox } = await createCheckboxTest({
163
+ id: 'test',
164
+ name: 'test',
165
+ })
138
166
  await checkbox.updateComplete
139
167
 
140
- expect(checkbox.defaultChecked).toBe(true)
141
- expect(checkbox.checked).toBe(true)
168
+ expect(checkbox.checked).toBe(false)
142
169
 
143
- // Wait for another update cycle to ensure DOM is updated
170
+ checkbox.checked = true
144
171
  await checkbox.updateComplete
145
172
 
173
+ expect(checkbox.checked).toBe(true)
146
174
  const input = checkbox.querySelector('input[type="checkbox"]') as HTMLInputElement
147
175
  expect(input?.checked).toBe(true)
148
176
  })
149
177
 
150
- test('handles disabled property correctly', async () => {
151
- const container = await createCheckbox('id="test" name="test" disabled')
152
-
153
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
178
+ test('handles disabled state correctly', async () => {
179
+ const { checkbox } = await createCheckboxTest({
180
+ id: 'test',
181
+ name: 'test',
182
+ disabled: true,
183
+ })
154
184
  await checkbox.updateComplete
155
185
 
156
186
  expect(checkbox.disabled).toBe(true)
157
187
 
158
188
  const input = checkbox.querySelector('input[type="checkbox"]') as HTMLInputElement
159
- const label = checkbox.querySelector('.pkt-input-check__input-label')
160
- expect(input?.disabled).toBe(true)
161
- expect(label).toHaveClass('pkt-input-check__input-label--disabled')
189
+ expect(input.disabled).toBe(true)
162
190
  })
163
191
 
164
192
  test('handles labelPosition property correctly', async () => {
165
193
  // Test left position
166
- const container = await createCheckbox('id="test" name="test" label="Test"')
167
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
194
+ const { checkbox } = await createCheckboxTest({
195
+ id: 'test',
196
+ name: 'test',
197
+ label: 'Test',
198
+ })
168
199
  checkbox.labelPosition = 'left'
169
200
  await checkbox.updateComplete
170
201
 
@@ -184,22 +215,25 @@ describe('PktCheckbox', () => {
184
215
  })
185
216
 
186
217
  test('handles hideLabel property correctly', async () => {
187
- const container = await createCheckbox('id="test" name="test" label="Hidden Label"')
188
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
218
+ const { checkbox } = await createCheckboxTest({
219
+ id: 'test',
220
+ name: 'test',
221
+ label: 'Hidden Label',
222
+ })
189
223
  checkbox.hideLabel = true
190
224
  await checkbox.updateComplete
191
225
 
192
226
  expect(checkbox.hideLabel).toBe(true)
193
-
194
227
  const label = checkbox.querySelector('.pkt-input-check__input-label')
195
228
  expect(label).toHaveClass('pkt-sr-only')
196
229
  })
197
230
 
198
231
  test('handles isSwitch property correctly', async () => {
199
- const container = await createCheckbox('id="test" name="test"')
200
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
201
- checkbox.isSwitch = true
202
- await checkbox.updateComplete
232
+ const { checkbox } = await createCheckboxTest({
233
+ id: 'test',
234
+ name: 'test',
235
+ isSwitch: true,
236
+ })
203
237
 
204
238
  expect(checkbox.isSwitch).toBe(true)
205
239
 
@@ -208,10 +242,11 @@ describe('PktCheckbox', () => {
208
242
  })
209
243
 
210
244
  test('handles hasTile property correctly', async () => {
211
- const container = await createCheckbox('id="test" name="test"')
212
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
213
- checkbox.hasTile = true
214
- await checkbox.updateComplete
245
+ const { checkbox } = await createCheckboxTest({
246
+ id: 'test',
247
+ name: 'test',
248
+ hasTile: true,
249
+ })
215
250
 
216
251
  expect(checkbox.hasTile).toBe(true)
217
252
 
@@ -228,9 +263,11 @@ describe('PktCheckbox', () => {
228
263
 
229
264
  describe('Label and helptext functionality', () => {
230
265
  test('renders label correctly', async () => {
231
- const container = await createCheckbox('id="test" name="test" label="Checkbox Label"')
232
-
233
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
266
+ const { checkbox } = await createCheckboxTest({
267
+ id: 'test',
268
+ name: 'test',
269
+ label: 'Checkbox Label',
270
+ })
234
271
  await checkbox.updateComplete
235
272
 
236
273
  expect(checkbox.label).toBe('Checkbox Label')
@@ -241,11 +278,12 @@ describe('PktCheckbox', () => {
241
278
  })
242
279
 
243
280
  test('renders checkHelptext when provided', async () => {
244
- const container = await createCheckbox(
245
- 'id="test" name="test" label="Test" checkHelptext="This is help text"',
246
- )
247
-
248
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
281
+ const { checkbox } = await createCheckboxTest({
282
+ id: 'test',
283
+ name: 'test',
284
+ label: 'Test',
285
+ checkHelptext: 'This is help text',
286
+ })
249
287
  await checkbox.updateComplete
250
288
 
251
289
  expect(checkbox.checkHelptext).toBe('This is help text')
@@ -256,9 +294,11 @@ describe('PktCheckbox', () => {
256
294
  })
257
295
 
258
296
  test('does not render helptext when not provided', async () => {
259
- const container = await createCheckbox('id="test" name="test" label="Test"')
260
-
261
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
297
+ const { checkbox } = await createCheckboxTest({
298
+ id: 'test',
299
+ name: 'test',
300
+ label: 'Test',
301
+ })
262
302
  await checkbox.updateComplete
263
303
 
264
304
  const helptext = checkbox.querySelector('.pkt-input-check__input-helptext')
@@ -268,11 +308,12 @@ describe('PktCheckbox', () => {
268
308
 
269
309
  describe('Tag functionality', () => {
270
310
  test('renders custom tagText when provided', async () => {
271
- const container = await createCheckbox(
272
- 'id="test" name="test" label="Test" tagText="Custom Tag"',
273
- )
274
-
275
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
311
+ const { checkbox } = await createCheckboxTest({
312
+ id: 'test',
313
+ name: 'test',
314
+ label: 'Test',
315
+ tagText: 'Custom Tag',
316
+ })
276
317
  await checkbox.updateComplete
277
318
 
278
319
  expect(checkbox.tagText).toBe('Custom Tag')
@@ -283,9 +324,12 @@ describe('PktCheckbox', () => {
283
324
  })
284
325
 
285
326
  test('renders optional tag when optionalTag is true', async () => {
286
- const container = await createCheckbox('id="test" name="test" label="Test" optionalTag')
287
-
288
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
327
+ const { checkbox } = await createCheckboxTest({
328
+ id: 'test',
329
+ name: 'test',
330
+ label: 'Test',
331
+ optionalTag: true,
332
+ })
289
333
  await checkbox.updateComplete
290
334
 
291
335
  expect(checkbox.optionalTag).toBe(true)
@@ -297,9 +341,12 @@ describe('PktCheckbox', () => {
297
341
  })
298
342
 
299
343
  test('renders required tag when requiredTag is true', async () => {
300
- const container = await createCheckbox('id="test" name="test" label="Test" requiredTag')
301
-
302
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
344
+ const { checkbox } = await createCheckboxTest({
345
+ id: 'test',
346
+ name: 'test',
347
+ label: 'Test',
348
+ requiredTag: true,
349
+ })
303
350
  await checkbox.updateComplete
304
351
 
305
352
  expect(checkbox.requiredTag).toBe(true)
@@ -311,11 +358,15 @@ describe('PktCheckbox', () => {
311
358
  })
312
359
 
313
360
  test('renders custom optional and required text', async () => {
314
- const container = await createCheckbox(
315
- 'id="test" name="test" label="Test" optionalTag optionalText="Custom Optional" requiredTag requiredText="Custom Required"',
316
- )
317
-
318
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
361
+ const { checkbox } = await createCheckboxTest({
362
+ id: 'test',
363
+ name: 'test',
364
+ label: 'Test',
365
+ })
366
+ checkbox.optionalTag = true
367
+ checkbox.optionalText = 'Custom Optional'
368
+ checkbox.requiredTag = true
369
+ checkbox.requiredText = 'Custom Required'
319
370
  await checkbox.updateComplete
320
371
 
321
372
  expect(checkbox.optionalText).toBe('Custom Optional')
@@ -328,11 +379,14 @@ describe('PktCheckbox', () => {
328
379
  })
329
380
 
330
381
  test('renders multiple tags when multiple are enabled', async () => {
331
- const container = await createCheckbox(
332
- 'id="test" name="test" label="Test" tagText="Custom" optionalTag requiredTag',
333
- )
334
-
335
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
382
+ const { checkbox } = await createCheckboxTest({
383
+ id: 'test',
384
+ name: 'test',
385
+ label: 'Test',
386
+ })
387
+ checkbox.tagText = 'Custom'
388
+ checkbox.optionalTag = true
389
+ checkbox.requiredTag = true
336
390
  await checkbox.updateComplete
337
391
 
338
392
  const customTag = checkbox.querySelector('.pkt-tag--gray')
@@ -347,9 +401,11 @@ describe('PktCheckbox', () => {
347
401
 
348
402
  describe('User interaction', () => {
349
403
  test('toggles checked state when clicked', async () => {
350
- const container = await createCheckbox('id="test" name="test" label="Test"')
351
-
352
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
404
+ const { checkbox } = await createCheckboxTest({
405
+ id: 'test',
406
+ name: 'test',
407
+ label: 'Test',
408
+ })
353
409
  await checkbox.updateComplete
354
410
 
355
411
  const input = checkbox.querySelector('input[type="checkbox"]') as HTMLInputElement
@@ -371,9 +427,12 @@ describe('PktCheckbox', () => {
371
427
  })
372
428
 
373
429
  test('does not toggle when disabled', async () => {
374
- const container = await createCheckbox('id="test" name="test" label="Test" disabled')
375
-
376
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
430
+ const { checkbox } = await createCheckboxTest({
431
+ id: 'test',
432
+ name: 'test',
433
+ label: 'Test',
434
+ disabled: true,
435
+ })
377
436
  await checkbox.updateComplete
378
437
 
379
438
  const input = checkbox.querySelector('input[type="checkbox"]') as HTMLInputElement
@@ -390,9 +449,11 @@ describe('PktCheckbox', () => {
390
449
  })
391
450
 
392
451
  test('handles focus and blur events', async () => {
393
- const container = await createCheckbox('id="test" name="test" label="Test"')
394
-
395
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
452
+ const { checkbox } = await createCheckboxTest({
453
+ id: 'test',
454
+ name: 'test',
455
+ label: 'Test',
456
+ })
396
457
  await checkbox.updateComplete
397
458
 
398
459
  const input = checkbox.querySelector('input[type="checkbox"]') as HTMLInputElement
@@ -410,9 +471,11 @@ describe('PktCheckbox', () => {
410
471
  })
411
472
 
412
473
  test('marks as touched when interacted with', async () => {
413
- const container = await createCheckbox('id="test" name="test" label="Test"')
414
-
415
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
474
+ const { checkbox } = await createCheckboxTest({
475
+ id: 'test',
476
+ name: 'test',
477
+ label: 'Test',
478
+ })
416
479
  await checkbox.updateComplete
417
480
 
418
481
  const input = checkbox.querySelector('input[type="checkbox"]') as HTMLInputElement
@@ -431,9 +494,11 @@ describe('PktCheckbox', () => {
431
494
 
432
495
  describe('Label position and structure', () => {
433
496
  test('places label on the right by default', async () => {
434
- const container = await createCheckbox('id="test" name="test" label="Right Label"')
435
-
436
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
497
+ const { checkbox } = await createCheckboxTest({
498
+ id: 'test',
499
+ name: 'test',
500
+ label: 'Right Label',
501
+ })
437
502
  await checkbox.updateComplete
438
503
 
439
504
  const inputDiv = checkbox.querySelector('.pkt-input-check__input')
@@ -445,11 +510,12 @@ describe('PktCheckbox', () => {
445
510
  })
446
511
 
447
512
  test('places label on the left when labelPosition is left', async () => {
448
- const container = await createCheckbox(
449
- 'id="test" name="test" label="Left Label" labelPosition="left"',
450
- )
451
-
452
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
513
+ const { checkbox } = await createCheckboxTest({
514
+ id: 'test',
515
+ name: 'test',
516
+ label: 'Left Label',
517
+ })
518
+ checkbox.labelPosition = 'left'
453
519
  await checkbox.updateComplete
454
520
 
455
521
  const inputDiv = checkbox.querySelector('.pkt-input-check__input')
@@ -463,9 +529,11 @@ describe('PktCheckbox', () => {
463
529
 
464
530
  describe('Error handling', () => {
465
531
  test('applies error styling when hasError is true', async () => {
466
- const container = await createCheckbox('id="test" name="test" label="Test"')
467
-
468
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
532
+ const { checkbox } = await createCheckboxTest({
533
+ id: 'test',
534
+ name: 'test',
535
+ label: 'Test',
536
+ })
469
537
  checkbox.hasError = true
470
538
  await checkbox.updateComplete
471
539
 
@@ -474,9 +542,11 @@ describe('PktCheckbox', () => {
474
542
  })
475
543
 
476
544
  test('does not apply error styling when hasError is false', async () => {
477
- const container = await createCheckbox('id="test" name="test" label="Test"')
478
-
479
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
545
+ const { checkbox } = await createCheckboxTest({
546
+ id: 'test',
547
+ name: 'test',
548
+ label: 'Test',
549
+ })
480
550
  await checkbox.updateComplete
481
551
 
482
552
  const input = checkbox.querySelector('.pkt-input-check__input-checkbox')
@@ -486,11 +556,11 @@ describe('PktCheckbox', () => {
486
556
 
487
557
  describe('Accessibility', () => {
488
558
  test('has no accessibility violations', async () => {
489
- const container = await createCheckbox(
490
- 'id="accessible-checkbox" name="test" label="Accessible Checkbox"',
491
- )
492
-
493
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
559
+ const { checkbox } = await createCheckboxTest({
560
+ id: 'accessible-checkbox',
561
+ name: 'test',
562
+ label: 'Accessible Checkbox',
563
+ })
494
564
  await checkbox.updateComplete
495
565
 
496
566
  const results = await axe(checkbox)
@@ -498,11 +568,11 @@ describe('PktCheckbox', () => {
498
568
  })
499
569
 
500
570
  test('associates label with input correctly', async () => {
501
- const container = await createCheckbox(
502
- 'id="test-association" name="test" label="Associated Label"',
503
- )
504
-
505
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
571
+ const { checkbox } = await createCheckboxTest({
572
+ id: 'test-association',
573
+ name: 'test',
574
+ label: 'Associated Label',
575
+ })
506
576
  await checkbox.updateComplete
507
577
 
508
578
  const input = checkbox.querySelector('input[type="checkbox"]')
@@ -513,9 +583,12 @@ describe('PktCheckbox', () => {
513
583
  })
514
584
 
515
585
  test('has correct role for switch when isSwitch is true', async () => {
516
- const container = await createCheckbox('id="test" name="test" label="Test Switch" isSwitch')
517
-
518
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
586
+ const { checkbox } = await createCheckboxTest({
587
+ id: 'test',
588
+ name: 'test',
589
+ label: 'Test Switch',
590
+ })
591
+ checkbox.isSwitch = true
519
592
  await checkbox.updateComplete
520
593
 
521
594
  const input = checkbox.querySelector('input[type="checkbox"]')
@@ -523,9 +596,11 @@ describe('PktCheckbox', () => {
523
596
  })
524
597
 
525
598
  test('has correct role for checkbox by default', async () => {
526
- const container = await createCheckbox('id="test" name="test" label="Test Checkbox"')
527
-
528
- const checkbox = container.querySelector('pkt-checkbox') as PktCheckbox
599
+ const { checkbox } = await createCheckboxTest({
600
+ id: 'test',
601
+ name: 'test',
602
+ label: 'Test Checkbox',
603
+ })
529
604
  await checkbox.updateComplete
530
605
 
531
606
  const input = checkbox.querySelector('input[type="checkbox"]')