aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/components/messageModal/message-modal.service.spec.ts
blob: ffaccb19866e5ac6bfef367639041f4c3ddb994e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import {MessageModal} from "./message-modal.service";
import {getTestBed, TestBed} from "@angular/core/testing";
import {SdcUiCommon} from "onap-ui-angular";
import each from "jest-each";
import {MessageBoxService} from "../messageBox/messageBox.service";
import {MessageModalModel} from "./message-modal.model";
import {MessageBoxData} from "../messageBox/messageBox.data";


describe('Message Modal Service', () => {
  let injector;
  let service: MessageModal;

  beforeAll(done => (async () => {
    TestBed.configureTestingModule({
      imports: [],
      providers: [MessageModal]
    });
    await TestBed.compileComponents();

    injector = getTestBed();
    service = injector.get(MessageModal);
  })().then(done).catch(done.fail));


  each([
    ["error", SdcUiCommon.ModalType.error],
    ["info", SdcUiCommon.ModalType.info],
    ["success", SdcUiCommon.ModalType.success]
  ]).test('getModalType with type %s should return %s', (inputMessageType, expectedResult) => {

    let message = {
      type: inputMessageType
    };

    const type = MessageModal.getModalType(<any>message)
    expect(type).toEqual(expectedResult);
  });

  test('showMessageModal should call open modal with all data' , async (done)=>{
    spyOn(MessageBoxService.openModal, 'next');
    let message : MessageModalModel  = new MessageModalModel('title', 'text',  "success", []);

    MessageModal.showMessageModal(message);
    setTimeout(()=>{
      const messageBoxData = new MessageBoxData( message.title,
        message.text,
        SdcUiCommon.ModalType.success,
        SdcUiCommon.ModalSize.medium,
        message.buttons)
      expect(MessageBoxService.openModal.next).toHaveBeenCalledWith(messageBoxData);
      done();
    }, 500)
  });

});