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

import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
import { BciBannerComponent } from './bci-banner.component';
import { NotificationBannerService } from './../../notification/notification-banner.service';
import { NotificationTypes } from './../../notification/notification.models';

describe('BciBannerComponent', () => {
  let component: BciBannerComponent;
  let fixture: ComponentFixture<BciBannerComponent>;
  let notificationBannerService: NotificationBannerService;

  beforeEach(
    waitForAsync(() => {
      TestBed.configureTestingModule({
        declarations: [BciBannerComponent],
        schemas: [CUSTOM_ELEMENTS_SCHEMA],
      }).compileComponents();
    })
  );

  beforeEach(() => {
    fixture = TestBed.createComponent(BciBannerComponent);
    notificationBannerService = TestBed.inject(NotificationBannerService);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

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

  it('should show last banner', fakeAsync(() => {
    expect(component.hasBanner).toBeFalsy();
    const bannerId1 = notificationBannerService.showBanner('test1', NotificationTypes.Information, [], true);
    tick();
    expect(component.hasBanner).toBeTruthy();
    expect(component.banner.text).toEqual('test1');

    const bannerId2 = notificationBannerService.showBanner('test2', NotificationTypes.Information, [], true);
    tick();
    expect(component.hasBanner).toBeTruthy();
    expect(component.banner.text).toEqual('test2');

    const bannerId3 = notificationBannerService.showBanner('test3', NotificationTypes.Information, [], true);
    tick();
    expect(component.hasBanner).toBeTruthy();
    expect(component.banner.text).toEqual('test3');

    notificationBannerService.hideBanner(bannerId3);
    tick();
    expect(component.hasBanner).toBeTruthy();
    expect(component.banner.text).toEqual('test2');

    notificationBannerService.hideBanner(bannerId1);
    tick();
    expect(component.hasBanner).toBeTruthy();
    expect(component.banner.text).toEqual('test2');

    notificationBannerService.hideBanner(bannerId2);
    tick();
    expect(component.hasBanner).toBeFalsy();
    expect(component.banner).toBeUndefined();
  }));
});
