This repository has been archived by the owner on Nov 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
selection-list-driver.ts
55 lines (43 loc) · 1.76 KB
/
selection-list-driver.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {DriverBase, simulate} from 'test-drive-react';
import {SelectionList} from '../../src';
import dividerBaseStyle from '../../src/components/selection-list/divider.st.css';
import optionBaseStyle from '../../src/components/selection-list/option.st.css';
import listBaseStyle from '../../src/components/selection-list/selection-list.st.css';
import {elementHasStylableClassName, elementHasStylableState} from '../utils';
export class SelectionListTestDriver extends DriverBase {
public static ComponentClass = SelectionList;
public focus(): void {
simulate.focus(this.root);
}
public blur(): void {
simulate.blur(this.root);
}
public get items(): Element[] {
return Array.from(this.root.children);
}
public get focusedIndex() {
const id = this.root.getAttribute('aria-activedescendant');
return id ? this.items.findIndex(element => element.id === id) : -1;
}
public keyDown(eventData: object): void {
simulate.keyDown(this.root, eventData);
}
public mouseDown(element: Element): void {
simulate.mouseDown(element, {button: 0});
}
public click(element: Element): void {
simulate.click(element, {button: 0});
}
public selectItem(index: number) {
simulate.click(this.items[index], {button: 0});
}
public isDivider(element: Element): boolean {
return elementHasStylableClassName(element, dividerBaseStyle, 'root');
}
public itemHasStylableState(index: number, stateName: string): boolean {
return elementHasStylableState(this.items[index], optionBaseStyle, stateName);
}
public hasStylableState(stateName: string): boolean {
return elementHasStylableState(this.root, listBaseStyle, stateName);
}
}