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