Skip to content

Commit 4ee107d

Browse files
committed
allow users to specify location of button click
1 parent 306e60d commit 4ee107d

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/material-experimental/mdc-button/testing/button-harness.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,18 @@ export class MatButtonHarness extends ComponentHarness {
3737
(harness, text) => HarnessPredicate.stringMatches(harness.getText(), text));
3838
}
3939

40+
/**
41+
* Clicks the button at the given position relative to its top-left.
42+
* @param relativeX The relative x position of the click.
43+
* @param relativeY The relative y position of the click.
44+
*/
45+
click(relativeX: number, relativeY: number): Promise<void>;
46+
/** Clicks the button at its center. */
47+
click(location: 'center'): Promise<void>;
4048
/** Clicks the button. */
41-
async click(): Promise<void> {
42-
return (await this.host()).click();
49+
click(): Promise<void>;
50+
async click(...args: ['center'] | [number, number]): Promise<void> {
51+
return (await this.host()).click(...(args as [any]));
4352
}
4453

4554
/** Gets a boolean promise indicating if the button is disabled. */

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,18 @@ export class MatButtonHarness extends ComponentHarness {
3737
(harness, text) => HarnessPredicate.stringMatches(harness.getText(), text));
3838
}
3939

40+
/**
41+
* Clicks the button at the given position relative to its top-left.
42+
* @param relativeX The relative x position of the click.
43+
* @param relativeY The relative y position of the click.
44+
*/
45+
click(relativeX: number, relativeY: number): Promise<void>;
46+
/** Clicks the button at its center. */
47+
click(location: 'center'): Promise<void>;
4048
/** Clicks the button. */
41-
async click(): Promise<void> {
42-
return (await this.host()).click();
49+
click(): Promise<void>;
50+
async click(...args: ['center'] | [number, number]): Promise<void> {
51+
return (await this.host()).click(...(args as [any]));
4352
}
4453

4554
/** Whether the button is disabled. */

tools/public_api_guard/material/button/testing.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export interface ButtonHarnessFilters extends BaseHarnessFilters {
44

55
export declare class MatButtonHarness extends ComponentHarness {
66
blur(): Promise<void>;
7+
click(relativeX: number, relativeY: number): Promise<void>;
8+
click(location: 'center'): Promise<void>;
79
click(): Promise<void>;
810
focus(): Promise<void>;
911
getText(): Promise<string>;

0 commit comments

Comments
 (0)