<commit_before>/* tslint:disable:no-unused-variable */

/*!
 * NDVI Filter Form Component Test
 *
 * Copyright(c) <NAME> <<EMAIL>>
 * Licensed under MIT
 */

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { Router } from '@angular/router';
import { FormBuilder, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { FormsModule as SaraiInteractiveMapsFormsModule, FlatpickrComponent } from '../../forms';
import { LeafletMapService } from '../../leaflet';
import { LocationsService } from '../locations.service';
import { MockRouter } from '../../mocks/router';
import { MockLocationsService } from '../../mocks/map';
import { NdviFilterFormComponent } from './ndvi-filter-form.component';

describe('Component: NdviFilterForm', () => {
  let component: NdviFilterFormComponent;
  let fixture: ComponentFixture<NdviFilterFormComponent>;
  let mockRouter: MockRouter;

  // elements
  let startingDate: DebugElement;
  let startingDateEl: HTMLInputElement;
  let scanRange: DebugElement;
  let scanRangeEl: HTMLInputElement;
  let provinceSelect: DebugElement;
  let provinceSelectEl: HTMLElement;

  beforeEach(async(() => {
    mockRouter = new MockRouter();

    TestBed.configureTestingModule({
      declarations: [
        NdviFilterFormComponent
      ],
      imports: [
        FormsModule,
        ReactiveFormsModule,
        SaraiInteractiveMapsFormsModule
      ],
      providers: [
        FormBuilder,
        LeafletMapService,

        { provide: Router, useValue: mockRouter },
        { provide: LocationsService, useClass: MockLocationsService }
      ]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(NdviFilterFormComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();

    // get the starting date and helper element
    startingDate = fixture.debugElement.query(By.directive(FlatpickrComponent));
    startingDateEl = startingDate.nativeElement;

    // get the scan range element
    scanRange = fixture.debugElement.query(By.css('#ec_scan_range_txt'));
    scanRangeEl = scanRange.nativeElement;

    // get the province selector
    provinceSelect = fixture.debugElement.query(By.css('#ec_province_filter_sel'));
    provinceSelectEl = provinceSelect.nativeElement;
  });

  it('should create component', () => {
    expect(component).toBeTruthy();
  });

  it('should show that date is required', async(() => {
    component.startDate.markAsTouched();

    // detect changes in the fixture
    fixture.detectChanges();

    setTimeout(() => {
      let helpBlockEl = startingDateEl.parentElement.querySelector('.help-block-wrapper');

      expect(helpBlockEl.children.length).toBe(1);
      expect(helpBlockEl.children[0].textContent.trim()).toBe('Starting Date is required.');
    }, 0);
  }));

  it('should not show any error messages for date', async(() => {
    // gain focus of the element
    startingDateEl.focus();

    startingDateEl.value = '2016-11-10';

    // dispatch input event
    startingDateEl.dispatchEvent(new Event('input'));

    // remove the focus from the event
    startingDateEl.blur();

    // detect changes in the fixture
    fixture.detectChanges();

    setTimeout(() => {
      let helpBlockEl = startingDateEl.parentElement.querySelector('.help-block-wrapper');

      expect(helpBlockEl.children.length).toBe(0);
    }, 0);
  }));

  it('should show that scan range is required', async(() => {
    scanRangeEl.focus();
    scanRangeEl.blur();

    // detect changes in the fixture<commit_msg>Remove irrelevant unit test<commit_after>/* tslint:disable:no-unused-variable */

/*!
 * NDVI Filter Form Component Test
 *
 * Copyright(c) <NAME> <<EMAIL>>
 * Licensed under MIT
 */

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { Router } from '@angular/router';
import { FormBuilder, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { FormsModule as SaraiInteractiveMapsFormsModule, FlatpickrComponent } from '../../forms';
import { LeafletMapService } from '../../leaflet';
import { LocationsService } from '../locations.service';
import { MockRouter } from '../../mocks/router';
import { MockLocationsService } from '../../mocks/map';
import { NdviFilterFormComponent } from './ndvi-filter-form.component';

describe('Component: NdviFilterForm', () => {
  let component: NdviFilterFormComponent;
  let fixture: ComponentFixture<NdviFilterFormComponent>;
  let mockRouter: MockRouter;

  // elements
  let startingDate: DebugElement;
  let startingDateEl: HTMLInputElement;
  let scanRange: DebugElement;
  let scanRangeEl: HTMLInputElement;
  let provinceSelect: DebugElement;
  let provinceSelectEl: HTMLElement;

  beforeEach(async(() => {
    mockRouter = new MockRouter();

    TestBed.configureTestingModule({
      declarations: [
        NdviFilterFormComponent
      ],
      imports: [
        FormsModule,
        ReactiveFormsModule,
        SaraiInteractiveMapsFormsModule
      ],
      providers: [
        FormBuilder,
        LeafletMapService,

        { provide: Router, useValue: mockRouter },
        { provide: LocationsService, useClass: MockLocationsService }
      ]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(NdviFilterFormComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();

    // get the starting date and helper element
    startingDate = fixture.debugElement.query(By.directive(FlatpickrComponent));
    startingDateEl = startingDate.nativeElement;

    // get the scan range element
    scanRange = fixture.debugElement.query(By.css('#ec_scan_range_txt'));
    scanRangeEl = scanRange.nativeElement;

    // get the province selector
    provinceSelect = fixture.debugElement.query(By.css('#ec_province_filter_sel'));
    provinceSelectEl = provinceSelect.nativeElement;
  });

  it('should create component', () => {
    expect(component).toBeTruthy();
  });

  it('should show that date is required', async(() => {
    component.startDate.markAsTouched();

    // detect changes in the fixture
    fixture.detectChanges();

    setTimeout(() => {
      let helpBlockEl = startingDateEl.parentElement.querySelector('.help-block-wrapper');

      expect(helpBlockEl.children.length).toBe(1);
      expect(helpBlockEl.children[0].textContent.trim()).toBe('Starting Date is required.');
    }, 0);
  }));

  it('should show that scan range is required', async(() => {
    scanRangeEl.focus();
    scanRangeEl.blur();

    // detect changes in the fixture
{'fraction_non_alphanumeric': 0.1273154954425169, 'fraction_numerical': 0.0023522493384298734, 'mean_word_length': 3.734168406402227, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, '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': '827884', 'n_tokens_mistral': 1914, 'n_tokens_neox': 1879, 'n_words': 431}