material-web/migrations/v2/query-selector-aria_test.ts
Elizabeth Mitchell 5df9410e60 fix!: aria-labels announcing twice with "group" on components
BREAKING CHANGE: `querySelector` for `[role]` and `[aria-*]` attributes may no longer work. See `@material/web/migrations/v2/README.md` and `@material/web/migrations/v2/query-selector-aria.ts`.

Browser/SR test results (go/mwc-double-aria-test-results)
  -  VoiceOver on Chrome
  -  VoiceOver on iOS Safari
  -  TalkBack on Chrome
  -  ChromeVox on Chrome
  -  NVDA on Chrome
  -  NVDA on Firefox
  -  JAWS on Chrome
  -  JAWS on Firefox
  (Optional)
  -  VoiceOver on Safari
  -  VoiceOver on Firefox

PiperOrigin-RevId: 648859827
2024-07-02 15:22:12 -07:00

88 lines
2.3 KiB
TypeScript

/**
* @license
* Copyright 2024 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import '@material/web/checkbox/checkbox.js';
import {html} from 'lit';
import {Environment} from '../../testing/environment.js';
import {ariaSelector} from './query-selector-aria.js';
describe('query-selector-aria', () => {
const env = new Environment();
it('is needed when querying by aria attribute selectors fails', () => {
// Arrange
const root = env.render(
html`<md-checkbox aria-label="Agree"></md-checkbox>`,
);
// Act
const checkbox = root.querySelector('[aria-label="Agree"]');
// Assert
expect(checkbox)
.withContext('aria attribute query expected to fail without patches')
.toBeNull();
});
describe('ariaSelector()', () => {
it('returns the element with an aria attribute query', () => {
// Arrange
const root = env.render(
html`<md-checkbox aria-label="Agree"></md-checkbox>`,
);
// Act
const element = root.querySelector(ariaSelector('[aria-label="Agree"]'));
// Assert
expect(element).withContext('queried element').not.toBeNull();
});
it('returns the element with a role attribute query', () => {
// Arrange
const root = env.render(html`<md-checkbox role="radio"></md-checkbox>`);
// Act
const element = root.querySelector(ariaSelector('[role="radio"]'));
// Assert
expect(element).withContext('queried element').not.toBeNull();
});
it('returns the element when combined with other selectors', () => {
// Arrange
const root = env.render(html`
<md-checkbox
class="checkbox"
aria-label="Agree"
aria-haspopup="true"></md-checkbox>
`);
// Act
const element = root.querySelector(
ariaSelector('.checkbox[aria-label="Agree"][aria-haspopup="true"]'),
);
// Assert
expect(element).withContext('queried element').not.toBeNull();
});
it('returns expected elements when not using aria attribute selectors', () => {
// Arrange
const root = env.render(html`
<md-checkbox class="checkbox"></md-checkbox>
`);
// Act
const element = root.querySelector(ariaSelector('.checkbox'));
// Assert
expect(element).withContext('queried element').not.toBeNull();
});
});
});