-
Notifications
You must be signed in to change notification settings - Fork 6.7k
/
combobox.spec.ts
89 lines (69 loc) · 2.62 KB
/
combobox.spec.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import {Component, DebugElement} from '@angular/core';
import {ComponentFixture, TestBed, async} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {CdkComboboxModule} from './combobox-module';
import {CdkCombobox} from './combobox';
import {dispatchMouseEvent} from '@angular/cdk/testing/private';
describe('Combobox', () => {
describe('with a basic toggle trigger', () => {
let fixture: ComponentFixture<ComboboxToggle>;
let combobox: DebugElement;
let comboboxInstance: CdkCombobox<unknown>;
let comboboxElement: HTMLElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [CdkComboboxModule],
declarations: [ComboboxToggle],
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ComboboxToggle);
fixture.detectChanges();
combobox = fixture.debugElement.query(By.directive(CdkCombobox));
comboboxInstance = combobox.injector.get<CdkCombobox<unknown>>(CdkCombobox);
comboboxElement = combobox.nativeElement;
});
it('should have the combobox role', () => {
expect(comboboxElement.getAttribute('role')).toBe('combobox');
});
it('should update the aria disabled attribute', () => {
comboboxInstance.disabled = true;
fixture.detectChanges();
expect(comboboxElement.getAttribute('aria-disabled')).toBe('true');
comboboxInstance.disabled = false;
fixture.detectChanges();
expect(comboboxElement.getAttribute('aria-disabled')).toBe('false');
});
it('should have a panel that is closed by default', () => {
expect(comboboxInstance.hasPanel()).toBeTrue();
expect(comboboxInstance.isOpen()).toBeFalse();
});
it('should have an open action of click by default', () => {
expect(comboboxInstance.isOpen()).toBeFalse();
dispatchMouseEvent(comboboxElement, 'click');
fixture.detectChanges();
expect(comboboxInstance.isOpen()).toBeTrue();
});
it('should not open panel when disabled', () => {
expect(comboboxInstance.isOpen()).toBeFalse();
comboboxInstance.disabled = true;
fixture.detectChanges();
dispatchMouseEvent(comboboxElement, 'click');
fixture.detectChanges();
expect(comboboxInstance.isOpen()).toBeFalse();
});
});
});
@Component({
template: `
<button cdkCombobox #toggleCombobox class="example-combobox"
[cdkComboboxTriggerFor]="panel"
[openActions]="'focus'">
No Value
</button>
<ng-template cdkComboboxPanel #panel="cdkComboboxPanel">
Panel Content
</ng-template>`,
})
class ComboboxToggle {
}