Skip to content

Commit 989463f

Browse files
devversionwagnermaciel
authored andcommitted
fix(material/list/testing): avoid element selectors that could conflict 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)
1 parent 16f9f83 commit 989463f

File tree

4 files changed

+7
-13
lines changed

4 files changed

+7
-13
lines changed

src/material/list/testing/action-list-harness.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ export class MatActionListHarness extends MatListHarnessBase<
3333
/** Harness for interacting with an action list item. */
3434
export class MatActionListItemHarness extends MatListItemHarnessBase {
3535
/** The selector for the host element of a `MatListItem` instance. */
36-
static hostSelector = ['mat-list-item', 'a[mat-list-item]', 'button[mat-list-item]']
37-
.map(selector => `${MatActionListHarness.hostSelector} ${selector}`)
38-
.join(',');
36+
static hostSelector = `${MatActionListHarness.hostSelector} .mat-list-item`;
3937

4038
/**
4139
* Gets a `HarnessPredicate` that can be used to search for a `MatActionListItemHarness` that

src/material/list/testing/list-harness.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {getListItemPredicate, MatListItemHarnessBase} from './list-item-harness-
1515
export class MatListHarness extends
1616
MatListHarnessBase<typeof MatListItemHarness, MatListItemHarness, ListItemHarnessFilters> {
1717
/** The selector for the host element of a `MatList` instance. */
18-
static hostSelector = '.mat-list:not(mat-action-list):not(mat-nav-list):not(mat-selection-list)';
18+
static hostSelector = '.mat-list:not(mat-action-list)';
1919

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

4038
/**
4139
* Gets a `HarnessPredicate` that can be used to search for a `MatListItemHarness` that meets

src/material/list/testing/list-item-harness-base.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ export class MatSubheaderHarness extends ComponentHarness {
5151
* @docs-private
5252
*/
5353
export class MatListItemHarnessBase extends ComponentHarness {
54-
private _lines = this.locatorForAll('[mat-line], [matLine]');
55-
private _avatar = this.locatorForOptional('[mat-list-avatar], [matListAvatar]');
56-
private _icon = this.locatorForOptional('[mat-list-icon], [matListIcon]');
54+
private _lines = this.locatorForAll('.mat-line');
55+
private _avatar = this.locatorForOptional('.mat-list-avatar');
56+
private _icon = this.locatorForOptional('.mat-list-icon');
5757

5858
/** Gets the full text content of the list item (including text from any font icons). */
5959
async getText(): Promise<string> {

src/material/list/testing/nav-list-harness.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ export class MatNavListHarness extends MatListHarnessBase<
3333
/** Harness for interacting with a nav list item. */
3434
export class MatNavListItemHarness extends MatListItemHarnessBase {
3535
/** The selector for the host element of a `MatListItem` instance. */
36-
static hostSelector = ['mat-list-item', 'a[mat-list-item]', 'button[mat-list-item]']
37-
.map(selector => `${MatNavListHarness.hostSelector} ${selector}`)
38-
.join(',');
36+
static hostSelector = `${MatNavListHarness.hostSelector} .mat-list-item`;
3937

4038
/**
4139
* Gets a `HarnessPredicate` that can be used to search for a `MatNavListItemHarness` that

0 commit comments

Comments
 (0)