Skip to content

Commit 30be8eb

Browse files
author
shleewhite
committed
chore: standardized how handle checking from elements that may not exist
1 parent 821e769 commit 30be8eb

File tree

13 files changed

+45
-28
lines changed

13 files changed

+45
-28
lines changed

showcase/tests/integration/components/hds/alert/index-test.gts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ module('Integration | Component | hds/alert/index', function (hooks) {
280280
</template>,
281281
);
282282
const title = find('#test-alert .hds-alert__title');
283-
assert.dom('#test-alert').hasAttribute('aria-labelledby', title?.id ?? '');
283+
const titleId = title?.id ?? '';
284+
285+
assert.dom('#test-alert').hasAttribute('aria-labelledby', titleId);
284286
});
285287

286288
test('it should render with an auto-generated `aria-labelledby` when description is provided', async function (assert) {

showcase/tests/integration/components/hds/code-block/index-test.gts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,15 @@ module('Integration | Component | hds/code-block/index', function (hooks) {
9494
</template>,
9595
);
9696
const title = find('.hds-code-block__title');
97-
assert.dom('.hds-code-block__code').hasAria('labelledby', title?.id ?? '');
97+
const titleId = title?.id ?? '';
98+
99+
assert.dom('.hds-code-block__code').hasAria('labelledby', titleId);
98100
assert.dom('.hds-code-block__title').hasText('Title');
99101

100102
const description = find('.hds-code-block__description');
101-
assert
102-
.dom('.hds-code-block__code')
103-
.hasAria('describedby', description?.id ?? '');
103+
const descriptionId = description?.id ?? '';
104+
105+
assert.dom('.hds-code-block__code').hasAria('describedby', descriptionId);
104106
assert.dom('.hds-code-block__description').hasText('Description');
105107
});
106108

showcase/tests/integration/components/hds/dropdown/index-test.gts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,11 @@ module('Integration | Component | hds/dropdown/index', function (hooks) {
322322
</template>,
323323
);
324324
const button = find('.hds-dropdown-toggle-button');
325+
const buttonId = button?.id ?? '';
326+
325327
await click('button.hds-dropdown-toggle-button');
326328

327329
assert.dom('#test-dropdown ul').hasAttribute('role', 'listbox');
328-
assert
329-
.dom('#test-dropdown ul')
330-
.hasAttribute('aria-labelledby', button?.id ?? '');
330+
assert.dom('#test-dropdown ul').hasAttribute('aria-labelledby', buttonId);
331331
});
332332
});

showcase/tests/integration/components/hds/dropdown/list-item/checkbox-test.gts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ module(
6969
);
7070

7171
const control = find('.hds-dropdown-list-item__control');
72+
const controlId = control?.id ?? '';
73+
7274
assert
7375
.dom('.hds-dropdown-list-item__label')
74-
.hasAttribute('for', control?.id ?? '');
76+
.hasAttribute('for', controlId);
7577
});
7678

7779
// ICON

showcase/tests/integration/components/hds/dropdown/list-item/radio-test.gts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ module(
6969
);
7070

7171
const control = find('.hds-dropdown-list-item__control');
72+
const controlId = control?.id ?? '';
73+
7274
assert
7375
.dom('.hds-dropdown-list-item__label')
74-
.hasAttribute('for', control?.id ?? '');
76+
.hasAttribute('for', controlId);
7577
});
7678

7779
// ICON

showcase/tests/integration/components/hds/flyout/index-test.gts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,9 @@ module('Integration | Component | hds/flyout/index', function (hooks) {
393393
);
394394

395395
const titleElement = find('.hds-flyout__title');
396-
assert
397-
.dom('dialog')
398-
.hasAttribute('aria-labelledby', titleElement?.id ?? '');
396+
const titleId = titleElement?.id ?? '';
397+
398+
assert.dom('dialog').hasAttribute('aria-labelledby', titleId);
399399
});
400400

401401
// FOCUS MANAGEMENT

showcase/tests/integration/components/hds/form/key-value-inputs/field-test.gts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,11 @@ module(
292292
await createKeyValueInputsField(opts);
293293

294294
const label = find('#test-form-key-value-field .hds-form-label');
295+
const labelId = label?.id ?? '';
296+
295297
const input = find(`#test-form-key-value-field ${selector}`);
298+
const inputId = input?.id ?? '';
299+
296300
const helper = find(
297301
'#test-form-key-value-field .hds-form-key-value-inputs__field-helper-text',
298302
);
@@ -303,7 +307,7 @@ module(
303307
if (type === 'SuperSelectSingle' || type === 'SuperSelectMultiple') {
304308
assert
305309
.dom('#test-form-key-value-field [role="combobox"]')
306-
.hasAria('labelledby', label?.id ?? '');
310+
.hasAria('labelledby', labelId);
307311
assert
308312
.dom('#test-form-key-value-field [role="combobox"]')
309313
.hasAria(
@@ -315,7 +319,7 @@ module(
315319
.dom(
316320
'#test-form-key-value-field .hds-form-key-value-inputs__field-label',
317321
)
318-
.hasAttribute('for', input?.id ?? '');
322+
.hasAttribute('for', inputId);
319323
assert
320324
.dom(`#test-form-key-value-field ${selector}`)
321325
.hasAria(

showcase/tests/integration/components/hds/form/key-value-inputs/index-test.gts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,16 +364,15 @@ module(
364364
const legend = find(
365365
'#test-form-key-value-inputs .hds-form-key-value-inputs__header legend',
366366
);
367+
const legendId = legend?.id ?? '';
367368
const helper = find(
368369
'#test-form-key-value-inputs .hds-form-key-value-inputs__header .hds-form-key-value-inputs__helper-text',
369370
);
370371
const error = find(
371372
'#test-form-key-value-inputs .hds-form-key-value-inputs__error',
372373
);
373374

374-
assert
375-
.dom('#test-form-key-value-inputs')
376-
.hasAria('labelledby', legend?.id ?? '');
375+
assert.dom('#test-form-key-value-inputs').hasAria('labelledby', legendId);
377376
assert
378377
.dom('#test-form-key-value-inputs')
379378
.hasAria(

showcase/tests/integration/components/hds/form/radio/group-test.gts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ module('Integration | Component | hds/form/radio/group', function (hooks) {
173173
assert.dom(labels[0]).hasAttribute('for', 'true');
174174

175175
// the `false` value should not be used, but the `id` (input) attribute should be generated and the `for` (label) attribute should match it
176-
const generatedId = inputs[1]?.id;
176+
const generatedId = inputs[1]?.id ?? '';
177177
assert.true(generatedId?.startsWith('ember'));
178-
assert.dom(labels[1]).hasAttribute('for', generatedId ?? '');
178+
assert.dom(labels[1]).hasAttribute('for', generatedId);
179179
});
180180

181181
// NAME

showcase/tests/integration/components/hds/modal/index-test.gts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,9 @@ module('Integration | Component | hds/modal/index', function (hooks) {
419419
);
420420

421421
const titleElement = find('.hds-modal__title');
422-
assert
423-
.dom('dialog')
424-
.hasAttribute('aria-labelledby', titleElement?.id ?? '');
422+
const titleId = titleElement?.id ?? '';
423+
424+
assert.dom('dialog').hasAttribute('aria-labelledby', titleId);
425425
});
426426

427427
// FOCUS MANAGEMENT

0 commit comments

Comments
 (0)