Files
angular__angular/e2e/components/slide-toggle-e2e.spec.ts
T
Kristiyan Kostadinov ac8339cc10 test: fix slide-toggle e2e failures (#12699)
Fixes some e2e failures in the slide toggle after the new design got in. The tests expect the ripples to go away at some point, however we introduced a permanent ripple.
2018-08-16 11:31:14 -07:00

68 lines
2.1 KiB
TypeScript

import {browser, element, by, Key} from 'protractor';
import {expectToExist} from '../util/index';
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('mat-slide-toggle');
});
it('should change the checked state on click', async () => {
const 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');
});
it('should change the checked state on click', async () => {
const 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');
});
it('should not change the checked state on click when disabled', async () => {
const 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');
});
it('should move the thumb on state change', async () => {
const slideToggleEl = getNormalToggle();
const thumbEl = element(by.css('#normal-slide-toggle .mat-slide-toggle-thumb-container'));
const previousPosition = await thumbEl.getLocation();
slideToggleEl.click();
const position = await thumbEl.getLocation();
expect(position.x).not.toBe(previousPosition.x);
});
it('should toggle the slide-toggle on space key', () => {
const 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');
});
});