import { DebugElement, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { ShelfHistoryLogComponent } from './history-log.component';
import { ShelfHistoryLogHeaderComponent } from './log-header';
import { ShelfHistoryLogBodyComponent } from './log-body';
import { By } from '@angular/platform-browser';
import { historiesDtoMock, historyDtoMock } from '../../shared/mockdata';
import { HistoryDtoToInfoTextPipe, HistoryDtoToStatusTextPipe, GetStatusFromHistoryPipe } from '../../pages/shelf-history/pipes';
import { HistoryDTO } from '@cmf/trade-api';

fdescribe('HistoryLogComponent', () => {
  let fixture: ComponentFixture<ShelfHistoryLogComponent>;
  let component: ShelfHistoryLogComponent;
  let debugElement: DebugElement;

  beforeEach(async () => {
    TestBed.configureTestingModule({
      declarations: [
        ShelfHistoryLogComponent,
        ShelfHistoryLogHeaderComponent,
        ShelfHistoryLogBodyComponent,
        HistoryDtoToInfoTextPipe,
        HistoryDtoToStatusTextPipe,
        GetStatusFromHistoryPipe,
      ],
      schemas: [CUSTOM_ELEMENTS_SCHEMA],
    }).compileComponents();
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(ShelfHistoryLogComponent);
    component = fixture.componentInstance;
    debugElement = fixture.debugElement;

    const historyMockWithMultipleLogEntries: HistoryDTO = historiesDtoMock.find((history) => history.values && history.values.length > 2);
    component.history = historyMockWithMultipleLogEntries;

    fixture.detectChanges();
  });

  it('should be created', () => {
    expect(component instanceof ShelfHistoryLogComponent).toBeTruthy();
  });

  it('should show a header for all history values (log entries)', () => {
    const header = debugElement.queryAll(By.css('app-shelf-history-log-header'));

    expect(header.length).toBe(1);
  });

  it('should show an entry for each history value (log entry)', () => {
    const historyMockWithMultipleLogEntries: HistoryDTO = historiesDtoMock.find((history) => history.values && history.values.length > 2);

    fixture.detectChanges();

    const entries = debugElement.queryAll(By.css('app-shelf-history-log-body'));

    expect(entries.length).toBe(historyMockWithMultipleLogEntries.values.length);
  });
});
