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

import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { TestBed, waitForAsync } from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { BrowserTestingModule } from '@angular/platform-browser/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { BciCoreModule, BciLayoutModule, BciSharedModule, BreadcrumbsService } from '@bci-web-core/core';
import { of } from 'rxjs';
import { AppComponent } from './app.component';

describe('AppComponent', () => {
  let httpMock: HttpTestingController;
  let app: AppComponent;

  beforeEach(
    waitForAsync(() => {
      TestBed.configureTestingModule({
        imports: [
          RouterTestingModule,
          BrowserTestingModule,
          HttpClientTestingModule,
          NoopAnimationsModule,
          BciCoreModule.forRoot({ core_config_url: '/assets/config/config.json' }),
          BciSharedModule,
          BciLayoutModule,
        ],
        declarations: [AppComponent],
        providers: [{ provide: BreadcrumbsService, useValue: { breadcrumbs: of([]) } }],
      }).compileComponents();
      httpMock = TestBed.inject(HttpTestingController);

      const req = httpMock.expectOne(`/assets/config/config.json`);
      expect(req.request.method).toBe('GET');
      req.flush({});

      const fixture = TestBed.createComponent(AppComponent);
      app = fixture.debugElement.componentInstance;
    })
  );

  afterEach(() => {
    httpMock.verify();
  });

  it(
    'should create the app',
    waitForAsync(() => {
      expect(app).toBeTruthy();
    })
  );

  it(
    `should have as title 'Web Core Demo'`,
    waitForAsync(() => {
      expect(app.title).toEqual('Web Core Demo');
    })
  );
});
