Skip to content

Commit 5ad8474

Browse files
committed
add accessibility tests
1 parent 59c8f97 commit 5ad8474

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

packages/dialtone-vue/components/filter_pill/filter_pill.test.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,87 @@ describe('DtFilterPill Tests', function () {
536536
});
537537
});
538538

539+
describe('Accessibility Tests', () => {
540+
describe.each([
541+
{ mode: 'popover', props: {} },
542+
{ mode: 'dropdown', props: { useDropdown: true, modelValue: MOCK_TEST_FILTERS } },
543+
])('ARIA attributes on the primary button ($mode mode)', ({ props }) => {
544+
beforeEach(() => {
545+
mockProps = props;
546+
updateWrapper();
547+
});
548+
549+
it('Should have aria-haspopup', () => {
550+
expect(button.attributes('aria-haspopup')).toBeTruthy();
551+
});
552+
553+
it('Should have aria-expanded="false" by default', () => {
554+
expect(button.attributes('aria-expanded')).toBe('false');
555+
});
556+
557+
it('Should have aria-expanded="true" when open', async () => {
558+
await button.trigger('click');
559+
560+
expect(button.attributes('aria-expanded')).toBe('true');
561+
});
562+
563+
it('Should have aria-controls pointing to an id', () => {
564+
expect(button.attributes('aria-controls')).toBeTruthy();
565+
});
566+
});
567+
568+
describe('Keyboard navigation', () => {
569+
it.each(['ArrowDown', 'ArrowUp'])('Should open popover on %s', async (key) => {
570+
await button.trigger('keydown', { key });
571+
572+
expect(wrapper.emitted('open')[0][0]).toBe(true);
573+
});
574+
});
575+
576+
describe('Checkbox group labelling', () => {
577+
it('Should have aria-label matching the label prop', async () => {
578+
mockProps = { label: MOCK_LABEL, modelValue: MOCK_TEST_FILTERS };
579+
updateWrapper();
580+
await button.trigger('click');
581+
582+
const checkboxGroup = document.querySelector('[data-qa="checkbox-group"]');
583+
584+
expect(checkboxGroup.getAttribute('aria-label')).toBe(MOCK_LABEL);
585+
});
586+
});
587+
588+
describe('Clear button accessible name', () => {
589+
it('Should fall back to localized "Clear filter" when endTooltipText is empty', () => {
590+
mockProps = { modelValue: [{ name: 'Test item 1', active: true }] };
591+
updateWrapper();
592+
593+
expect(clearButton.attributes('aria-label')).toBe('Clear filter');
594+
});
595+
});
596+
597+
describe('Checkbox group name', () => {
598+
it('Should use label prop as checkbox group name', async () => {
599+
mockProps = { label: 'Teams', modelValue: MOCK_TEST_FILTERS };
600+
updateWrapper();
601+
await button.trigger('click');
602+
603+
const checkbox = document.querySelector('input[type="checkbox"]');
604+
605+
expect(checkbox.getAttribute('name')).toBe('Teams');
606+
});
607+
608+
it('Should fall back to "filter-pill" when no label is provided', async () => {
609+
mockProps = { modelValue: MOCK_TEST_FILTERS };
610+
updateWrapper();
611+
await button.trigger('click');
612+
613+
const checkbox = document.querySelector('input[type="checkbox"]');
614+
615+
expect(checkbox.getAttribute('name')).toBe('filter-pill');
616+
});
617+
});
618+
});
619+
539620
describe('Overlay Class Props Tests', () => {
540621
describe('When popover class props are set', () => {
541622
it.each([

packages/dialtone-vue/components/filter_pill/filter_pill.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
v-if="modelValue?.length"
9999
:selected-values="deferSelection ? pendingActiveFilters : activeFilters"
100100
:aria-label="label"
101-
name="contact-centers"
101+
:name="label || 'filter-pill'"
102102
>
103103
<dt-checkbox
104104
v-for="filter in displayFilters"

packages/dialtone-vue/localization/en-US.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ DIALTONE_FEED_ITEM_PILL_ARIA_LABEL = Click to expand
9494
DIALTONE_FILTER_PILL_CLEAR_BUTTON_LABEL = Clear filter
9595
DIALTONE_FILTER_PILL_CANCEL_BUTTON_LABEL = Cancel
9696
DIALTONE_FILTER_PILL_APPLY_BUTTON_LABEL = Apply
97-
DIALTONE_FILTER_PILL_READ_ONLY_TOOLTIP = Filter is disabled
97+
DIALTONE_FILTER_PILL_READ_ONLY_TOOLTIP = Read-only filter
9898
9999
DIALTONE_GENERAL_ROW_ACTIVE_VOICE_CHAT_TEXT = Active voice chat
100100
DIALTONE_GENERAL_ROW_CALL_BUTTON_TOOLTIP = Call

0 commit comments

Comments
 (0)