From 15df44ad9b868ecaf6fd76d3d01574b512b311be Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Sat, 24 Dec 2016 15:35:06 +0100 Subject: [PATCH] chore(checkbox): add e2e test for spacebar checking * Adds the missing e2e test for the checkbox, where the space key should toggle the state * Cleanup the existing e2e test by removing repeating statements --- e2e/components/checkbox/checkbox.e2e.ts | 33 ++++++++++++++++++++----- src/lib/checkbox/checkbox.spec.ts | 1 - 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/e2e/components/checkbox/checkbox.e2e.ts b/e2e/components/checkbox/checkbox.e2e.ts index 18e2d434c348..9e941f6efcb3 100644 --- a/e2e/components/checkbox/checkbox.e2e.ts +++ b/e2e/components/checkbox/checkbox.e2e.ts @@ -1,20 +1,41 @@ -import {browser, by, element} from 'protractor'; +import {browser, by, element, Key} from 'protractor'; describe('checkbox', function () { + describe('check behavior', function () { + beforeEach(function() { browser.get('/checkbox'); }); - it('should be checked when clicked, and be unchecked when clicked again', function () { - element(by.id('test-checkbox')).click(); - element(by.css('input[id=input-test-checkbox]')).getAttribute('checked').then((value: string) => { + + it('should be checked when clicked, and be unchecked when clicked again', () => { + let checkboxEl = element(by.id('test-checkbox')); + let inputEl = element(by.css('input[id=input-test-checkbox]')); + + checkboxEl.click(); + inputEl.getAttribute('checked').then((value: string) => { expect(value).toBeTruthy('Expect checkbox "checked" property to be true'); }); - element(by.id('test-checkbox')).click(); - element(by.css('input[id=input-test-checkbox]')).getAttribute('checked').then((value: string) => { + checkboxEl.click(); + inputEl.getAttribute('checked').then((value: string) => { + expect(value).toBeFalsy('Expect checkbox "checked" property to be false'); + }); + }); + + it('should toggle the checkbox when pressing space', () => { + let inputEl = element(by.css('input[id=input-test-checkbox]')); + + inputEl.getAttribute('checked').then((value: string) => { expect(value).toBeFalsy('Expect checkbox "checked" property to be false'); }); + + inputEl.sendKeys(Key.SPACE); + + inputEl.getAttribute('checked').then((value: string) => { + expect(value).toBeTruthy('Expect checkbox "checked" property to be true'); + }); }); + }); }); diff --git a/src/lib/checkbox/checkbox.spec.ts b/src/lib/checkbox/checkbox.spec.ts index b88bf3b73da9..ff830032ffa6 100644 --- a/src/lib/checkbox/checkbox.spec.ts +++ b/src/lib/checkbox/checkbox.spec.ts @@ -18,7 +18,6 @@ import {ViewportRuler} from '../core/overlay/position/viewport-ruler'; import {FakeViewportRuler} from '../core/overlay/position/fake-viewport-ruler'; -// TODO: Implement E2E tests for spacebar/click behavior for checking/unchecking describe('MdCheckbox', () => { let fixture: ComponentFixture;