<commit_before>import {
  describe,
  expect,
  it,
  inject,
  injectAsync,
  fakeAsync,
  tick,
  beforeEach
} from '@angular/core/testing';
import { By, DOCUMENT } from '@angular/platform-browser';
import { Component, Optional, DebugElement } from '@angular/core';
import { TestComponentBuilder, ComponentFixture } from '@angular/compiler/testing';
import { MdlCheckboxComponent } from './mdl-checkbox.component';

describe('Component: MdlCheckbox', () => {

  var builder: TestComponentBuilder;
  var doc: HTMLDocument;

  beforeEach(inject([TestComponentBuilder, DOCUMENT], function (tcb: TestComponentBuilder, document) {
    builder = tcb;
    doc = document;
  }));

  it('should add the css class mdl-checkbox to the host element', () => {

    return builder
      .createAsync(MdlTestCheckboxComponent).then( (fixture) => {

        fixture.detectChanges();

        let checkboxEl:HTMLElement = fixture.nativeElement.children.item(0);
        expect(checkboxEl.classList.contains('mdl-checkbox')).toBe(true);

      })
  });

  it('should support ngModel', () => {
    return builder
      .createAsync(MdlTestCheckboxComponent).then( (fixture) => {

          fixture.detectChanges();

          let instance = fixture.componentInstance;
          let component = fixture.debugElement.query(By.directive(MdlCheckboxComponent)).componentInstance;
          let el: HTMLInputElement = fixture.debugElement.query(By.css('input')).nativeElement;

          instance.checkboxValue1 = true;
          fixture.detectChanges();
          expect(el.checked).toEqual(true);

          component.value = false;
          fixture.detectChanges();
          expect(el.checked).toEqual(false);

      })
  })

  it('should change the value on click', () => {
    return builder
      .createAsync(MdlTestCheckboxComponent).then( (fixture) => {
        fixture.detectChanges();

        fakeAsync(() => {

          let instance = fixture.componentInstance;
          let component = fixture.debugElement.query(By.directive(MdlCheckboxComponent)).componentInstance;
          let el: HTMLInputElement = fixture.debugElement.query(By.css('input')).nativeElement;

          instance.checkboxValue1 = false;
          fixture.detectChanges();
          tick();
          expect(el.checked).toEqual(false);

          fixture.debugElement.query(By.directive(MdlCheckboxComponent)).nativeElement.click();
          fixture.detectChanges();
          tick();
          expect(el.checked).toEqual(true);
        })();
      })
  })

  it('should mark the component as focused and blured', () => {
    return builder
      .createAsync(MdlTestCheckboxComponent).then( (fixture) => {
        fixture.detectChanges();

          let inputEl: HTMLInputElement = fixture.debugElement.query(By.css('input')).nativeElement;

          var evt = doc.createEvent('HTMLEvents');
          evt.initEvent('focus', true, true);
          inputEl.dispatchEvent(evt);

          fixture.detectChanges();

          let checkboxEl:HTMLElement = fixture.debugElement.query(By.directive(MdlCheckboxComponent)).nativeElement;
          expect(checkboxEl.classList.contains('is-focused')).toBe(true);

          var evtBlur = doc.createEvent('HTMLEvents');
          evtBlur.initEvent('blur', true, true);
          inputEl.dispatchEvent(evtBlur);

          fixture.detectChanges();
          expect(checkboxEl.classList.contains('is-focused')).toBe(false);

      })
  })

});


@Component({
  selector: 'test-icon',
  template: '<mdl-checkbox [(ngModel)]="checkboxValue1" mdl-ripple>checkbox label</mdl-checkbox>',
  directives: [MdlCheckboxComponent]
})
class MdlTestCheckboxComponent {
  checkboxValue1 = false;
}
<commit_msg>cleanup code<commit_after>import {
  describe,
  expect,
  it,
  inject,
  injectAsync,
  beforeEach
} from '@angular/core/testing';
import { By, DOCUMENT } from '@angular/platform-browser';
import { Component, Optional, DebugElement } from '@angular/core';
import { TestComponentBuilder, ComponentFixture } from '@angular/compiler/testing';
import { MdlCheckboxComponent } from './mdl-checkbox.component';

describe('Component: MdlCheckbox', () => {

  var builder: TestComponentBuilder;
  var doc: HTMLDocument;

  beforeEach(inject([TestComponentBuilder, DOCUMENT], function (tcb: TestComponentBuilder, document) {
    builder = tcb;
    doc = document;
  }));

  it('should add the css class mdl-checkbox to the host element', () => {

    return builder
      .createAsync(MdlTestCheckboxComponent).then( (fixture) => {

        fixture.detectChanges();

        let checkboxEl:HTMLElement = fixture.nativeElement.children.item(0);
        expect(checkboxEl.classList.contains('mdl-checkbox')).toBe(true);

      })
  });

  it('should support ngModel', () => {
    return builder
      .createAsync(MdlTestCheckboxComponent).then( (fixture) => {

          fixture.detectChanges();

          let instance = fixture.componentInstance;
          let component = fixture.debugElement.query(By.directive(MdlCheckboxComponent)).componentInstance;
          let el: HTMLInputElement = fixture.debugElement.query(By.css('input')).nativeElement;

          instance.checkboxValue1 = true;
          fixture.detectChanges();
          expect(el.checked).toEqual(true);

          component.value = false;
          fixture.detectChanges();
          expect(el.checked).toEqual(false);

      })
  })

  it('should change the value on click', () => {
    return builder
      .createAsync(MdlTestCheckboxComponent).then( (fixture) => {
        fixture.detectChanges();

          let instance = fixture.componentInstance;
          let component = fixture.debugElement.query(By.directive(MdlCheckboxComponent)).componentInstance;
          let el: HTMLInputElement = fixture.debugElement.query(By.css('input')).nativeElement;

          instance.checkboxValue1 = false;
          fixture.detectChanges();

          expect(el.checked).toEqual(false);

          fixture.debugElement.query(By.directive(MdlCheckboxComponent)).nativeElement.click();
          fixture.detectChanges();

          expect(el.checked).toEqual(true);

      })
  })

  it('should mark the component as focused and blured', () => {
    return builder
      .createAsync(MdlTestCheckboxComponent).then( (fixture) => {
        fixture.detectChanges();

          let inputEl: HTMLInputElement = fixture.debugElement.query(By.css('input')).nativeElement;

          var evt = doc.createEvent('HTMLEvents');
          evt.initEvent('focus', true, true);
          inputEl.dispatchEvent(evt);

          fixture.detectChanges();

          let checkboxEl:HTMLElement = fixture.debugElement.query(By.directive(MdlCheckboxComponent)).nativeElement;
          expect(checkboxEl.classList.contains('is-focused')).toBe(true);

          var evtBlur = doc.createEvent('HTMLEvents');
          evtBlur.initEvent('blur', true, true);
          inputEl.dispatchEvent(evtBlur);

          fixture.detectChanges();
          expect(checkboxEl.classList.contains('is-focused')).toBe(false);

      })
  })

});


@Component({
  selector: 'test-icon',
  template: '<mdl-checkbox [(ngModel)]="checkboxValue1" mdl-ripple>checkbox label</mdl-checkbox>',
  directives: [MdlCheckboxComponent]
})
class MdlTestCheckboxComponent {
  checkboxValue1 = false;
}

{'fraction_non_alphanumeric': 0.13064295485636115, 'fraction_numerical': 0.0013679890560875513, 'mean_word_length': 3.270443925233645, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6610123', 'n_tokens_mistral': 2046, 'n_tokens_neox': 2035, 'n_words': 350}