2022-07-25 20:44:44 +03:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright 2022 Google LLC
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2023-03-04 02:04:37 +03:00
|
|
|
// import 'jasmine'; (google3-only)
|
2023-06-21 21:32:45 +03:00
|
|
|
import './list.js';
|
|
|
|
import './list-item.js';
|
|
|
|
|
2023-06-30 01:17:52 +03:00
|
|
|
import {html} from 'lit';
|
2022-07-25 20:44:44 +03:00
|
|
|
|
2023-06-30 01:17:52 +03:00
|
|
|
import {Environment} from '../testing/environment.js';
|
2023-03-04 02:04:37 +03:00
|
|
|
import {createTokenTests} from '../testing/tokens.js';
|
|
|
|
|
2023-09-15 04:59:01 +03:00
|
|
|
import {ListHarness, ListItemHarness} from './harness.js';
|
2023-03-04 02:04:37 +03:00
|
|
|
import {MdList} from './list.js';
|
|
|
|
import {MdListItem} from './list-item.js';
|
|
|
|
|
|
|
|
describe('<md-list>', () => {
|
2023-06-30 01:17:52 +03:00
|
|
|
const env = new Environment();
|
|
|
|
|
2023-03-04 02:04:37 +03:00
|
|
|
describe('.styles', () => {
|
|
|
|
createTokenTests(MdList.styles);
|
|
|
|
});
|
2023-06-21 21:32:45 +03:00
|
|
|
|
2023-06-30 01:17:52 +03:00
|
|
|
describe('keyboard navigation', () => {
|
|
|
|
it('non-nagivable key does nothing', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
2023-10-25 21:58:21 +03:00
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(0);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await listHarness.keypress('k');
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(0);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('ArrowDown activates the next item', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
2023-10-25 21:58:21 +03:00
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(0);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await listHarness.pressHandledKey('ArrowDown');
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(0);
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
|
|
|
|
2023-09-15 03:47:21 +03:00
|
|
|
it('ArrowRight in LTR activates the next item', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-09-15 03:47:21 +03:00
|
|
|
|
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
2023-10-25 21:58:21 +03:00
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-09-15 03:47:21 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(0);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-09-15 03:47:21 +03:00
|
|
|
|
|
|
|
await listHarness.pressHandledKey('ArrowRight');
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(0);
|
2023-09-15 03:47:21 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('ArrowLeft in RTL activates the next item', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list dir="rtl">
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-09-15 03:47:21 +03:00
|
|
|
|
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
2023-10-25 21:58:21 +03:00
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-09-15 03:47:21 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(0);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-09-15 03:47:21 +03:00
|
|
|
|
|
|
|
await listHarness.pressHandledKey('ArrowLeft');
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(0);
|
2023-09-15 03:47:21 +03:00
|
|
|
});
|
|
|
|
|
2023-06-30 01:17:52 +03:00
|
|
|
it('ArrowDown will loop around', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
2023-10-25 21:58:21 +03:00
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(0);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await listHarness.pressHandledKey('ArrowDown');
|
|
|
|
await env.waitForStability();
|
2023-06-21 21:32:45 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('ArrowDown will do nothing if nothing is selectable', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" disabled></md-list-item>
|
|
|
|
<md-list-item type="button" disabled></md-list-item>
|
|
|
|
</md-list>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
|
|
|
const [first, second] = Array.from(root.querySelectorAll('md-list-item'));
|
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await listHarness.pressHandledKey('ArrowDown');
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('ArrowDown does not activate disabled items', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
<md-list-item type="button" disabled></md-list-item>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
2023-10-25 21:58:21 +03:00
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await listHarness.pressHandledKey('ArrowDown');
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(0);
|
|
|
|
expect(document.activeElement).toEqual(third);
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('ArrowDown will select itself if its the only activatable', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
|
|
|
const first = root.querySelector('md-list-item')!;
|
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await listHarness.pressHandledKey('ArrowDown');
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(document.activeElement).toEqual(first);
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('ArrowUp activates the previous item', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
2023-10-25 21:58:21 +03:00
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(0);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await listHarness.pressHandledKey('ArrowUp');
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
|
|
|
expect(document.activeElement).toEqual(first);
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
|
|
|
|
2023-09-15 03:47:21 +03:00
|
|
|
it('ArrowLeft in LTR activates the previous item', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-09-15 03:47:21 +03:00
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
2023-10-25 21:58:21 +03:00
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-09-15 03:47:21 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(0);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-09-15 03:47:21 +03:00
|
|
|
|
|
|
|
await listHarness.pressHandledKey('ArrowLeft');
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-09-15 03:47:21 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('ArrowRight in RTL activates the previous item', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list dir="rtl">
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-09-15 03:47:21 +03:00
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
2023-10-25 21:58:21 +03:00
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-09-15 03:47:21 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(0);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-09-15 03:47:21 +03:00
|
|
|
|
|
|
|
await listHarness.pressHandledKey('ArrowRight');
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-09-15 03:47:21 +03:00
|
|
|
});
|
|
|
|
|
2023-06-30 01:17:52 +03:00
|
|
|
it('activatePreviousItem will loop around', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
2023-10-25 21:58:21 +03:00
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-06-21 21:32:45 +03:00
|
|
|
|
2023-06-30 01:17:52 +03:00
|
|
|
await listHarness.pressHandledKey('ArrowUp');
|
|
|
|
await env.waitForStability();
|
2023-06-21 21:32:45 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(0);
|
|
|
|
expect(document.activeElement).toEqual(third);
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
2023-06-21 21:32:45 +03:00
|
|
|
|
2023-06-30 01:17:52 +03:00
|
|
|
it('ArrowUp will return null if nothing is selectable', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" disabled></md-list-item>
|
|
|
|
<md-list-item type="button" disabled></md-list-item>
|
|
|
|
</md-list>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
|
|
|
const [first, second] = Array.from(root.querySelectorAll('md-list-item'));
|
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await listHarness.pressHandledKey('ArrowUp');
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('ArrowUp does not activate disabled items', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" disabled></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
2023-10-25 21:58:21 +03:00
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(0);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await listHarness.pressHandledKey('ArrowUp');
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
|
|
|
expect(document.activeElement).toEqual(first);
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('ArrowUp will select itself if its the only activatable', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
|
|
|
const first = root.querySelector('md-list-item')!;
|
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await listHarness.pressHandledKey('ArrowUp');
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(document.activeElement).toEqual(first);
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
it('Home will select the first item if something is already selected', async () => {
|
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
</md-list>`);
|
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(0);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
|
|
|
|
|
|
|
await listHarness.pressHandledKey('Home');
|
|
|
|
await env.waitForStability();
|
|
|
|
|
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
|
|
|
expect(document.activeElement).toEqual(first);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Home will select the first activatable item if first is non-activatable', async () => {
|
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" disabled></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
</md-list>`);
|
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(0);
|
|
|
|
|
|
|
|
await listHarness.pressHandledKey('Home');
|
|
|
|
await env.waitForStability();
|
|
|
|
|
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(0);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
|
|
|
expect(document.activeElement).toEqual(second);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Home will select the first item if it is already selected', async () => {
|
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
</md-list>`);
|
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
|
|
|
|
|
|
|
await listHarness.pressHandledKey('Home');
|
|
|
|
await env.waitForStability();
|
|
|
|
|
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
|
|
|
expect(document.activeElement).toEqual(first);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('End will select the last item if something is already selected', async () => {
|
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
</md-list>`);
|
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(0);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
|
|
|
|
|
|
|
await listHarness.pressHandledKey('End');
|
|
|
|
await env.waitForStability();
|
|
|
|
|
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(0);
|
|
|
|
expect(document.activeElement).toEqual(third);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('End will select the last activatable item if last is non-activatable', async () => {
|
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
<md-list-item type="button" disabled></md-list-item>
|
|
|
|
</md-list>`);
|
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
|
|
|
|
|
|
|
await listHarness.pressHandledKey('End');
|
|
|
|
await env.waitForStability();
|
|
|
|
|
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(0);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
|
|
|
expect(document.activeElement).toEqual(second);
|
|
|
|
});
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
it('End will select the last item if it is already selected', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-09-15 04:14:21 +03:00
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const listHarness = new ListHarness(listEl);
|
2023-10-25 21:58:21 +03:00
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
await env.waitForStability();
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(0);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
await listHarness.pressHandledKey('End');
|
|
|
|
await env.waitForStability();
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(0);
|
|
|
|
expect(document.activeElement).toEqual(third);
|
|
|
|
});
|
2023-09-15 04:59:01 +03:00
|
|
|
|
|
|
|
it('Clicking on an item will activate it', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
</md-list>`);
|
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-09-15 04:59:01 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(0);
|
|
|
|
|
|
|
|
const secondHarness = new ListItemHarness(second);
|
|
|
|
|
|
|
|
await secondHarness.clickWithMouse();
|
|
|
|
await env.waitForStability();
|
|
|
|
|
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(0);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
|
|
|
});
|
2023-09-15 04:14:21 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('activate items methods', () => {
|
|
|
|
it('List will activate only first item by default', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
</md-list>`);
|
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
|
|
|
expect(document.activeElement).toEqual(document.body);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('List will activate only first activatable item by default', async () => {
|
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" disabled></md-list-item>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
</md-list>`);
|
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(0);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
|
|
|
expect(document.activeElement).toEqual(document.body);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('List will activate first activatable item if all are tabindex -1', async () => {
|
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
</md-list>`);
|
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-09-15 04:14:21 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
|
|
|
expect(document.activeElement).toEqual(document.body);
|
|
|
|
});
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
it('List will activate first activatable item if defined by user', async () => {
|
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="2"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="1"></md-list-item>
|
|
|
|
</md-list>`);
|
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(0);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
|
|
|
expect(document.activeElement).toEqual(document.body);
|
|
|
|
});
|
2023-06-21 21:32:45 +03:00
|
|
|
|
2023-06-30 01:17:52 +03:00
|
|
|
it('activateNextItem activates the next item', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
const listEl = root.querySelector('md-list')!;
|
2023-10-25 21:58:21 +03:00
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(0);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
const nextItem = listEl.activateNextItem();
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(0);
|
2023-06-30 01:17:52 +03:00
|
|
|
expect(nextItem).toEqual(third);
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(document.activeElement).toEqual(third);
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('activateNextItem will loop around', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
const listEl = root.querySelector('md-list')!;
|
2023-10-25 21:58:21 +03:00
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(0);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
const nextItem = listEl.activateNextItem();
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-06-30 01:17:52 +03:00
|
|
|
expect(nextItem).toEqual(first);
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(document.activeElement).toEqual(first);
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
it('activateNextItem will return null if nothing is selectable', async () => {
|
|
|
|
const root = env.render(html` <md-list> </md-list>`);
|
|
|
|
const listEl = root.querySelector('md-list')!;
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
await env.waitForStability();
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
const nextItem = listEl.activateNextItem();
|
|
|
|
await env.waitForStability();
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
expect(nextItem).toBeNull();
|
|
|
|
});
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
it('activateNextItem does not activate disabled items', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
<md-list-item type="button" disabled></md-list-item>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
const listEl = root.querySelector('md-list')!;
|
2023-10-25 21:58:21 +03:00
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
const nextItem = listEl.activateNextItem();
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(0);
|
2023-06-30 01:17:52 +03:00
|
|
|
expect(nextItem).toEqual(third);
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(document.activeElement).toEqual(third);
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
it('activateNextItem will return itself if it is the only activatable item', async () => {
|
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
</md-list>`);
|
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const first = root.querySelector('md-list-item')!;
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
await env.waitForStability();
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
const nextItem = listEl.activateNextItem();
|
|
|
|
await env.waitForStability();
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(nextItem).toEqual(first);
|
|
|
|
expect(document.activeElement).toEqual(first);
|
|
|
|
});
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
it('activatePreviousItem activates the previous item', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
const listEl = root.querySelector('md-list')!;
|
2023-10-25 21:58:21 +03:00
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(0);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
const nextItem = listEl.activatePreviousItem();
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-06-30 01:17:52 +03:00
|
|
|
expect(nextItem).toEqual(first);
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(document.activeElement).toEqual(first);
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('activatePreviousItem will loop around', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
const listEl = root.querySelector('md-list')!;
|
2023-10-25 21:58:21 +03:00
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
const nextItem = listEl.activatePreviousItem();
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(0);
|
2023-06-30 01:17:52 +03:00
|
|
|
expect(nextItem).toEqual(third);
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(document.activeElement).toEqual(third);
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
it('activatePreviousItem will return null if nothing is selectable', async () => {
|
|
|
|
const root = env.render(html` <md-list> </md-list>`);
|
|
|
|
const listEl = root.querySelector('md-list')!;
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
await env.waitForStability();
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
const nextItem = listEl.activatePreviousItem();
|
|
|
|
await env.waitForStability();
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
expect(nextItem).toBeNull();
|
|
|
|
expect(document.activeElement).toEqual(document.body);
|
|
|
|
});
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
it('activatePreviousItem does not activate disabled items', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button" tabindex="-1"></md-list-item>
|
|
|
|
<md-list-item type="button" disabled></md-list-item>
|
|
|
|
<md-list-item type="button" tabindex="0"></md-list-item>
|
|
|
|
</md-list>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
const listEl = root.querySelector('md-list')!;
|
2023-10-25 21:58:21 +03:00
|
|
|
const [first, second, third] = Array.from(
|
|
|
|
root.querySelectorAll('md-list-item'),
|
|
|
|
);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(-1);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(0);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
const nextItem = listEl.activatePreviousItem();
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(second.tabIndex).toEqual(-1);
|
|
|
|
expect(third.tabIndex).toEqual(-1);
|
2023-06-30 01:17:52 +03:00
|
|
|
expect(nextItem).toEqual(first);
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(document.activeElement).toEqual(first);
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
it('activatePreviousItem will return itself if its activatable', async () => {
|
|
|
|
const root = env.render(html` <md-list>
|
|
|
|
<md-list-item type="button"></md-list-item>
|
|
|
|
</md-list>`);
|
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
const first = root.querySelector('md-list-item')!;
|
2023-06-21 21:32:45 +03:00
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
await env.waitForStability();
|
2023-06-21 21:32:45 +03:00
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
2023-06-21 21:32:45 +03:00
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
const nextItem = listEl.activatePreviousItem();
|
|
|
|
await env.waitForStability();
|
2023-06-21 21:32:45 +03:00
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
expect(first.tabIndex).toEqual(0);
|
|
|
|
expect(nextItem).toEqual(first);
|
|
|
|
expect(document.activeElement).toEqual(first);
|
|
|
|
});
|
2023-06-21 21:32:45 +03:00
|
|
|
});
|
2023-09-15 23:44:49 +03:00
|
|
|
|
|
|
|
describe('aria', () => {
|
|
|
|
it('Sets default role to list', async () => {
|
|
|
|
const root = env.render(html`<md-list></md-list>`);
|
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
await env.waitForStability();
|
2023-10-25 21:58:21 +03:00
|
|
|
const internals = (
|
|
|
|
listEl as unknown as {internals: {role: string | null}}
|
|
|
|
).internals;
|
2023-09-15 23:44:49 +03:00
|
|
|
|
|
|
|
expect(internals.role).toEqual('list');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Does not override user given role attribute', async () => {
|
|
|
|
const root = env.render(html`<md-list role="listbox"></md-list>`);
|
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
await env.waitForStability();
|
|
|
|
|
|
|
|
expect(listEl.getAttribute('role')).toBe('listbox');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Does not override user given role property', async () => {
|
|
|
|
const root = env.render(html`<md-list .role=${'listbox'}></md-list>`);
|
|
|
|
const listEl = root.querySelector('md-list')!;
|
|
|
|
await env.waitForStability();
|
|
|
|
|
|
|
|
expect(listEl.role).toBe('listbox');
|
|
|
|
});
|
|
|
|
});
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
2023-06-21 21:32:45 +03:00
|
|
|
|
2023-06-30 01:17:52 +03:00
|
|
|
describe('<md-list-item>', () => {
|
|
|
|
const env = new Environment();
|
|
|
|
|
|
|
|
describe('.styles', () => {
|
|
|
|
createTokenTests(MdListItem.styles);
|
|
|
|
});
|
2023-06-21 21:32:45 +03:00
|
|
|
|
2023-06-30 01:17:52 +03:00
|
|
|
describe('rendering', () => {
|
2023-09-15 04:14:21 +03:00
|
|
|
it('self-describes as a list-item', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(html` <md-list-item> </md-list-item>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
const listItemEl = root.querySelector('md-list-item')!;
|
2023-06-30 01:17:52 +03:00
|
|
|
|
|
|
|
await env.waitForStability();
|
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(listItemEl.hasAttribute('md-list-item')).toBeTrue();
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
2023-09-15 04:14:21 +03:00
|
|
|
});
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
it('disabled overrides tabIndex', async () => {
|
2023-09-26 00:02:45 +03:00
|
|
|
const root = env.render(html`<md-list-item type="button"></md-list-item>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
const listItem = root.querySelector('md-list-item')!;
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
await env.waitForStability();
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
const internalRoot = listItem.renderRoot.querySelector(
|
|
|
|
'#item',
|
|
|
|
) as HTMLElement;
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(internalRoot.tabIndex).toBe(0);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
listItem.disabled = true;
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
await env.waitForStability();
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
expect(listItem.disabled).toBeTrue();
|
|
|
|
expect(internalRoot.tabIndex).toBe(-1);
|
|
|
|
});
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-19 21:43:15 +03:00
|
|
|
it('ripple and focus ring rendered on interactive', async () => {
|
2023-09-15 04:14:21 +03:00
|
|
|
const root = env.render(html`<md-list-item></md-list-item>`);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
const listItem = root.querySelector('md-list-item')!;
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
await env.waitForStability();
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
let rippleEl = listItem.renderRoot.querySelector('md-ripple');
|
|
|
|
let focusRingEl = listItem.renderRoot.querySelector('md-focus-ring');
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-19 21:43:15 +03:00
|
|
|
expect(rippleEl).toBeNull();
|
|
|
|
expect(focusRingEl).toBeNull();
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-23 01:29:39 +03:00
|
|
|
listItem.type = 'button';
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
await env.waitForStability();
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-15 04:14:21 +03:00
|
|
|
rippleEl = listItem.renderRoot.querySelector('md-ripple');
|
|
|
|
focusRingEl = listItem.renderRoot.querySelector('md-focus-ring');
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-09-19 21:43:15 +03:00
|
|
|
expect(rippleEl).toBeTruthy();
|
|
|
|
expect(focusRingEl).toBeTruthy();
|
2023-06-21 21:32:45 +03:00
|
|
|
});
|
2023-03-04 02:04:37 +03:00
|
|
|
});
|
|
|
|
|
2023-08-04 23:18:02 +03:00
|
|
|
describe('<md-list-item> link', () => {
|
2023-06-30 01:17:52 +03:00
|
|
|
const env = new Environment();
|
|
|
|
|
2023-03-04 02:04:37 +03:00
|
|
|
describe('.styles', () => {
|
|
|
|
createTokenTests(MdListItem.styles);
|
|
|
|
});
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-08-04 23:18:02 +03:00
|
|
|
it('setting href renders an anchor tag', async () => {
|
|
|
|
const root = env.render(
|
2023-10-25 21:58:21 +03:00
|
|
|
html`<md-list-item href="https://google.com"></md-list-item>`,
|
|
|
|
);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-08-04 23:18:02 +03:00
|
|
|
const listItem = root.querySelector('md-list-item')!;
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-08-04 23:18:02 +03:00
|
|
|
await env.waitForStability();
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
const internalRoot = listItem.renderRoot.querySelector(
|
|
|
|
'#item',
|
|
|
|
) as HTMLElement;
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-08-04 23:18:02 +03:00
|
|
|
expect(internalRoot.tagName).toBe('A');
|
|
|
|
});
|
2023-09-15 03:47:21 +03:00
|
|
|
|
2023-08-04 23:18:02 +03:00
|
|
|
it('setting target without href renders nothing', async () => {
|
2023-10-25 21:58:21 +03:00
|
|
|
const root = env.render(
|
|
|
|
html`<md-list-item target="_blank"></md-list-item>`,
|
|
|
|
);
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-08-04 23:18:02 +03:00
|
|
|
const listItem = root.querySelector('md-list-item')!;
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-08-04 23:18:02 +03:00
|
|
|
await env.waitForStability();
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-10-25 21:58:21 +03:00
|
|
|
const internalRoot = listItem.renderRoot.querySelector(
|
|
|
|
'#item',
|
|
|
|
) as HTMLElement;
|
2023-06-30 01:17:52 +03:00
|
|
|
|
2023-08-04 23:18:02 +03:00
|
|
|
expect(internalRoot.hasAttribute('target')).toBe(false);
|
2023-06-30 01:17:52 +03:00
|
|
|
});
|
2022-07-25 20:44:44 +03:00
|
|
|
});
|