/*
 * Copyright (C) 2018 Robert Bosch GmbH Copyright (C) 2018 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 { BciPicklistIntl } from '../picklist-intl';
import { PicklistComponent } from './picklist.component';
import { MatIconModule } from '@angular/material/icon';
import { MatFormFieldModule } from '@angular/material/form-field';
import { DragDropListComponent } from '../drag-drop-list/drag-drop-list.component';
import { FormsModule } from '@angular/forms';
import { MatTooltipModule } from '@angular/material/tooltip';
import { DragDropModule } from '@angular/cdk/drag-drop';
import { MatListModule } from '@angular/material/list';
import { ScrollingModule } from '@angular/cdk/scrolling';
import { MatInputModule } from '@angular/material/input';

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

  beforeEach(
    waitForAsync(() => {
    TestBed.configureTestingModule({
        imports: [MatIconModule,
          MatFormFieldModule,FormsModule,
          MatTooltipModule,DragDropModule, 
          MatListModule,ScrollingModule,
          MatInputModule,
          BrowserAnimationsModule ],
        declarations: [PicklistComponent,DragDropListComponent],
        providers: [BciPicklistIntl]
      }).compileComponents();
    })
  );

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