1b913cfe9c679873debc80745748809004d77b73
[vid.git] /
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
69
70   test('generateContextMenuOptions should return list of optional context menu', () => {
71     const options : TreeNodeContextMenuModel[] = service.generateContextMenuOptions();
72     const expected : TreeNodeContextMenuModel[] = [
73       new TreeNodeContextMenuModel('edit', 'context-menu-edit', 'Edit', 'edit-file-o'),
74       new TreeNodeContextMenuModel('duplicate', 'context-menu-duplicate', 'Duplicate', 'copy-o'),
75       new TreeNodeContextMenuModel('showAuditInfo', 'context-menu-showAuditInfo', 'Show audit info', 'eye-o'),
76       new TreeNodeContextMenuModel('addGroupMember', 'context-menu-addGroupMember', 'Add group members', 'plus'),
77       new TreeNodeContextMenuModel('delete', 'context-menu-delete', 'Delete', 'trash-o'),
78       new TreeNodeContextMenuModel('remove', 'context-menu-remove', 'Remove', 'trash-o'),
79       new TreeNodeContextMenuModel('undoDelete', 'context-menu-undoDelete', 'Undo Delete', 'undo-delete')
80     ];
81     expect(options.length).toEqual(7);
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 });