Skip to content

Commit

Permalink
feat: enhance accessibility and add tests for auro-counter and auro-c…
Browse files Browse the repository at this point in the history
…ounter-group components #195
  • Loading branch information
rmenner committed Feb 5, 2025
1 parent ee205bb commit 3d083ed
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
6 changes: 4 additions & 2 deletions components/counter/src/auro-counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,13 @@ export class AuroCounter extends LitElement {
return html`
<div class="counter">
<div class="content" >
<label class="label"><slot></slot></label>
<label id="counter-label" class="label"><slot></slot></label>
<slot name="description"></slot>
</div>
<div part="counterControl">
<div part="counterControl" aria-labelledby="counter-label">
<auro-counter-button
arialabel="Decrement"
part="controlMinus"
@click="${() => this.decrement()}"
?disabled="${this.disabled || this.disableMin || this.isIncrementDisabled(this.min)}"
Expand All @@ -289,6 +290,7 @@ export class AuroCounter extends LitElement {
</div>
<auro-counter-button
arialabel="Increment"
part="controlPlus"
@click="${() => this.increment()}"
?disabled="${this.disabled || this.disableMax || this.isIncrementDisabled(this.max)}"
Expand Down
34 changes: 32 additions & 2 deletions components/counter/test/auro-counter-group.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-undef, no-magic-numbers */
/* eslint-disable no-undef, no-magic-numbers, max-lines */

import { fixture, html, expect, elementUpdated } from '@open-wc/testing';
import { fixture, html, expect, elementUpdated, assert } from '@open-wc/testing';
import '../src/index.js';

describe('auro-counter-group: configureCounters', () => {
Expand Down Expand Up @@ -249,3 +249,33 @@ describe('auro-counter-group: rendering logic', () => {

});

describe('auro-counter-group: accessibility tests', () => {
const ignoredRules = {
ignoredRules: ['color-contrast'],
};

it('auro-counter-group passes accessibility test', async () => {
const el = await fixture(html`
<auro-counter-group>
<auro-counter value="2"></auro-counter>
<auro-counter value="3"></auro-counter>
</auro-counter-group>
`);

await assert.isAccessible(el, ignoredRules);
});

it('auro-counter-group with dropdown passes accessibility test', async () => {
const el = await fixture(html`
<auro-counter-group isDropdown>
<span slot="label">Counter Group Label</span>
<span slot="helpText">Help Text</span>
<auro-counter value="2"></auro-counter>
<auro-counter value="3"></auro-counter>
</auro-counter-group>
`);

await assert.isAccessible(el, ignoredRules);
});

});
18 changes: 17 additions & 1 deletion components/counter/test/auro-counter.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-unused-expressions, no-undef, no-magic-numbers, arrow-parens */

import { fixture, html, expect } from '@open-wc/testing';
import { fixture, html, expect, assert } from '@open-wc/testing';
import '../src/index.js';

describe('auro-counter: increment', () => {
Expand Down Expand Up @@ -84,3 +84,19 @@ describe('auro-counter: isIncrementDisabled', () => {
expect(el.isIncrementDisabled(el.max)).to.be.true;
});
});

describe('auro-counter: accessibility tests', () => {
const ignoredRules = {
ignoredRules: ['color-contrast'],
};

it('is accessible', async () => {
const el = await fixture(html`<auro-counter value="5" min="0" max="10">Counter</auro-counter>`);
await assert.isAccessible(el, ignoredRules);
});

it('is accessible when disabled', async () => {
const el = await fixture(html`<auro-counter value="5" min="0" max="10" disabled>Counter</auro-counter>`);
await assert.isAccessible(el, ignoredRules);
});
});

0 comments on commit 3d083ed

Please sign in to comment.