import { TestBed, ComponentFixture, async } from "@angular/core/testing";
import { RouterTestingModule } from "@angular/router/testing";
import { InvestmentProposalsComponent } from "./investment-proposals.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 { CatalogsService } from "@app/services/catalogs.service";
import { InvestmentsService } from "@app/services/investments.service";
import {
  MatButtonModule,
  MatInputModule,
  MatRippleModule,
  MatFormFieldModule,
  MatSelectModule,
  MatExpansionModule,
  MatTableModule,
  MatPaginatorModule,
  MatProgressSpinnerModule,
  MatSortModule
} from "@angular/material";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";

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

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [InvestmentProposalsComponent],
      imports: [
        RouterTestingModule,
        HttpClientModule,
        ReactiveFormsModule,
        FormsModule,
        MatButtonModule,
        MatInputModule,
        MatRippleModule,
        MatFormFieldModule,
        MatSelectModule,
        MatExpansionModule,
        MatTableModule,
        MatPaginatorModule,
        MatProgressSpinnerModule,
        MatSortModule,
        BrowserAnimationsModule
      ],
      providers: [CatalogsService, InvestmentsService],
      schemas: [NO_ERRORS_SCHEMA]
    }).compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(InvestmentProposalsComponent);
    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 = false;
        break;
      }
    }

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