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

import { Logos } from "../config/Logos";

import { LogoComponent } from "./logo.component";

describe("LogoComponent", () => {
  let component: LogoComponent;
  let fixture: ComponentFixture<LogoComponent>;
  let compiled: HTMLElement;

  beforeEach(async () => {
    await TestBed.configureTestingModule({
      imports: [LogoComponent]
    }).compileComponents();

    fixture = TestBed.createComponent(LogoComponent);
    component = fixture.componentInstance;
  });

  for (const expected of Logos) {
    it(`should parse ${expected.alt} properties correctly`, () => {
      component.logo = expected;
      fixture.detectChanges();
      expect(component.logo).toBe(expected);
      expect(component.link).toBe(expected.link);
      expect(component.alt).toBe(expected.alt);
      expect(component.file).toBe(`/assets/img/${expected.file}`);
    });

    it(`should render ${expected.alt} correctly`, () => {
      component.logo = expected;
      fixture.detectChanges();
      compiled = fixture.nativeElement;
      const link = compiled.querySelector("a");
      expect(link?.href).toContain(expected.link);
      expect(link?.target).toBe("_blank");
      expect(link?.rel).toBe("noopener noreferrer");

      const logo = link?.querySelector("img");
      expect(logo?.src).toContain(`/assets/img/${expected.file}`);
      expect(logo?.classList).toContain("logo");
      expect(logo?.alt).toBe(expected.alt);
      expect(logo?.height).toBe(50);
    });
  }
});
