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

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

import { TestimonialsComponent } from "./testimonials.component";

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

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

    fixture = TestBed.createComponent(TestimonialsComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it("should have expected properties", () => {
    expect(component.testimonials).toEqual(
      Testimonials.sort((a, b) => b.date.getTime() - a.date.getTime())
    );
  });

  it("should render reviews correctly", () => {
    compiled = fixture.nativeElement;
    const reviews = compiled.querySelectorAll("app-review");
    expect(reviews).toHaveSize(Testimonials.length);
    for (let i = 0; i < component.testimonials.length; i++) {
      const review = reviews[i];
      const content = review.querySelector("article");
      expect(content?.textContent).toBe(component.testimonials[i].content);
    }
  });
});
