Skip to content

Commit

Permalink
fix(material/list/testing): avoid element selectors that could confli…
Browse files Browse the repository at this point in the history
…ct with the MDC version (#20528)

Simplifies the harness CSS selectors for list items. They currently
are built up based on element types but could be just using the
list-item class that is applied automatically by the component.

Also removes a few of the unnecessary `:not` selectors for
the standard `MatList` harness.

(cherry picked from commit 8d643a0)
  • Loading branch information
devversion authored and wagnermaciel committed Sep 15, 2020
1 parent 16f9f83 commit 989463f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/material/list/testing/action-list-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ export class MatActionListHarness extends MatListHarnessBase<
/** Harness for interacting with an action list item. */
export class MatActionListItemHarness extends MatListItemHarnessBase {
/** The selector for the host element of a `MatListItem` instance. */
static hostSelector = ['mat-list-item', 'a[mat-list-item]', 'button[mat-list-item]']
.map(selector => `${MatActionListHarness.hostSelector} ${selector}`)
.join(',');
static hostSelector = `${MatActionListHarness.hostSelector} .mat-list-item`;

/**
* Gets a `HarnessPredicate` that can be used to search for a `MatActionListItemHarness` that
Expand Down
6 changes: 2 additions & 4 deletions src/material/list/testing/list-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {getListItemPredicate, MatListItemHarnessBase} from './list-item-harness-
export class MatListHarness extends
MatListHarnessBase<typeof MatListItemHarness, MatListItemHarness, ListItemHarnessFilters> {
/** The selector for the host element of a `MatList` instance. */
static hostSelector = '.mat-list:not(mat-action-list):not(mat-nav-list):not(mat-selection-list)';
static hostSelector = '.mat-list:not(mat-action-list)';

/**
* Gets a `HarnessPredicate` that can be used to search for a `MatListHarness` that meets certain
Expand All @@ -33,9 +33,7 @@ export class MatListHarness extends
/** Harness for interacting with a list item. */
export class MatListItemHarness extends MatListItemHarnessBase {
/** The selector for the host element of a `MatListItem` instance. */
static hostSelector = ['mat-list-item', 'a[mat-list-item]', 'button[mat-list-item]']
.map(selector => `${MatListHarness.hostSelector} ${selector}`)
.join(',');
static hostSelector = `${MatListHarness.hostSelector} .mat-list-item`;

/**
* Gets a `HarnessPredicate` that can be used to search for a `MatListItemHarness` that meets
Expand Down
6 changes: 3 additions & 3 deletions src/material/list/testing/list-item-harness-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export class MatSubheaderHarness extends ComponentHarness {
* @docs-private
*/
export class MatListItemHarnessBase extends ComponentHarness {
private _lines = this.locatorForAll('[mat-line], [matLine]');
private _avatar = this.locatorForOptional('[mat-list-avatar], [matListAvatar]');
private _icon = this.locatorForOptional('[mat-list-icon], [matListIcon]');
private _lines = this.locatorForAll('.mat-line');
private _avatar = this.locatorForOptional('.mat-list-avatar');
private _icon = this.locatorForOptional('.mat-list-icon');

/** Gets the full text content of the list item (including text from any font icons). */
async getText(): Promise<string> {
Expand Down
4 changes: 1 addition & 3 deletions src/material/list/testing/nav-list-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ export class MatNavListHarness extends MatListHarnessBase<
/** Harness for interacting with a nav list item. */
export class MatNavListItemHarness extends MatListItemHarnessBase {
/** The selector for the host element of a `MatListItem` instance. */
static hostSelector = ['mat-list-item', 'a[mat-list-item]', 'button[mat-list-item]']
.map(selector => `${MatNavListHarness.hostSelector} ${selector}`)
.join(',');
static hostSelector = `${MatNavListHarness.hostSelector} .mat-list-item`;

/**
* Gets a `HarnessPredicate` that can be used to search for a `MatNavListItemHarness` that
Expand Down

0 comments on commit 989463f

Please sign in to comment.