Files
angular__angular/e2e/components/slide-toggle-e2e.spec.ts
T
Kristiyan Kostadinov 8e6bee8116 chore: reorganize e2e test files (#5032)
* Renames the e2e test file to match the pattern of `{{component}}-e2e.spec.ts`.
* Flattens the directory structure in the `e2e` directory. Having a separate dir for each component was overkill since only have one file per component.
* Fixes some inconsistent code styles in the Protractor config.

Fixes #5030.
2017-06-09 16:09:08 -07:00

84 lines
2.7 KiB
TypeScript

import {browser, element, by, Key, ExpectedConditions} from 'protractor';
import {expectToExist} from '../util/index';
import {screenshot} from '../screenshot';
describe('slide-toggle', () => {
const getInput = () => element(by.css('#normal-slide-toggle input'));
const getNormalToggle = () => element(by.css('#normal-slide-toggle'));
beforeEach(() => browser.get('slide-toggle'));
it('should render a slide-toggle', () => {
expectToExist('md-slide-toggle');
screenshot();
});
it('should change the checked state on click', async () => {
let inputEl = getInput();
expect(inputEl.getAttribute('checked')).toBeFalsy('Expect slide-toggle to be unchecked');
getNormalToggle().click();
expect(inputEl.getAttribute('checked')).toBeTruthy('Expect slide-toggle to be checked');
await browser.wait(ExpectedConditions.not(
ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element')))));
screenshot();
});
it('should change the checked state on click', async () => {
let inputEl = getInput();
expect(inputEl.getAttribute('checked')).toBeFalsy('Expect slide-toggle to be unchecked');
getNormalToggle().click();
expect(inputEl.getAttribute('checked')).toBeTruthy('Expect slide-toggle to be checked');
await browser.wait(ExpectedConditions.not(
ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element')))));
screenshot();
});
it('should not change the checked state on click when disabled', async () => {
let inputEl = getInput();
expect(inputEl.getAttribute('checked')).toBeFalsy('Expect slide-toggle to be unchecked');
element(by.css('#disabled-slide-toggle')).click();
expect(inputEl.getAttribute('checked')).toBeFalsy('Expect slide-toggle to be unchecked');
await browser.wait(ExpectedConditions.not(
ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element')))));
screenshot();
});
it('should move the thumb on state change', async () => {
let slideToggleEl = getNormalToggle();
let thumbEl = element(by.css('#normal-slide-toggle .mat-slide-toggle-thumb-container'));
let previousPosition = await thumbEl.getLocation();
slideToggleEl.click();
let position = await thumbEl.getLocation();
expect(position.x).not.toBe(previousPosition.x);
await browser.wait(ExpectedConditions.not(
ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element')))));
screenshot();
});
it('should toggle the slide-toggle on space key', () => {
let inputEl = getInput();
expect(inputEl.getAttribute('checked')).toBeFalsy('Expect slide-toggle to be unchecked');
inputEl.sendKeys(Key.SPACE);
expect(inputEl.getAttribute('checked')).toBeTruthy('Expect slide-toggle to be checked');
});
});