/*
 * Copyright (C) 2023 Robert Bosch GmbH Copyright (C) 2023 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
 */

import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { BciCorePicklistIntl } from '../bci-core-picklist-intl';
import { BciCorePicklistComponent } from './bci-core-picklist.component';
import { BciCoreDragDropListComponent } from '../drag-drop-list/bci-core-drag-drop-list.component';
import { DragDropModule } from '@angular/cdk/drag-drop';
import { ScrollingModule } from '@angular/cdk/scrolling';
import { FormsModule } from '@angular/forms';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatListModule } from '@angular/material/list';
import { MatTooltipModule } from '@angular/material/tooltip';
import { MatCheckboxModule } from '@angular/material/checkbox';

describe('BciCorePicklistComponent', () => {
  let component: BciCorePicklistComponent;
  let fixture: ComponentFixture<BciCorePicklistComponent>;

  beforeEach(
    waitForAsync(async () => {
      await TestBed.configureTestingModule({
        declarations: [BciCorePicklistComponent, BciCoreDragDropListComponent],
        imports: [MatIconModule,MatCheckboxModule,
          MatFormFieldModule,FormsModule,
          MatTooltipModule,DragDropModule, 
          MatListModule,ScrollingModule,
          MatInputModule,BrowserAnimationsModule],
        providers: [BciCorePicklistIntl]
      }).compileComponents();
    })
  );

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

  afterEach(() => {
    fixture.destroy();
  });

  it('should show items, even when they are loaded asynchronously', (done) => {
    setTimeout(() => {
      component.source = ['bla', 'blub'];
      fixture.detectChanges();
      expect(fixture.debugElement.queryAll((el) => el.name === 'mat-list-option').length).toBe(2);
      expect(component.source).toContain('bla');
      done();
    }, 500);
  });
});
