Updating INFO.yaml
[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     ];
80     expect(options.length).toEqual(11);
81     expect(options).toEqual(expected);
82   });
83
84   test('isVNFMissingData should return true if vnf isMissingData = true', () => {
85     let node: ITreeNode = <any>{
86       data: {
87         type: 'VF',
88         vnfStoreKey: "vnfStoreKey"
89       }
90     };
91     let result: boolean = service.isVNFMissingData(node, "serviceInstanceId");
92     expect(result).toBeTruthy();
93   });
94
95
96   test('isVNFMissingData should return false if vnf has isMissingData = false', () => {
97     let node: ITreeNode = <any>{
98       data: {
99         type: 'VFModule',
100         modelName: "vfModulesName",
101         dynamicModelName: "vfModulesName",
102         parent: {
103           vnfStoreKey: "vnfStoreKey1",
104           type: 'VF'
105         }
106       }
107     };
108     let result: boolean = service.isVNFMissingData(node, "serviceInstanceId");
109     expect(result).toBeFalsy();
110   });
111
112
113   test('isVFModuleMissingData should return true if vnfModule has isMissingData = true', () => {
114     let node: ITreeNode = <any>{
115       data: {
116         type: 'VFModule',
117         modelName: "vfModulesName",
118         dynamicModelName: "vfModulesName",
119         parent: {
120           vnfStoreKey: "vnfStoreKey",
121           type: 'VF'
122         }
123       }
124     };
125     let result: boolean = service.isVFModuleMissingData(node, "serviceInstanceId");
126     expect(result).toBeFalsy();
127   });
128
129
130   test('isVFModuleMissingData should return false if vnfModule has isMissingData = false', () => {
131     let node: ITreeNode = <any>{
132       data: {
133         type: 'VFModule',
134         modelName: "vfModulesName",
135         dynamicModelName: "vfModulesName",
136         parent: {
137           vnfStoreKey: "vnfStoreKey1",
138           type: 'VF'
139         }
140       }
141     };
142     let result: boolean = service.isVFModuleMissingData(node, "serviceInstanceId");
143     expect(result).toBeFalsy();
144   });
145
146 });