aboutsummaryrefslogtreecommitdiffstats
path: root/src/angular/modals/modal.component.spec.ts
blob: d1f6b789aa6c989c9b2234f8ae05bc4e667e9734 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Component, Input, NgModule, ViewContainerRef, Inject, Injectable, Type, ApplicationRef, ComponentFactoryResolver, ComponentRef, EmbeddedViewRef, Injector } from '@angular/core';
import { NO_ERRORS_SCHEMA } from '@angular/core/src/metadata/ng_module';
import { ModalService } from './modal.service';
import { CreateDynamicComponentService } from "../utils/create-dynamic-component.service";
import { IModalConfig, ModalType, ModalSize } from "../../../src/angular/modals/models/modal-config";

describe("Modal unit-tests", () => {
    let testService: ModalService;
    const testInputModal = {
        size: 'xl', // 'xl|l|md|sm|xsm'
        title: 'Test_Title',
        message: 'Test_Message',
        modalVisible: true
    };

    beforeEach(async(() => {
        // TestBed.configureTestingModule({
        //    providers: [
        //         ModalService,
        //         { provide : CreateDynamicComponentService, useClass: CreateDynamicComponentServiceTest}
        //     ],
        //     declarations: [],
        //     schemas: [NO_ERRORS_SCHEMA]
        // });
        // testService = TestBed.get(ModalService);
    }));

    it('Modal should be open test', () => {
        const modalInstance = testService.openModal(testInputModal);
        expect(modalInstance).toBeTruthy();
    });

    it('Modal warning window test', () => {
        const modalInstance = testService.openWarningModal('Worning title', 'testAlert', 'testMessage');
        expect(modalInstance).toBeTruthy();
    });

    it('Modal info window test', () => {
        const modalInstance = testService.openErrorModal('Error title', 'testMessage', 'sampleTestId');
        expect(modalInstance).toBeTruthy();
    });

    // it('Custom Modal should be open', () => {
    //     const modalConfig: IModalConfig = {
    //         size: ModalSize.medium,
    //         title: 'Title',
    //         type: ModalType.custom,
    //         buttons: [{text: "Save & Close", closeModal: true},
    //                   {text: "Save", callback: this.customModalOnSave, closeModal: false},
    //                   {text: "Cancel", type: 'secondary', closeModal: true}]
    //     } as IModalConfig;
    //     const modalInstance = testService.openCustomModal(modalConfig, ModalInnerContent, {name: "Sample Content"});
    //     expect(modalInstance).toBeTruthy();
    // });

    // it('Should close window', () => {
    //     const modalInstance = testService.openModal(testInputModal);
    //     modalInstance.instance.closeModal();
    //     expect(modalInstance.instance.modalVisible).toBeFalsy();
    // });
});

const testModalInstance = {
    instance: {
        closeAnimationComplete: {
            subscribe: () => {
                return true;
            },
        },
        _createDynamicComponentService: {
            insertComponentDynamically: () => {
                return true;
            }
        },
        modalVisible: true
    }
};

// @Component({
//     selector: 'modal-test',
//     template: `<div></div>`
// })

// export class CreateDynamicComponentServiceTest {
//     modalVisble: true;
//     public createComponentDynamically = (modalInstance, customData) => {
//         return testModalInstance;
//     }
//     public insertComponentDynamically = () => {
//         return testModalInstance;
//     }

// }