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

import { TestBed } from '@angular/core/testing';
import { WidgetDefinition } from '../models/widget-definition';
import { TestTextWidgetUserSetting } from '../widget/test-text-widget-component';
import { CatalogConf } from '../models/catalog-conf';
import { WidgetContentComponent } from '../models/widget-content-component';
import { WidgetCatalogService } from './widget-catalog.service';

describe('PinboardInteractionService', () => {
  let service: WidgetCatalogService;

  beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [WidgetCatalogService],
    });

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

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

  it('#widgetAdded should be triggered when a user tries to add a widget', () => {
    const catConf1 = {} as CatalogConf;
    catConf1.id = '101';
    catConf1.title = 'Widget One';
    catConf1.description = 'Random description';
    catConf1.categoryIds = ['1', '2'];

    const def1 = new WidgetDefinition<WidgetContentComponent, TestTextWidgetUserSetting, any>(
      '10',
      catConf1,
      'TextWidget'
    );

    service.widgetAdded.subscribe((res) => {
      expect(res).toEqual([def1]);
    });
    service.widgetAdded.next([def1]);
  });
});
