Skip to content

Commit 9e79940

Browse files
authored
feat(material/sidenav/testing): polish harness API (#17415)
1 parent 36d34a6 commit 9e79940

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

src/material/sidenav/testing/drawer-harness-filters.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88

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

11-
export interface DrawerHarnessFilters extends BaseHarnessFilters {}
11+
export interface DrawerHarnessFilters extends BaseHarnessFilters {
12+
position?: 'start' | 'end';
13+
}

src/material/sidenav/testing/drawer-harness.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export class MatDrawerHarness extends ComponentHarness {
2323
* @return `HarnessPredicate` configured with the given options.
2424
*/
2525
static with(options: DrawerHarnessFilters = {}): HarnessPredicate<MatDrawerHarness> {
26-
return new HarnessPredicate(MatDrawerHarness, options);
26+
return new HarnessPredicate(MatDrawerHarness, options)
27+
.addOption('position', options.position,
28+
async (harness, position) => (await harness.getPosition()) === position);
2729
}
2830

2931
/** Gets whether the drawer is open. */

src/material/sidenav/testing/shared.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ export function runHarnessTests(sidenavModule: typeof MatSidenavModule,
3131
expect(drawers.length).toBe(3);
3232
});
3333

34+
it('should load drawer harness based on position', async () => {
35+
const drawers = await loader.getAllHarnesses(drawerHarness.with({position: 'end'}));
36+
expect(drawers.length).toBe(1);
37+
expect(await (await drawers[0].host()).text()).toBe('Two');
38+
});
39+
3440
it('should be able to get whether the drawer is open', async () => {
3541
const drawers = await loader.getAllHarnesses(drawerHarness);
3642

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export class MatSidenavHarness extends MatDrawerHarness {
2424
* @return `HarnessPredicate` configured with the given options.
2525
*/
2626
static with(options: DrawerHarnessFilters = {}): HarnessPredicate<MatDrawerHarness> {
27-
return new HarnessPredicate(MatDrawerHarness, options);
27+
return new HarnessPredicate(MatDrawerHarness, options)
28+
.addOption('position', options.position,
29+
async (harness, position) => (await harness.getPosition()) === position);
2830
}
2931

3032
/** Gets whether the sidenav is fixed in the viewport. */

0 commit comments

Comments
 (0)