Skip to content

Commit d4b53ef

Browse files
committed
fixup! feat(aria/combobox): add test harnesses
1 parent 63afee0 commit d4b53ef

5 files changed

Lines changed: 29 additions & 31 deletions

File tree

goldens/aria/simple-combobox/testing/index.api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { HarnessLoader } from '@angular/cdk/testing';
1212
import { HarnessPredicate } from '@angular/cdk/testing';
1313

1414
// @public
15-
export class SimpleComboboxHarness extends ContentContainerComponentHarness {
15+
export class ComboboxHarness extends ContentContainerComponentHarness {
1616
blur(): Promise<void>;
1717
close(): Promise<void>;
1818
focus(): Promise<void>;
@@ -32,11 +32,11 @@ export class SimpleComboboxHarness extends ContentContainerComponentHarness {
3232
isOpen(): Promise<boolean>;
3333
open(): Promise<void>;
3434
setValue(value: string): Promise<void>;
35-
static with(options?: SimpleComboboxHarnessFilters): HarnessPredicate<SimpleComboboxHarness>;
35+
static with(options?: ComboboxHarnessFilters): HarnessPredicate<ComboboxHarness>;
3636
}
3737

3838
// @public
39-
export interface SimpleComboboxHarnessFilters extends BaseHarnessFilters {
39+
export interface ComboboxHarnessFilters extends BaseHarnessFilters {
4040
disabled?: boolean;
4141
placeholder?: string | RegExp;
4242
value?: string | RegExp;

src/aria/simple-combobox/testing/simple-combobox-harness-filters.ts renamed to src/aria/simple-combobox/testing/combobox-harness-filters.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import {BaseHarnessFilters} from '@angular/cdk/testing';
1010

11-
/** A set of criteria that can be used to filter a list of `SimpleComboboxHarness` instances. */
12-
export interface SimpleComboboxHarnessFilters extends BaseHarnessFilters {
11+
/** A set of criteria that can be used to filter a list of `ComboboxHarness` instances. */
12+
export interface ComboboxHarnessFilters extends BaseHarnessFilters {
1313
/** Only find instances whose placeholder matches the given value. */
1414
placeholder?: string | RegExp;
1515
/** Only find instances whose value matches the given value. */

src/aria/simple-combobox/testing/simple-combobox-harness.spec.ts renamed to src/aria/simple-combobox/testing/combobox-harness.spec.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
1313
import {Combobox, ComboboxPopup, ComboboxWidget} from '../index';
1414
import {Listbox, Option} from '../../listbox';
1515
import {ListboxHarness, ListboxOptionHarness} from '../../listbox/testing/listbox-harness';
16-
import {SimpleComboboxHarness} from './simple-combobox-harness';
16+
import {ComboboxHarness} from './combobox-harness';
1717
import {OverlayModule} from '@angular/cdk/overlay';
1818

19-
describe('SimpleComboboxHarness', () => {
19+
describe('ComboboxHarness', () => {
2020
let fixture: ComponentFixture<any>;
2121
let loader: HarnessLoader;
2222

@@ -27,22 +27,22 @@ describe('SimpleComboboxHarness', () => {
2727
}
2828

2929
describe('Basic usage', () => {
30-
beforeEach(() => setupTest(SimpleComboboxTestApp));
30+
beforeEach(() => setupTest(ComboboxTestApp));
3131

3232
it('should load combobox harness', async () => {
33-
await expectAsync(loader.getHarness(SimpleComboboxHarness)).toBeResolved();
33+
await expectAsync(loader.getHarness(ComboboxHarness)).toBeResolved();
3434
});
3535

3636
it('should get and set values', async () => {
37-
const combobox = await loader.getHarness(SimpleComboboxHarness);
37+
const combobox = await loader.getHarness(ComboboxHarness);
3838
await combobox.setValue('California');
3939
fixture.detectChanges();
4040

4141
expect(await combobox.getValue()).toBe('California');
4242
});
4343

4444
it('should correctly report disabled state', async () => {
45-
const combobox = await loader.getHarness(SimpleComboboxHarness);
45+
const combobox = await loader.getHarness(ComboboxHarness);
4646
expect(await combobox.isDisabled()).toBeFalse();
4747

4848
fixture.componentInstance.disabled.set(true);
@@ -52,7 +52,7 @@ describe('SimpleComboboxHarness', () => {
5252
});
5353

5454
it('should open and close the popup', async () => {
55-
const combobox = await loader.getHarness(SimpleComboboxHarness);
55+
const combobox = await loader.getHarness(ComboboxHarness);
5656
expect(await combobox.isOpen()).toBeFalse();
5757

5858
await combobox.open();
@@ -65,7 +65,7 @@ describe('SimpleComboboxHarness', () => {
6565
});
6666

6767
it('should allow loading nested harnesses within the popup content via unified container API', async () => {
68-
const combobox = await loader.getHarness(SimpleComboboxHarness);
68+
const combobox = await loader.getHarness(ComboboxHarness);
6969
await combobox.open();
7070
fixture.detectChanges();
7171

@@ -76,15 +76,15 @@ describe('SimpleComboboxHarness', () => {
7676
});
7777

7878
it('should fail to resolve nested items when closed', async () => {
79-
const combobox = await loader.getHarness(SimpleComboboxHarness);
79+
const combobox = await loader.getHarness(ComboboxHarness);
8080
// Popup isn't open yet, so getPopupWidget should fail.
8181
await expectAsync(combobox.getPopupWidget(ListboxHarness)).toBeRejectedWithError(
8282
/Cannot retrieve popup content because the combobox is closed/,
8383
);
8484
});
8585

8686
it('should support getting explicit popup loader for descendant matching', async () => {
87-
const combobox = await loader.getHarness(SimpleComboboxHarness);
87+
const combobox = await loader.getHarness(ComboboxHarness);
8888
await combobox.open();
8989
fixture.detectChanges();
9090

@@ -95,7 +95,7 @@ describe('SimpleComboboxHarness', () => {
9595
});
9696

9797
it('should support focusing and blurring', async () => {
98-
const combobox = await loader.getHarness(SimpleComboboxHarness);
98+
const combobox = await loader.getHarness(ComboboxHarness);
9999
await combobox.focus();
100100
expect(await combobox.isFocused()).toBeTrue();
101101

@@ -106,8 +106,8 @@ describe('SimpleComboboxHarness', () => {
106106

107107
describe('Overlay and Popover integrations', () => {
108108
it('should find and resolve harnesses nested inside standard CdkOverlay', async () => {
109-
setupTest(SimpleComboboxOverlayTestApp);
110-
const combobox = await loader.getHarness(SimpleComboboxHarness);
109+
setupTest(ComboboxOverlayTestApp);
110+
const combobox = await loader.getHarness(ComboboxHarness);
111111

112112
await combobox.open();
113113
fixture.detectChanges();
@@ -119,8 +119,8 @@ describe('SimpleComboboxHarness', () => {
119119
});
120120

121121
it('should resolve nested harnesses when using Native Popover API', async () => {
122-
setupTest(SimpleComboboxNativePopoverTestApp);
123-
const combobox = await loader.getHarness(SimpleComboboxHarness);
122+
setupTest(ComboboxNativePopoverTestApp);
123+
const combobox = await loader.getHarness(ComboboxHarness);
124124

125125
await combobox.open();
126126
fixture.detectChanges();
@@ -153,7 +153,7 @@ describe('SimpleComboboxHarness', () => {
153153
`,
154154
imports: [Combobox, ComboboxPopup, ComboboxWidget, Listbox, Option],
155155
})
156-
class SimpleComboboxTestApp {
156+
class ComboboxTestApp {
157157
disabled = signal(false);
158158
}
159159

@@ -174,7 +174,7 @@ class SimpleComboboxTestApp {
174174
`,
175175
imports: [Combobox, ComboboxPopup, ComboboxWidget, Listbox, Option, OverlayModule],
176176
})
177-
class SimpleComboboxOverlayTestApp {
177+
class ComboboxOverlayTestApp {
178178
popupExpanded = signal(false);
179179
}
180180

@@ -195,6 +195,6 @@ class SimpleComboboxOverlayTestApp {
195195
`,
196196
imports: [Combobox, ComboboxPopup, ComboboxWidget, Listbox, Option, OverlayModule],
197197
})
198-
class SimpleComboboxNativePopoverTestApp {
198+
class ComboboxNativePopoverTestApp {
199199
popupExpanded = signal(false);
200200
}

src/aria/simple-combobox/testing/simple-combobox-harness.ts renamed to src/aria/simple-combobox/testing/combobox-harness.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ import {
1414
HarnessPredicate,
1515
TestKey,
1616
} from '@angular/cdk/testing';
17-
import {SimpleComboboxHarnessFilters} from './simple-combobox-harness-filters';
17+
import {ComboboxHarnessFilters} from './combobox-harness-filters';
1818

1919
/** Harness for interacting with a standard `ngCombobox` input element in tests. */
20-
export class SimpleComboboxHarness extends ContentContainerComponentHarness {
20+
export class ComboboxHarness extends ContentContainerComponentHarness {
2121
static hostSelector = '[ngCombobox]';
2222

2323
/**
2424
* Gets a `HarnessPredicate` that can be used to search for a combobox with specific attributes.
2525
* @param options Options for filtering which combobox instances are considered a match.
2626
* @return a `HarnessPredicate` configured with the given options.
2727
*/
28-
static with(options: SimpleComboboxHarnessFilters = {}): HarnessPredicate<SimpleComboboxHarness> {
29-
return new HarnessPredicate(SimpleComboboxHarness, options)
28+
static with(options: ComboboxHarnessFilters = {}): HarnessPredicate<ComboboxHarness> {
29+
return new HarnessPredicate(ComboboxHarness, options)
3030
.addOption('placeholder', options.placeholder, async (harness, placeholder) =>
3131
HarnessPredicate.stringMatches(await harness.getPlaceholder(), placeholder),
3232
)
@@ -108,8 +108,6 @@ export class SimpleComboboxHarness extends ContentContainerComponentHarness {
108108
if (value) {
109109
await host.sendKeys(value);
110110
}
111-
// Trigger simulated standard input pipeline.
112-
await host.dispatchEvent('input');
113111
}
114112

115113
/** Gets the placeholder text of the combobox. */

src/aria/simple-combobox/testing/public-api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
export * from './simple-combobox-harness';
10-
export * from './simple-combobox-harness-filters';
9+
export * from './combobox-harness';
10+
export * from './combobox-harness-filters';

0 commit comments

Comments
 (0)