Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/

export type AutocompleteHarnessFilters = {
id?: string;
name?: string,
};
import {BaseHarnessFilters} from '@angular/cdk-experimental/testing';

export interface AutocompleteHarnessFilters extends BaseHarnessFilters {}
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ function runTests() {
});

it('should be able to get text inside the input', async () => {
const input = await loader.getHarness(harness.with({id: 'prefilled'}));
const input = await loader.getHarness(harness.with({selector: '#prefilled'}));
expect(await input.getText()).toBe('Prefilled value');
});

it('should get disabled state', async () => {
const enabled = await loader.getHarness(harness.with({id: 'plain'}));
const disabled = await loader.getHarness(harness.with({id: 'disabled'}));
const enabled = await loader.getHarness(harness.with({selector: '#plain'}));
const disabled = await loader.getHarness(harness.with({selector: '#disabled'}));

expect(await enabled.isDisabled()).toBe(false);
expect(await disabled.isDisabled()).toBe(true);
});

it('should focus and blur an input', async () => {
const input = await loader.getHarness(harness.with({id: 'plain'}));
const input = await loader.getHarness(harness.with({selector: '#plain'}));
expect(getActiveElementId()).not.toBe('plain');
await input.focus();
expect(getActiveElementId()).toBe('plain');
Expand All @@ -78,19 +78,19 @@ function runTests() {
});

it('should be able to type in an input', async () => {
const input = await loader.getHarness(harness.with({id: 'plain'}));
const input = await loader.getHarness(harness.with({selector: '#plain'}));
await input.enterText('Hello there');
expect(await input.getText()).toBe('Hello there');
});

it('should be able to get the autocomplete panel', async () => {
const input = await loader.getHarness(harness.with({id: 'plain'}));
const input = await loader.getHarness(harness.with({selector: '#plain'}));
await input.focus();
expect(await input.getPanel()).toBeTruthy();
});

it('should be able to get the autocomplete panel options', async () => {
const input = await loader.getHarness(harness.with({id: 'plain'}));
const input = await loader.getHarness(harness.with({selector: '#plain'}));
await input.focus();
const options = await input.getOptions();

Expand All @@ -99,7 +99,7 @@ function runTests() {
});

it('should be able to get the autocomplete panel groups', async () => {
const input = await loader.getHarness(harness.with({id: 'grouped'}));
const input = await loader.getHarness(harness.with({selector: '#grouped'}));
await input.focus();
const groups = await input.getOptionGroups();
const options = await input.getOptions();
Expand All @@ -113,13 +113,13 @@ function runTests() {
fixture.componentInstance.states = [];
fixture.detectChanges();

const input = await loader.getHarness(harness.with({id: 'plain'}));
const input = await loader.getHarness(harness.with({selector: '#plain'}));
await input.focus();
expect(await input.isPanelVisible()).toBe(false);
});

it('should be able to get whether the autocomplete is open', async () => {
const input = await loader.getHarness(harness.with({id: 'plain'}));
const input = await loader.getHarness(harness.with({selector: '#plain'}));

expect(await input.isOpen()).toBe(false);
await input.focus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ export class MatAutocompleteHarness extends ComponentHarness {
* @return a `HarnessPredicate` configured with the given options.
*/
static with(options: AutocompleteHarnessFilters = {}): HarnessPredicate<MatAutocompleteHarness> {
return new HarnessPredicate(MatAutocompleteHarness)
.addOption('name', options.name,
async (harness, name) => (await harness.getAttribute('name')) === name)
.addOption('id', options.id,
async (harness, id) => (await harness.getAttribute('id')) === id);
return new HarnessPredicate(MatAutocompleteHarness, options);
}

async getAttribute(attributeName: string): Promise<string|null> {
Expand Down