2018-08-16 20:31:14 +02:00
|
|
|
import {browser, element, by, Key} from 'protractor';
|
2017-06-10 01:09:08 +02:00
|
|
|
import {expectToExist} from '../util/index';
|
2016-12-19 20:17:23 +02:00
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
|
2016-12-13 20:38:17 +01:00
|
|
|
describe('slide-toggle', () => {
|
2017-01-18 23:13:48 +01:00
|
|
|
const getInput = () => element(by.css('#normal-slide-toggle input'));
|
|
|
|
|
const getNormalToggle = () => element(by.css('#normal-slide-toggle'));
|
2016-12-13 20:38:17 +01:00
|
|
|
|
|
|
|
|
beforeEach(() => browser.get('slide-toggle'));
|
|
|
|
|
|
|
|
|
|
it('should render a slide-toggle', () => {
|
2017-09-28 13:45:03 -07:00
|
|
|
expectToExist('mat-slide-toggle');
|
2016-12-13 20:38:17 +01:00
|
|
|
});
|
|
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
it('should change the checked state on click', async () => {
|
2018-08-16 20:31:14 +02:00
|
|
|
const inputEl = getInput();
|
2016-12-13 20:38:17 +01:00
|
|
|
|
|
|
|
|
expect(inputEl.getAttribute('checked')).toBeFalsy('Expect slide-toggle to be unchecked');
|
|
|
|
|
|
2017-01-18 23:13:48 +01:00
|
|
|
getNormalToggle().click();
|
2016-12-13 20:38:17 +01:00
|
|
|
|
|
|
|
|
expect(inputEl.getAttribute('checked')).toBeTruthy('Expect slide-toggle to be checked');
|
|
|
|
|
});
|
|
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
it('should change the checked state on click', async () => {
|
2018-08-16 20:31:14 +02:00
|
|
|
const inputEl = getInput();
|
2016-12-13 20:38:17 +01:00
|
|
|
|
|
|
|
|
expect(inputEl.getAttribute('checked')).toBeFalsy('Expect slide-toggle to be unchecked');
|
|
|
|
|
|
2017-01-18 23:13:48 +01:00
|
|
|
getNormalToggle().click();
|
2016-12-13 20:38:17 +01:00
|
|
|
|
|
|
|
|
expect(inputEl.getAttribute('checked')).toBeTruthy('Expect slide-toggle to be checked');
|
|
|
|
|
});
|
|
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
it('should not change the checked state on click when disabled', async () => {
|
2018-08-16 20:31:14 +02:00
|
|
|
const inputEl = getInput();
|
2016-12-13 20:38:17 +01:00
|
|
|
|
|
|
|
|
expect(inputEl.getAttribute('checked')).toBeFalsy('Expect slide-toggle to be unchecked');
|
|
|
|
|
|
2017-01-18 23:13:48 +01:00
|
|
|
element(by.css('#disabled-slide-toggle')).click();
|
2016-12-13 20:38:17 +01:00
|
|
|
|
|
|
|
|
expect(inputEl.getAttribute('checked')).toBeFalsy('Expect slide-toggle to be unchecked');
|
|
|
|
|
});
|
|
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
it('should move the thumb on state change', async () => {
|
2018-08-16 20:31:14 +02:00
|
|
|
const slideToggleEl = getNormalToggle();
|
|
|
|
|
const thumbEl = element(by.css('#normal-slide-toggle .mat-slide-toggle-thumb-container'));
|
|
|
|
|
const previousPosition = await thumbEl.getLocation();
|
2016-12-13 20:38:17 +01:00
|
|
|
|
|
|
|
|
slideToggleEl.click();
|
|
|
|
|
|
2018-08-16 20:31:14 +02:00
|
|
|
const position = await thumbEl.getLocation();
|
2016-12-13 20:38:17 +01:00
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
expect(position.x).not.toBe(previousPosition.x);
|
2016-12-13 20:38:17 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should toggle the slide-toggle on space key', () => {
|
2018-08-16 20:31:14 +02:00
|
|
|
const inputEl = getInput();
|
2016-12-13 20:38:17 +01:00
|
|
|
|
|
|
|
|
expect(inputEl.getAttribute('checked')).toBeFalsy('Expect slide-toggle to be unchecked');
|
|
|
|
|
|
2017-01-18 23:13:48 +01:00
|
|
|
inputEl.sendKeys(Key.SPACE);
|
2016-12-13 20:38:17 +01:00
|
|
|
|
|
|
|
|
expect(inputEl.getAttribute('checked')).toBeTruthy('Expect slide-toggle to be checked');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|