Skip to content

Commit 4b06b90

Browse files
authored
docs(cdk/testing): copy over doc comments from base class to subclasses (#22437)
* docs(cdk/testing): copy over doc comments from base class to subclasses On our docs site, the docs are not inherited from the base class. This PR also marks our ProtractorHarnessEnvironment as deprecated * fixup! docs(cdk/testing): copy over doc comments from base class to subclasses
1 parent 03be924 commit 4b06b90

10 files changed

+224
-39
lines changed

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

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,49 +69,89 @@ function toProtractorModifierKeys(modifiers: ModifierKeys): string[] {
6969
return result;
7070
}
7171

72-
/** A `TestElement` implementation for Protractor. */
72+
/**
73+
* A `TestElement` implementation for Protractor.
74+
* @deprecated
75+
* @breaking-change 13.0.0
76+
*/
7377
export class ProtractorElement implements TestElement {
7478
constructor(readonly element: ElementFinder) {}
7579

80+
/** Blur the element. */
7681
async blur(): Promise<void> {
7782
return browser.executeScript('arguments[0].blur()', this.element);
7883
}
7984

85+
/** Clear the element's input (for input and textarea elements only). */
8086
async clear(): Promise<void> {
8187
return this.element.clear();
8288
}
8389

90+
/**
91+
* Click the element at the default location for the current environment. If you need to guarantee
92+
* the element is clicked at a specific location, consider using `click('center')` or
93+
* `click(x, y)` instead.
94+
*/
95+
click(modifiers?: ModifierKeys): Promise<void>;
96+
/** Click the element at the element's center. */
97+
click(location: 'center', modifiers?: ModifierKeys): Promise<void>;
98+
/**
99+
* Click the element at the specified coordinates relative to the top-left of the element.
100+
* @param relativeX Coordinate within the element, along the X-axis at which to click.
101+
* @param relativeY Coordinate within the element, along the Y-axis at which to click.
102+
* @param modifiers Modifier keys held while clicking
103+
*/
104+
click(relativeX: number, relativeY: number, modifiers?: ModifierKeys): Promise<void>;
84105
async click(...args: [ModifierKeys?] | ['center', ModifierKeys?] |
85106
[number, number, ModifierKeys?]): Promise<void> {
86107
await this._dispatchClickEventSequence(args, Button.LEFT);
87108
}
88109

110+
/**
111+
* Right clicks on the element at the specified coordinates relative to the top-left of it.
112+
* @param relativeX Coordinate within the element, along the X-axis at which to click.
113+
* @param relativeY Coordinate within the element, along the Y-axis at which to click.
114+
* @param modifiers Modifier keys held while clicking
115+
*/
116+
rightClick(relativeX: number, relativeY: number, modifiers?: ModifierKeys): Promise<void>;
89117
async rightClick(...args: [ModifierKeys?] | ['center', ModifierKeys?] |
90118
[number, number, ModifierKeys?]): Promise<void> {
91119
await this._dispatchClickEventSequence(args, Button.RIGHT);
92120
}
93121

122+
/** Focus the element. */
94123
async focus(): Promise<void> {
95124
return browser.executeScript('arguments[0].focus()', this.element);
96125
}
97126

127+
/** Get the computed value of the given CSS property for the element. */
98128
async getCssValue(property: string): Promise<string> {
99129
return this.element.getCssValue(property);
100130
}
101131

132+
/** Hovers the mouse over the element. */
102133
async hover(): Promise<void> {
103134
return browser.actions()
104135
.mouseMove(await this.element.getWebElement())
105136
.perform();
106137
}
107138

139+
/** Moves the mouse away from the element. */
108140
async mouseAway(): Promise<void> {
109141
return browser.actions()
110142
.mouseMove(await this.element.getWebElement(), {x: -1, y: -1})
111143
.perform();
112144
}
113145

146+
/**
147+
* Sends the given string to the input as a series of key presses. Also fires input events
148+
* and attempts to add the string to the Element's value.
149+
*/
114150
async sendKeys(...keys: (string | TestKey)[]): Promise<void>;
151+
/**
152+
* Sends the given string to the input as a series of key presses. Also fires input events
153+
* and attempts to add the string to the Element's value.
154+
*/
115155
async sendKeys(modifiers: ModifierKeys, ...keys: (string | TestKey)[]): Promise<void>;
116156
async sendKeys(...modifiersAndKeys: any[]): Promise<void> {
117157
const first = modifiersAndKeys[0];
@@ -135,37 +175,47 @@ export class ProtractorElement implements TestElement {
135175
return this.element.sendKeys(...keys);
136176
}
137177

178+
/**
179+
* Gets the text from the element.
180+
* @param options Options that affect what text is included.
181+
*/
138182
async text(options?: TextOptions): Promise<string> {
139183
if (options?.exclude) {
140184
return browser.executeScript(_getTextWithExcludedElements, this.element, options.exclude);
141185
}
142186
return this.element.getText();
143187
}
144188

189+
/** Gets the value for the given attribute from the element. */
145190
async getAttribute(name: string): Promise<string|null> {
146191
return browser.executeScript(
147192
`return arguments[0].getAttribute(arguments[1])`, this.element, name);
148193
}
149194

195+
/** Checks whether the element has the given class. */
150196
async hasClass(name: string): Promise<boolean> {
151197
const classes = (await this.getAttribute('class')) || '';
152198
return new Set(classes.split(/\s+/).filter(c => c)).has(name);
153199
}
154200

201+
/** Gets the dimensions of the element. */
155202
async getDimensions(): Promise<ElementDimensions> {
156203
const {width, height} = await this.element.getSize();
157204
const {x: left, y: top} = await this.element.getLocation();
158205
return {width, height, left, top};
159206
}
160207

208+
/** Gets the value of a property of an element. */
161209
async getProperty(name: string): Promise<any> {
162210
return browser.executeScript(`return arguments[0][arguments[1]]`, this.element, name);
163211
}
164212

213+
/** Sets the value of a property of an input. */
165214
async setInputValue(value: string): Promise<void> {
166215
return browser.executeScript(`arguments[0].value = arguments[1]`, this.element, value);
167216
}
168217

218+
/** Selects the options at the specified indexes inside of a native `select` element. */
169219
async selectOptions(...optionIndexes: number[]): Promise<void> {
170220
const options = await this.element.all(by.css('option'));
171221
const indexes = new Set(optionIndexes); // Convert to a set to remove duplicates.
@@ -187,17 +237,23 @@ export class ProtractorElement implements TestElement {
187237
}
188238
}
189239

240+
/** Checks whether this element matches the given selector. */
190241
async matchesSelector(selector: string): Promise<boolean> {
191242
return browser.executeScript(`
192243
return (Element.prototype.matches ||
193244
Element.prototype.msMatchesSelector).call(arguments[0], arguments[1])
194245
`, this.element, selector);
195246
}
196247

248+
/** Checks whether the element is focused. */
197249
async isFocused(): Promise<boolean> {
198250
return this.element.equals(browser.driver.switchTo().activeElement());
199251
}
200252

253+
/**
254+
* Dispatches an event with a particular name.
255+
* @param name Name of the event to be dispatched.
256+
*/
201257
async dispatchEvent(name: string, data?: Record<string, EventData>): Promise<void> {
202258
return browser.executeScript(_dispatchEvent, name, this.element, data);
203259
}

src/cdk/testing/protractor/protractor-harness-environment.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import {HarnessEnvironment, HarnessLoader, TestElement} from '@angular/cdk/testi
1010
import {by, element as protractorElement, ElementArrayFinder, ElementFinder} from 'protractor';
1111
import {ProtractorElement} from './protractor-element';
1212

13-
/** Options to configure the environment. */
13+
/**
14+
* Options to configure the environment.
15+
* @deprecated
16+
* @breaking-change 13.0.0
17+
*/
1418
export interface ProtractorHarnessEnvironmentOptions {
1519
/** The query function used to find DOM elements. */
1620
queryFn: (selector: string, root: ElementFinder) => ElementArrayFinder;
@@ -21,7 +25,11 @@ const defaultEnvironmentOptions: ProtractorHarnessEnvironmentOptions = {
2125
queryFn: (selector: string, root: ElementFinder) => root.all(by.css(selector))
2226
};
2327

24-
/** A `HarnessEnvironment` implementation for Protractor. */
28+
/**
29+
* A `HarnessEnvironment` implementation for Protractor.
30+
* @deprecated
31+
* @breaking-change 13.0.0
32+
*/
2533
export class ProtractorHarnessEnvironment extends HarnessEnvironment<ElementFinder> {
2634
/** The options for this environment. */
2735
private _options: ProtractorHarnessEnvironmentOptions;
@@ -45,25 +53,37 @@ export class ProtractorHarnessEnvironment extends HarnessEnvironment<ElementFind
4553
throw Error('This TestElement was not created by the ProtractorHarnessEnvironment');
4654
}
4755

56+
/**
57+
* Flushes change detection and async tasks captured in the Angular zone.
58+
* In most cases it should not be necessary to call this manually. However, there may be some edge
59+
* cases where it is needed to fully flush animation events.
60+
*/
4861
async forceStabilize(): Promise<void> {}
4962

63+
/** @docs-private */
5064
async waitForTasksOutsideAngular(): Promise<void> {
5165
// TODO: figure out how we can do this for the protractor environment.
5266
// https://github.com/angular/components/issues/17412
5367
}
5468

69+
/** Gets the root element for the document. */
5570
protected getDocumentRoot(): ElementFinder {
5671
return protractorElement(by.css('body'));
5772
}
5873

74+
/** Creates a `TestElement` from a raw element. */
5975
protected createTestElement(element: ElementFinder): TestElement {
6076
return new ProtractorElement(element);
6177
}
6278

79+
/** Creates a `HarnessLoader` rooted at the given raw element. */
6380
protected createEnvironment(element: ElementFinder): HarnessEnvironment<ElementFinder> {
6481
return new ProtractorHarnessEnvironment(element, this._options);
6582
}
6683

84+
/**
85+
* Gets a list of all elements matching the given selector under this environment's root element.
86+
*/
6787
protected async getAllRawElements(selector: string): Promise<ElementFinder[]> {
6888
const elementArrayFinder = this._options.queryFn(selector, this.rawRootElement);
6989
const length = await elementArrayFinder.count();

src/cdk/testing/test-element.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,14 @@ export interface TestElement {
145145
/** Checks whether the element is focused. */
146146
isFocused(): Promise<boolean>;
147147

148-
/**
149-
* Sets the value of a property of an input.
150-
*/
148+
/** Sets the value of a property of an input. */
151149
setInputValue(value: string): Promise<void>;
152150

153151
// Note that ideally here we'd be selecting options based on their value, rather than their
154152
// index, but we're limited by `@angular/forms` which will modify the option value in some cases.
155153
// Since the value will be truncated, we can't rely on it to do the lookup in the DOM. See:
156154
// https://github.com/angular/angular/blob/master/packages/forms/src/directives/select_control_value_accessor.ts#L19
157-
/**
158-
* Selects the options at the specified indexes inside of a native `select` element.
159-
*/
155+
/** Selects the options at the specified indexes inside of a native `select` element. */
160156
selectOptions(...optionIndexes: number[]): Promise<void>;
161157

162158
/**

src/cdk/testing/testbed/testbed-harness-environment.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ export class TestbedHarnessEnvironment extends HarnessEnvironment<Element> {
145145
return environment.createComponentHarness(harnessType, fixture.nativeElement);
146146
}
147147

148+
/**
149+
* Flushes change detection and async tasks captured in the Angular zone.
150+
* In most cases it should not be necessary to call this manually. However, there may be some edge
151+
* cases where it is needed to fully flush animation events.
152+
*/
148153
async forceStabilize(): Promise<void> {
149154
if (!disableAutoChangeDetection) {
150155
if (this._destroyed) {
@@ -155,6 +160,10 @@ export class TestbedHarnessEnvironment extends HarnessEnvironment<Element> {
155160
}
156161
}
157162

163+
/**
164+
* Waits for all scheduled or running async tasks to complete. This allows harness
165+
* authors to wait for async tasks outside of the Angular zone.
166+
*/
158167
async waitForTasksOutsideAngular(): Promise<void> {
159168
// If we run in the fake async zone, we run "flush" to run any scheduled tasks. This
160169
// ensures that the harnesses behave inside of the FakeAsyncTestZone similar to the
@@ -173,18 +182,24 @@ export class TestbedHarnessEnvironment extends HarnessEnvironment<Element> {
173182
await this._taskState.pipe(takeWhile(state => !state.stable)).toPromise();
174183
}
175184

185+
/** Gets the root element for the document. */
176186
protected getDocumentRoot(): Element {
177187
return document.body;
178188
}
179189

190+
/** Creates a `TestElement` from a raw element. */
180191
protected createTestElement(element: Element): TestElement {
181192
return new UnitTestElement(element, () => this.forceStabilize());
182193
}
183194

195+
/** Creates a `HarnessLoader` rooted at the given raw element. */
184196
protected createEnvironment(element: Element): HarnessEnvironment<Element> {
185197
return new TestbedHarnessEnvironment(element, this._fixture, this._options);
186198
}
187199

200+
/**
201+
* Gets a list of all elements matching the given selector under this environment's root element.
202+
*/
188203
protected async getAllRawElements(selector: string): Promise<Element[]> {
189204
await this.forceStabilize();
190205
return Array.from(this._options.queryFn(selector, this.rawRootElement));

0 commit comments

Comments
 (0)