Skip to content

Commit 2f7a5ff

Browse files
committed
address feedback
1 parent 9f13740 commit 2f7a5ff

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

src/cdk/testing/protractor/protractor-element.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ export class ProtractorElement implements TestElement {
7373
return this.element.clear();
7474
}
7575

76-
async click(relativeX = 1, relativeY = 1): Promise<void> {
76+
async click(...args: number[]): Promise<void> {
77+
const offsetArgs = args.length ? [{x: args[0], y: args[1]}] : [];
7778
await browser.actions()
78-
.mouseMove(await this.element.getWebElement(), {x: relativeX, y: relativeY})
79+
.mouseMove(await this.element.getWebElement(), ...offsetArgs)
7980
.click()
8081
.perform();
8182
}

src/cdk/testing/test-element.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,15 @@ export interface TestElement {
6767
/** Clear the element's input (for input and textarea elements only). */
6868
clear(): Promise<void>;
6969

70+
/** Click the element at the element's center. */
71+
click(): Promise<void>;
72+
7073
/**
71-
* Click the element.
74+
* Click the element at the specified coordinates relative to the top-left of the element.
7275
* @param relativeX Coordinate within the element, along the X-axis at which to click.
7376
* @param relativeY Coordinate within the element, along the Y-axis at which to click.
7477
*/
75-
click(relativeX?: number, relativeY?: number): Promise<void>;
78+
click(relativeX: number, relativeY: number): Promise<void>;
7679

7780
/** Focus the element. */
7881
focus(): Promise<void>;

src/cdk/testing/testbed/unit-test-element.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ export class UnitTestElement implements TestElement {
7171
await this._stabilize();
7272
}
7373

74-
async click(relativeX = 1, relativeY = 1): Promise<void> {
75-
await this._stabilize();
76-
const {left, top} = this.element.getBoundingClientRect();
74+
async click(...args: number[]): Promise<void> {
75+
const {left, top, width, height} = await this.getDimensions();
76+
const relativeX = args.length ? args[0] : width / 2;
77+
const relativeY = args.length ? args[1] : height / 2;
78+
7779
// Round the computed click position as decimal pixels are not
7880
// supported by mouse events and could lead to unexpected results.
7981
const clientX = Math.round(left + relativeX);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {ProtractorHarnessEnvironment} from '@angular/cdk/testing/protractor';
2-
import {MatButtonHarness} from '@angular/material/button/testing/button-harness';
2+
import {MatButtonHarness} from '@angular/material/button/testing';
33
import {browser} from 'protractor';
44

55
describe('button harness', () => {

0 commit comments

Comments
 (0)