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

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { inject, TestBed } from '@angular/core/testing';
import { MatButtonModule } from '@angular/material/button';
import { MatDialogModule, MatDialogRef } from '@angular/material/dialog';
import { MatIconModule } from '@angular/material/icon';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { AlertDialogComponent } from './alert-dialog/alert-dialog.component';
import { AlertService } from './alert.service';
import { AlertType, PrimaryButton } from './models/alert.enums';
import { BCI_ALERT_DIALOG_INTL_PROVIDER } from './bci-alert-dialog-intl';

@NgModule({
  imports: [
    CommonModule,
    MatIconModule,
    MatDialogModule,
    MatButtonModule,
    RouterTestingModule,
    NoopAnimationsModule,
  ],
  declarations: [AlertDialogComponent],
})
class DialogTestModule {}

describe('AlertService', () => {
  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [
        DialogTestModule, // create a own Module, so we can define entryComponents (@angular/material2 do the same)
      ],
      providers: [AlertService, BCI_ALERT_DIALOG_INTL_PROVIDER],
    });
  });

  it('should be created', inject([AlertService], (service: AlertService) => {
    expect(service).toBeTruthy();
  }));

  it('should open a MatDialog and return the reference', inject([AlertService], (service: AlertService) => {
    const dialogRef = service.openAlertBox({
      title: 'Testing Dialog',
      primaryButton: PrimaryButton.LeftButton,
      description: 'This is just a testing case',
      type: AlertType.Error,
      leftButtonTitle: 'Close',
    });

    expect(dialogRef).toEqual(expect.any(MatDialogRef));
  }));
});
