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

import { TestBed } from '@angular/core/testing';
import { MatSnackBar, MatSnackBarModule, MatSnackBarRef, SimpleSnackBar } from '@angular/material/snack-bar';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { NotificationService } from './notification.service';

describe('NotificationService', () => {
  let service: NotificationService;
  const sessionStorageKey = 'webcore.core.notification.notifications';

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [MatSnackBarModule, NoopAnimationsModule],
      providers: [MatSnackBar],
    });

    service = TestBed.inject(NotificationService);
  });

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

  it('notification methods should return all a snackbar ref', () => {
    const infoRef: MatSnackBarRef<SimpleSnackBar> = service.information('');
    const succRef: MatSnackBarRef<SimpleSnackBar> = service.success('');
    const warnRef: MatSnackBarRef<SimpleSnackBar> = service.warning('');
    const errRef: MatSnackBarRef<SimpleSnackBar> = service.error('');
    expect(infoRef instanceof MatSnackBarRef).toBe(true);
    expect(succRef instanceof MatSnackBarRef).toBe(true);
    expect(warnRef instanceof MatSnackBarRef).toBe(true);
    expect(errRef instanceof MatSnackBarRef).toBe(true);
  });

  it('notification methods should write to the session storage', () => {
    // wipe the storage
    sessionStorage.clear();
    // open notification
    service.information('asdf1h234rweghwelituqöugoöwet§%&/§GDFGHR');
    // check sessionStorage
    expect(sessionStorage.getItem(sessionStorageKey)).toContain('asdf1h234rweghwelituqöugoöwet§%&/§GDFGHR');
  });
});
