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

import { OverlayModule } from '@angular/cdk/overlay';
import { PortalModule } from '@angular/cdk/portal';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { MatBadgeModule } from '@angular/material/badge';
import { MatIconModule } from '@angular/material/icon';
import { MatListModule } from '@angular/material/list';
import { MatTooltipModule } from '@angular/material/tooltip';
import { RouterTestingModule } from '@angular/router/testing';

import { BciSidebarNavItemComponent } from './bci-sidebar-nav-item.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { BciSidebarService } from '../..';

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

  beforeEach(
    waitForAsync(async () => {
      await TestBed.configureTestingModule({
        imports: [
          RouterTestingModule,
          MatIconModule,
          MatBadgeModule,
          MatListModule,
          MatTooltipModule,
          OverlayModule,
          PortalModule,
          BrowserAnimationsModule
        ],
        declarations: [BciSidebarNavItemComponent],
      }).compileComponents();
    })
  );

  beforeEach(() => {
    fixture = TestBed.createComponent(BciSidebarNavItemComponent);
    component = fixture.componentInstance;
    component.navItem = {
      title: 'Test Nav Item',
    };
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should show only items with icons when collapsed', () => {
    const bciSidebarService = TestBed.inject(BciSidebarService);
    bciSidebarService.setSidebarState(false);

    delete component.navItem.icon;
    delete component.navItem.svgIcon;
    expect(component.isHidden).toBeTruthy();

    delete component.navItem.icon;
    component.navItem.svgIcon = 'foo';
    expect(component.isHidden).toBeFalsy();

    component.navItem.icon = 'foo';
    delete component.navItem.svgIcon;
    expect(component.isHidden).toBeFalsy();
  });
});
