<commit_before>import {async, ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
import {AddPhotoComponent} from './add-photo.component';
import {UserService} from '../../services/user.service';
import {AddPhotoService} from '../../services/add-photo.service';
import {UploadPhotoService} from '../../services/upload-photo.service';
import {ReactiveFormsModule} from '@angular/forms';
import {HttpClientService} from '../../services/http-client.service';
import {HttpModule} from '@angular/http';

describe('AddPhotoComponent', () => {
  let component: AddPhotoComponent;
  let fixture: ComponentFixture<AddPhotoComponent>;
  const blankForm = {photoName: '', title: '', description: ''};
  const populatedForm = {photoName: 'Rekz', title: 'Rekz photo', description: 'This is Rekz photo'};

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [AddPhotoComponent],
      providers: [UserService, AddPhotoService, UploadPhotoService, HttpClientService],
      imports: [ReactiveFormsModule, HttpModule]
    })
      .compileComponents();
  }));

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

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

  it(`should render 'Add your photo' text in h2 tag`, () => {
    fixture.detectChanges();
    const compiled = fixture.debugElement.nativeElement;
    expect(compiled.querySelector('h2').textContent).toEqual('Add your photo');
  });

  it('should have default properties', fakeAsync(() => {
    expect(component.addPhotoForm.value).toEqual(blankForm);
  }));

  it('should initialize form fields', fakeAsync(() => {
    updateFormAttributes('Rekz', 'Rekz photo', 'This is Rekz photo');
    expect(component.addPhotoForm.value).toEqual(populatedForm);
  }));

  it('photoAdded should be false if error occurred', async(() => {
    updateFormAttributes(blankForm.photoName, blankForm.title, blankForm.description);
    component.onSubmit();
    expect(component.photoAdded).toBeFalsy();
  }));

  /**
   *  create reusable function for a dry spec.
   */
  function updateFormAttributes(photoName, title, description) {
    component.addPhotoForm.controls['photoName'].setValue(photoName);
    component.addPhotoForm.controls['title'].setValue(title);
    component.addPhotoForm.controls['description'].setValue(description);
  }

});<commit_msg>front-end: updated add-photo component tests<commit_after>import {async, ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
import {AddPhotoComponent} from './add-photo.component';
import {UserService} from '../../services/user.service';
import {AddPhotoService} from '../../services/add-photo.service';
import {UploadPhotoService} from '../../services/upload-photo.service';
import {ReactiveFormsModule} from '@angular/forms';
import {HttpClientService} from '../../services/http-client.service';
import {HttpModule} from '@angular/http';

describe('AddPhotoComponent', () => {
  let component: AddPhotoComponent;
  let fixture: ComponentFixture<AddPhotoComponent>;
  const blankForm = {photoName: '', title: '', description: ''};
  const populatedForm = {photoName: 'Rekz', title: 'Rekz photo', description: 'This is Rekz photo'};

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [AddPhotoComponent],
      providers: [UserService, AddPhotoService, UploadPhotoService, HttpClientService],
      imports: [ReactiveFormsModule, HttpModule]
    })
      .compileComponents();
  }));

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

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

  it(`should render title in h2 tag`, () => {
    fixture.detectChanges();
    const compiled = fixture.debugElement.nativeElement;
    expect(compiled.querySelector('h2').textContent).toEqual('Uploading your favorite photos has never been this easy');
  });

  it('should have default properties', fakeAsync(() => {
    expect(component.addPhotoForm.value).toEqual(blankForm);
  }));

  it('should initialize form fields', fakeAsync(() => {
    updateFormAttributes('Rekz', 'Rekz photo', 'This is Rekz photo');
    expect(component.addPhotoForm.value).toEqual(populatedForm);
  }));

  it('photoAdded should be false if error occurred', async(() => {
    updateFormAttributes(blankForm.photoName, blankForm.title, blankForm.description);
    component.onSubmit();
    expect(component.photoAdded).toBeFalsy();
  }));

  /**
   *  create reusable function for a dry spec.
   */
  function updateFormAttributes(photoName, title, description) {
    component.addPhotoForm.controls['photoName'].setValue(photoName);
    component.addPhotoForm.controls['title'].setValue(title);
    component.addPhotoForm.controls['description'].setValue(description);
  }

});
{'fraction_non_alphanumeric': 0.15175019888623706, 'fraction_numerical': 0.0007955449482895784, 'mean_word_length': 4.944444444444445, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '1560560', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1395, 'n_words': 295}