Test Cases Addition and Fixes
[vid.git] / vid-webpack-master / src / app / drawingBoard / service-planning / drawing-board-tree / drawing-board-tree.service.spec.ts
1 import {getTestBed, TestBed} from '@angular/core/testing';
2 import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
3 import {NgRedux} from "@angular-redux/store";
4 import {DrawingBoardTreeService, TreeNodeContextMenuModel} from "./drawing-board-tree.service";
5 import {ITreeNode} from "angular-tree-component/dist/defs/api";
6
7 class MockAppStore<T> {
8   getState() {
9     return {
10       service: {
11         serviceInstance: {
12           "serviceInstanceId": {
13             vnfs: {
14               "vnfStoreKey": {
15                 isMissingData: true,
16                 vfModules: {
17                   "vfModulesName": {
18                     "vfModulesName": {
19                       isMissingData: true
20                     }
21                   }
22                 }
23               },
24
25               "vnfStoreKey1": {
26                 isMissingData: false,
27                 vfModules: {
28                   "vfModulesName": {
29                     "vfModulesName": {
30                       isMissingData: false
31                     }
32                   }
33                 }
34               }
35             }
36           }
37         }
38       }
39     }
40   }
41 }
42
43 describe('Drawing board tree Service', () => {
44   let injector;
45   let service: DrawingBoardTreeService;
46   let httpMock: HttpTestingController;
47
48
49   beforeAll(done => (async () => {
50     TestBed.configureTestingModule({
51       imports: [HttpClientTestingModule],
52       providers: [
53         DrawingBoardTreeService,
54         {provide: NgRedux, useClass: MockAppStore}]
55     });
56     await TestBed.compileComponents();
57
58     injector = getTestBed();
59     service = injector.get(DrawingBoardTreeService);
60     httpMock = injector.get(HttpTestingController);
61
62   })().then(done).catch(done.fail));
63
64
65   test('generateContextMenuOptions should return list of optional context menu', () => {
66     const options: TreeNodeContextMenuModel[] = service.generateContextMenuOptions();
67     const expected: TreeNodeContextMenuModel[] = [
68       new TreeNodeContextMenuModel('edit', 'context-menu-edit', 'Edit', 'edit-file-o'),
69       new TreeNodeContextMenuModel('duplicate', 'context-menu-duplicate', 'Duplicate', 'copy-o'),
70       new TreeNodeContextMenuModel('showAuditInfo', 'context-menu-showAuditInfo', 'Show audit info', 'eye-o'),
71       new TreeNodeContextMenuModel('addGroupMember', 'context-menu-addGroupMember', 'Add group members', 'plus'),
72       new TreeNodeContextMenuModel('delete', 'context-menu-delete', 'Delete', 'trash-o'),
73       new TreeNodeContextMenuModel('remove', 'context-menu-remove', 'Remove', 'trash-o'),
74       new TreeNodeContextMenuModel('upgrade', 'context-menu-upgrade', 'Upgrade', 'upgrade'),
75       new TreeNodeContextMenuModel('undoDelete', 'context-menu-undoDelete', 'Undo Delete', 'undo-delete'),
76       new TreeNodeContextMenuModel('undoUpgrade', 'context-menu-undoUpgrade', 'Undo Upgrade', 'undo-delete'),
77       new TreeNodeContextMenuModel('changeAssociations', 'context-menu-changeAssociations', 'Change Associations', 'edit-file-o'),
78       new TreeNodeContextMenuModel('pauseInstantiation', 'context-menu-pause', 'Add pause upon completion', 'pause-upon-completion'),
79       new TreeNodeContextMenuModel('removePause', 'context-menu-removePause', 'Remove Pause', 'pause-upon-completion')
80     ];
81     expect(options.length).toEqual(12);
82     expect(options).toEqual(expected);
83   });
84
85   test('isVNFMissingData should return true if vnf isMissingData = true', () => {
86     let node: ITreeNode = <any>{
87       data: {
88         type: 'VF',
89         vnfStoreKey: "vnfStoreKey"
90       }
91     };
92     let result: boolean = service.isVNFMissingData(node, "serviceInstanceId");
93     expect(result).toBeTruthy();
94   });
95
96
97   test('isVNFMissingData should return false if vnf has isMissingData = false', () => {
98     let node: ITreeNode = <any>{
99       data: {
100         type: 'VFModule',
101         modelName: "vfModulesName",
102         dynamicModelName: "vfModulesName",
103         parent: {
104           vnfStoreKey: "vnfStoreKey1",
105           type: 'VF'
106         }
107       }
108     };
109     let result: boolean = service.isVNFMissingData(node, "serviceInstanceId");
110     expect(result).toBeFalsy();
111   });
112
113
114   test('isVFModuleMissingData should return true if vnfModule has isMissingData = true', () => {
115     let node: ITreeNode = <any>{
116       data: {
117         type: 'VFModule',
118         modelName: "vfModulesName",
119         dynamicModelName: "vfModulesName",
120         parent: {
121           vnfStoreKey: "vnfStoreKey",
122           type: 'VF'
123         }
124       }
125     };
126     let result: boolean = service.isVFModuleMissingData(node, "serviceInstanceId");
127     expect(result).toBeFalsy();
128   });
129
130
131   test('isVFModuleMissingData should return false if vnfModule has isMissingData = false', () => {
132     let node: ITreeNode = <any>{
133       data: {
134         type: 'VFModule',
135         modelName: "vfModulesName",
136         dynamicModelName: "vfModulesName",
137         parent: {
138           vnfStoreKey: "vnfStoreKey1",
139           type: 'VF'
140         }
141       }
142     };
143     let result: boolean = service.isVFModuleMissingData(node, "serviceInstanceId");
144     expect(result).toBeFalsy();
145   });
146
147 });