mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
899f190da7
* test: add class with e2e test utilities * Adds a class that simplifies some common and hard to remember Protractor expressions. * Refactors the existing tests to use the new utilities. Fixes #2025. * Add types to the e2e utils and fix the selector on the dialog tests. * Remove unnecessary rounding. * Remove `any` cast. * Simplify the slide toggle tests. * Split the E2E utils class into smaller files. * Fix a leftover.
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import {browser} from 'protractor';
|
|
import {getElement, FinderResult, waitForElement} from './query';
|
|
import {Point} from './actions';
|
|
|
|
/**
|
|
* Asserts that an element exists.
|
|
*/
|
|
export function expectToExist(selector: string, expected = true) {
|
|
return waitForElement(selector).then((isPresent: boolean) => {
|
|
expect(isPresent).toBe(expected, `Expected "${selector}"${expected ? '' : ' not'} to exist`);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Asserts that an element is focused.
|
|
*/
|
|
export function expectFocusOn(element: FinderResult, expected = true): void {
|
|
expect(browser.driver.switchTo().activeElement().getId()).toBe(
|
|
getElement(element).getId(), `Expected element${expected ? '' : ' not'} to be focused.`);
|
|
}
|
|
|
|
/**
|
|
* Asserts that an element has a certan location.
|
|
*/
|
|
export function expectLocation(element: FinderResult, {x, y}: Point): void {
|
|
getElement(element).getLocation().then((location: Point) => {
|
|
expect(location.x).toEqual(x);
|
|
expect(location.y).toEqual(y);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Asserts that one element is aligned with another.
|
|
*/
|
|
export function expectAlignedWith(element: FinderResult, otherElement: FinderResult): void {
|
|
getElement(otherElement).getLocation().then((location: Point) => {
|
|
this.expectLocation(getElement(element), location);
|
|
});
|
|
}
|