import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormBuilder, FormControl } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { CookieService } from 'ngx-cookie-service';
import { NgxSpinnerService } from 'ngx-spinner';
import { AuthserviceService } from '../authservice.service';
import { LoginflowService } from '../data/loginflow.service';
import { blankUser, validUser } from '../mock';
import { ServicesService } from '../services.service';
import { CourseserviceService } from '../services/course/courseservice.service';
import { CryptoService } from '../services/crypto/crypto.service';

import { LoginComponent } from './login.component';
const router = jasmine.createSpyObj('Router', ['navigateByUrl']);
const loginflowService = jasmine.createSpyObj('LoginflowService', ['versions_getUserByEmail']);
const service = jasmine.createSpyObj('ServicesService', ['ShowError']);
const auth = jasmine.createSpyObj('AuthserviceService', ['login']);
const spinner = jasmine.createSpyObj('NgxSpinnerService', ['navigateByUrl']);
const route = jasmine.createSpyObj('ActivatedRoute', ['versions_getUserByEmail']);
const courseserviceService = jasmine.createSpyObj('CourseserviceService', ['ShowError']);
const cookieService = jasmine.createSpyObj('CookieService', ['login']);
const crypto = jasmine.createSpyObj('CryptoService', ['navigateByUrl']);


describe('Login Component Isolated Test', () => {
  let component: LoginComponent;

  beforeEach(async(() => {
    component = new LoginComponent(loginflowService, service, auth, spinner, new FormBuilder(), router, route, courseserviceService, cookieService, crypto);
    component.LoginForm
  }));

  function updateForm(userEmail, userPassword) {
    component.LoginForm.controls['email'].setValue(userEmail);
    component.LoginForm.controls['password'].setValue(userPassword);
  }

  it('Component successfully created', () => {
    expect(component).toBeTruthy();
  });

  it('component initial state', () => {
    expect(component.LoginForm).toBeDefined();
    expect(component.LoginForm.invalid).toBeTruthy();

  });


  it('form value should update from when u change the input', (() => {
    updateForm(validUser.email, validUser.password);
    expect(component.LoginForm.value).toEqual(validUser);
  }));

  it('Form invalid should be true when form is invalid', (() => {
    updateForm(blankUser.email, blankUser.password);
    expect(component.LoginForm.invalid).toBeTruthy();
  }));
});
