Skip to content

Commit 3230c33

Browse files
devversionjelbourn
authored andcommitted
chore(checkbox): add e2e test for spacebar checking (#2397)
* 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
1 parent 7cee84d commit 3230c33

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed
Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,41 @@
1-
import {browser, by, element} from 'protractor';
1+
import {browser, by, element, Key} from 'protractor';
22

33
describe('checkbox', function () {
4+
45
describe('check behavior', function () {
6+
57
beforeEach(function() {
68
browser.get('/checkbox');
79
});
8-
it('should be checked when clicked, and be unchecked when clicked again', function () {
9-
element(by.id('test-checkbox')).click();
10-
element(by.css('input[id=input-test-checkbox]')).getAttribute('checked').then((value: string) => {
10+
11+
it('should be checked when clicked, and be unchecked when clicked again', () => {
12+
let checkboxEl = element(by.id('test-checkbox'));
13+
let inputEl = element(by.css('input[id=input-test-checkbox]'));
14+
15+
checkboxEl.click();
16+
inputEl.getAttribute('checked').then((value: string) => {
1117
expect(value).toBeTruthy('Expect checkbox "checked" property to be true');
1218
});
1319

14-
element(by.id('test-checkbox')).click();
15-
element(by.css('input[id=input-test-checkbox]')).getAttribute('checked').then((value: string) => {
20+
checkboxEl.click();
21+
inputEl.getAttribute('checked').then((value: string) => {
22+
expect(value).toBeFalsy('Expect checkbox "checked" property to be false');
23+
});
24+
});
25+
26+
it('should toggle the checkbox when pressing space', () => {
27+
let inputEl = element(by.css('input[id=input-test-checkbox]'));
28+
29+
inputEl.getAttribute('checked').then((value: string) => {
1630
expect(value).toBeFalsy('Expect checkbox "checked" property to be false');
1731
});
32+
33+
inputEl.sendKeys(Key.SPACE);
34+
35+
inputEl.getAttribute('checked').then((value: string) => {
36+
expect(value).toBeTruthy('Expect checkbox "checked" property to be true');
37+
});
1838
});
39+
1940
});
2041
});

src/lib/checkbox/checkbox.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {ViewportRuler} from '../core/overlay/position/viewport-ruler';
1818
import {FakeViewportRuler} from '../core/overlay/position/fake-viewport-ruler';
1919

2020

21-
// TODO: Implement E2E tests for spacebar/click behavior for checking/unchecking
2221

2322
describe('MdCheckbox', () => {
2423
let fixture: ComponentFixture<any>;

0 commit comments

Comments
 (0)