import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { LoginComponent } from './login.component';
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';
import { ChangeDetectorRef } from '@angular/core';
import { I18nService, UCAP_I18N_NAMESPACE } from '@ucap/ng-i18n';
import { AuthenticationUiModule } from '../authentication-ui.module';
import { MatSelectModule } from '@angular/material/select';
import { Company } from '@ucap/api-external';
import { LogService } from '@ucap/ng-logger';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatButtonModule } from '@angular/material/button';
import { MatCheckboxModule } from '@angular/material/checkbox';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';

describe('ui::authentication::LoginComponent', () => {
  let component: LoginComponent;
  let fixture: ComponentFixture<LoginComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [
        BrowserModule,
        BrowserAnimationsModule,

        CommonModule,
        ReactiveFormsModule,

        MatButtonModule,
        MatCheckboxModule,
        MatFormFieldModule,
        MatIconModule,
        MatInputModule,
        MatProgressSpinnerModule,
        MatSelectModule
      ],
      providers: [
        AuthenticationUiModule,
        // { provide: FormBuilder, useValue: new FormBuilder() },
        // { provide: ChangeDetectorRef, useValue: ChangeDetectorRef },
        { provide: I18nService, useValue: new I18nService(new LogService({})) },
        {
          provide: UCAP_I18N_NAMESPACE,
          useValue: 'authentication'
        }
      ]
    }).compileComponents();
  }));

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

  it('should create', () => {
    component.companyList = [
      { companyName: 'LG CNS', companyCode: 'GUC100' },
      { companyName: 'LG UCAP', companyCode: 'GUC101' }
    ] as Company[];
    component.loginId = 'test';
    component.companyCode = 'GUC100';
    fixture.detectChanges();

    component.ngOnInit();

    expect(component).toBeTruthy();
  });

  it('login', (done) => {
    component.companyList = [
      { companyName: 'LG CNS', companyCode: 'GUC100' },
      { companyName: 'LG UCAP', companyCode: 'GUC101' }
    ] as Company[];
    component.loginId = 'test';
    component.companyCode = 'GUC100';

    component.ngOnInit();

    component.login.subscribe((value) => {
      console.log(value);
      done();
    });

    component.onClickLogin();
  });
});
