Skip to content

Commit

Permalink
chore(checkbox): add test for click + ngModel (#2738)
Browse files Browse the repository at this point in the history
  • Loading branch information
jelbourn authored and andrewseguin committed Jan 24, 2017
1 parent 5b76989 commit ffa622a
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/lib/checkbox/checkbox.spec.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
import {
async,
fakeAsync,
flushMicrotasks,
ComponentFixture,
TestBed,
} from '@angular/core/testing';
import {
NgControl,
FormsModule,
ReactiveFormsModule,
FormControl,
} from '@angular/forms';
import {async, fakeAsync, flushMicrotasks, ComponentFixture, TestBed} from '@angular/core/testing';
import {NgControl, FormsModule, ReactiveFormsModule, FormControl} from '@angular/forms';
import {Component, DebugElement} from '@angular/core';
import {By} from '@angular/platform-browser';
import {MdCheckbox, MdCheckboxChange, MdCheckboxModule} from './checkbox';
import {ViewportRuler} from '../core/overlay/position/viewport-ruler';
import {FakeViewportRuler} from '../core/overlay/position/fake-viewport-ruler';



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

Expand Down Expand Up @@ -586,9 +574,19 @@ describe('MdCheckbox', () => {
});

describe('with ngModel', () => {
let checkboxDebugElement: DebugElement;
let checkboxNativeElement: HTMLElement;
let checkboxInstance: MdCheckbox;
let inputElement: HTMLInputElement;

beforeEach(() => {
fixture = TestBed.createComponent(CheckboxWithFormDirectives);
fixture.detectChanges();

checkboxDebugElement = fixture.debugElement.query(By.directive(MdCheckbox));
checkboxNativeElement = checkboxDebugElement.nativeElement;
checkboxInstance = checkboxDebugElement.componentInstance;
inputElement = <HTMLInputElement>checkboxNativeElement.querySelector('input');
});

it('should be in pristine, untouched, and valid states initially', fakeAsync(() => {
Expand All @@ -604,6 +602,20 @@ describe('MdCheckbox', () => {
// TODO(jelbourn): test that `touched` and `pristine` state are modified appropriately.
// This is currently blocked on issues with async() and fakeAsync().
}));

it('should toggle checked state on click', () => {
expect(checkboxInstance.checked).toBe(false);

inputElement.click();
fixture.detectChanges();

expect(checkboxInstance.checked).toBe(true);

inputElement.click();
fixture.detectChanges();

expect(checkboxInstance.checked).toBe(false);
});
});

describe('with name attribute', () => {
Expand Down

0 comments on commit ffa622a

Please sign in to comment.