forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistbox-harness.spec.ts
More file actions
93 lines (69 loc) · 2.68 KB
/
listbox-harness.spec.ts
File metadata and controls
93 lines (69 loc) · 2.68 KB
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
90
91
92
93
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {Component} from '@angular/core';
import {TestBed} from '@angular/core/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {ListboxHarness, ListboxOptionHarness} from './listbox-harness';
import {Listbox, Option} from '../index';
describe('Listbox Harness', () => {
let fixture: any;
let loader: any;
@Component({
imports: [Listbox, Option],
template: `
<ul ngListbox [disabled]="false" [multi]="true" orientation="horizontal">
<li ngOption [value]="1" label="Apple" aria-selected="true">Apple</li>
<li ngOption [value]="2" label="Banana">Banana</li>
<div class="test-item">Inside Listbox</div>
</ul>
`,
})
class ListboxHarnessTestComponent {}
beforeEach(() => {
TestBed.configureTestingModule({
imports: [ListboxHarnessTestComponent],
});
fixture = TestBed.createComponent(ListboxHarnessTestComponent);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
});
it('finds the listbox container harness', async () => {
const listbox = await loader.getHarness(ListboxHarness);
expect(listbox).toBeTruthy();
});
it('returns all options scoped within the listbox', async () => {
const listbox = await loader.getHarness(ListboxHarness);
const options = await listbox.getOptions();
expect(options.length).toBe(2);
});
it('filters options by exact text content', async () => {
const listbox = await loader.getHarness(ListboxHarness);
const options = await listbox.getOptions({text: 'Apple'});
expect(options.length).toBe(1);
});
it('reports the disabled state of the listbox', async () => {
const listbox = await loader.getHarness(ListboxHarness);
const isDisabled = await listbox.isDisabled();
expect(isDisabled).toBeFalse();
});
it('reports the multi-selectable state of the listbox', async () => {
const listbox = await loader.getHarness(ListboxHarness);
const isMulti = await listbox.isMulti();
expect(isMulti).toBeTrue();
});
it('reports the orientation of the listbox', async () => {
const listbox = await loader.getHarness(ListboxHarness);
const orientation = await listbox.getOrientation();
expect(orientation).toBe('horizontal');
});
it('clicks an option inside the listbox', async () => {
const option = await loader.getHarness(ListboxOptionHarness.with({text: 'Apple'}));
await option.click();
expect(await option.isSelected()).toBeTrue();
});
});