b804342c6398eb2accbb366d9cc5476ef33269dd
[vid.git] / vid-webpack-master / src / app / drawingBoard / service-planning / drawing-board-tree / drawing-board-tree.service.spec.ts
1 import {TestBed, getTestBed} from '@angular/core/testing';
2 import {
3   HttpClientTestingModule,
4   HttpTestingController
5 } from '@angular/common/http/testing';
6 import {NgRedux} from "@angular-redux/store";
7 import {DrawingBoardTreeService, TreeNodeContextMenuModel} from "./drawing-board-tree.service";
8 import {ITreeNode} from "angular-tree-component/dist/defs/api";
9
10 class MockAppStore<T> {
11   getState() {
12     return {
13       service: {
14         serviceInstance: {
15           "serviceInstanceId": {
16             vnfs: {
17               "vnfStoreKey": {
18                 isMissingData: true,
19                 vfModules: {
20                   "vfModulesName": {
21                     "vfModulesName": {
22                       isMissingData: true
23                     }
24                   }
25                 }
26               },
27
28               "vnfStoreKey1": {
29                 isMissingData: false,
30                 vfModules: {
31                   "vfModulesName": {
32                     "vfModulesName": {
33                       isMissingData: false
34                     }
35                   }
36                 }
37               }
38             }
39           }
40         }
41       }
42     }
43   }
44 }
45
46 describe('Drawing board tree Service', () => {
47   let injector;
48   let service: DrawingBoardTreeService;
49   let httpMock: HttpTestingController;
50
51
52   beforeAll(done => (async () => {
53     TestBed.configureTestingModule({
54       imports: [HttpClientTestingModule],
55       providers: [
56         DrawingBoardTreeService,
57         {provide: NgRedux, useClass: MockAppStore}]
58     });
59     await TestBed.compileComponents();
60
61     injector = getTestBed();
62     service = injector.get(DrawingBoardTreeService);
63     httpMock = injector.get(HttpTestingController);
64
65   })().then(done).catch(done.fail));
66
67
68   test('generateContextMenuOptions should return list of optional context menu', () => {
69     const options: TreeNodeContextMenuModel[] = service.generateContextMenuOptions();
70     const expected: TreeNodeContextMenuModel[] = [
71       new TreeNodeContextMenuModel('edit', 'context-menu-edit', 'Edit', 'edit-file-o'),
72       new TreeNodeContextMenuModel('duplicate', 'context-menu-duplicate', 'Duplicate', 'copy-o'),
73       new TreeNodeContextMenuModel('showAuditInfo', 'context-menu-showAuditInfo', 'Show audit info', 'eye-o'),
74       new TreeNodeContextMenuModel('addGroupMember', 'context-menu-addGroupMember', 'Add group members', 'plus'),
75       new TreeNodeContextMenuModel('delete', 'context-menu-delete', 'Delete', 'trash-o'),
76       new TreeNodeContextMenuModel('remove', 'context-menu-remove', 'Remove', 'trash-o'),
77       new TreeNodeContextMenuModel('undoDelete', 'context-menu-undoDelete', 'Undo Delete', 'undo-delete'),
78       new TreeNodeContextMenuModel('changeAssociations', 'context-menu-changeAssociations', 'Change Associations', 'edit-file-o')
79     ];
80     expect(options.length).toEqual(8);
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 });