import { TestBed, ComponentFixture, async } from "@angular/core/testing";
import { RouterTestingModule } from "@angular/router/testing";
import { InvestmentProposalGeneralInfoComponent } from "./general-info.component";
import { By } from "@angular/platform-browser";
import { RouterOutlet, RouterLinkWithHref } from "@angular/router";
import { NO_ERRORS_SCHEMA } from "@angular/core";
import { HttpClientModule } from "@angular/common/http";
import { ReactiveFormsModule, FormsModule } from "@angular/forms";
import { FormInvestmentProposalService } from "@app/services/form-investment-proposal.service";
import { CatalogsService } from "@app/services/catalogs.service";
import { IAngularMyDpOptions, IMyDateModel } from "angular-mydatepicker";
import { InvestmentsService } from "@app/services/investments.service";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";

describe("InvestmentProposalGeneralInfoComponent", () => {
  let component: InvestmentProposalGeneralInfoComponent;
  let fixture: ComponentFixture<InvestmentProposalGeneralInfoComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [InvestmentProposalGeneralInfoComponent],
      imports: [
        RouterTestingModule,
        HttpClientModule,
        ReactiveFormsModule,
        FormsModule,
        BrowserAnimationsModule
      ],
      providers: [
        CatalogsService,
        InvestmentsService,
        FormInvestmentProposalService
      ],
      schemas: [NO_ERRORS_SCHEMA]
    }).compileComponents();
  }));

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

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

  it("Debe de tener un link a la página root", () => {
    const elementos = fixture.debugElement.queryAll(
      By.directive(RouterLinkWithHref)
    );

    // console.log( elementos );

    let existe = false;

    for (const elem of elementos) {
      if (elem.attributes["ng-reflect-router-link"] === "/") {
        existe = true;
        break;
      }
    }

    expect(existe).toBeTruthy();
  });
});
