|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2023 Google LLC |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +// import 'jasmine'; (google3-only) |
| 8 | +import './icon.js'; |
| 9 | + |
| 10 | +import {html} from 'lit'; |
| 11 | + |
| 12 | +import {Environment} from '../testing/environment.js'; |
| 13 | +import {createTokenTests} from '../testing/tokens.js'; |
| 14 | + |
| 15 | +import {MdIcon} from './icon.js'; |
| 16 | + |
| 17 | +describe('<md-icon>', () => { |
| 18 | + const env = new Environment(); |
| 19 | + |
| 20 | + describe('.styles', () => { |
| 21 | + createTokenTests(MdIcon.styles); |
| 22 | + }); |
| 23 | + |
| 24 | + describe('accessiblity', () => { |
| 25 | + it('sets aria-hidden to true by default', async () => { |
| 26 | + const root = env.render(html` |
| 27 | + <md-icon>check</md-icon>`); |
| 28 | + const icon = root.querySelector('md-icon')!; |
| 29 | + |
| 30 | + await env.waitForStability(); |
| 31 | + |
| 32 | + expect(icon.getAttribute('aria-hidden')).toBe('true'); |
| 33 | + }); |
| 34 | + |
| 35 | + it('sets aria-hidden is removed when initalized as false', async () => { |
| 36 | + const root = env.render(html` |
| 37 | + <md-icon aria-hidden="false">check</md-icon>`); |
| 38 | + const icon = root.querySelector('md-icon')!; |
| 39 | + |
| 40 | + await env.waitForStability(); |
| 41 | + |
| 42 | + expect(icon.hasAttribute('aria-hidden')).toBe(false); |
| 43 | + }); |
| 44 | + |
| 45 | + it('allows overriding aria-hidden after first render', async () => { |
| 46 | + const root = env.render(html` |
| 47 | + <md-icon>check</md-icon>`); |
| 48 | + const icon = root.querySelector('md-icon')!; |
| 49 | + |
| 50 | + await env.waitForStability(); |
| 51 | + |
| 52 | + expect(icon.getAttribute('aria-hidden')).toBe('true'); |
| 53 | + |
| 54 | + icon.removeAttribute('aria-hidden'); |
| 55 | + await env.waitForStability(); |
| 56 | + |
| 57 | + expect(icon.hasAttribute('aria-hidden')).toBe(false); |
| 58 | + }); |
| 59 | + |
| 60 | + it('overrides invalid aria-hidden values to true', async () => { |
| 61 | + const root = env.render(html` |
| 62 | + <!-- @ts-ignore:disable-next-line:no-incompatible-type-binding --> |
| 63 | + <md-icon aria-hidden="foo">check</md-icon>`); |
| 64 | + const icon = root.querySelector('md-icon')!; |
| 65 | + |
| 66 | + await env.waitForStability(); |
| 67 | + |
| 68 | + expect(icon.getAttribute('aria-hidden')).toBe('true'); |
| 69 | + }); |
| 70 | + }); |
| 71 | +}); |
0 commit comments