AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
| 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 13 | * or implied. See the License for the specific language governing |
| 14 | * permissions and limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | import {mapStateToProps} from 'sdc-app/onboarding/licenseModel/overview/LicenseModelOverview.js'; |
| 18 | import {overviewEditorHeaders, selectedButton} from 'sdc-app/onboarding/licenseModel/overview/LicenseModelOverviewConstants.js'; |
| 19 | |
| 20 | import {LicenseModelOverviewFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js'; |
| 21 | import { EntitlementPoolStoreFactory as EntitlementPool, EntitlementPoolDataListFactory } from 'test-utils/factories/licenseModel/EntitlementPoolFactories.js'; |
| 22 | import { FeatureGroupStoreFactory as FeatureGroup, FeatureGroupDataListFactory} from 'test-utils/factories/licenseModel/FeatureGroupFactories.js'; |
| 23 | import {LicenseAgreementStoreFactory as LicenseAgreement, LicenseAgreementDataListFactory} from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js'; |
| 24 | import { LicenseKeyGroupStoreFactory as LicenseKeyGroup, LicenseKeyGroupDataListFactory} from 'test-utils/factories/licenseModel/LicenseKeyGroupFactories.js'; |
| 25 | |
| 26 | describe('License Model Overview: ', function () { |
| 27 | |
| 28 | it('should mapper exist', () => { |
| 29 | expect(mapStateToProps).toBeTruthy(); |
| 30 | }); |
| 31 | |
| 32 | const VLM1 = LicenseModelOverviewFactory.build(); |
| 33 | |
| 34 | it('should mapper return vlm overview basic data', () => { |
| 35 | const state = { |
| 36 | licenseModel: VLM1 |
| 37 | }; |
| 38 | |
| 39 | var props = mapStateToProps(state); |
| 40 | expect(props.isReadOnlyMode).toEqual(true); |
| 41 | expect(props.isDisplayModal).toEqual(false); |
| 42 | expect(props.modalHeader).toEqual(undefined); |
| 43 | expect(props.licenseModelId).toEqual(VLM1.licenseModelEditor.data.id); |
| 44 | expect(props.licensingDataList).toEqual([]); |
| 45 | expect(props.selectedTab).toEqual(selectedButton.VLM_LIST_VIEW); |
| 46 | }); |
| 47 | |
| 48 | it('should mapper return overview data for show LA modal', () => { |
| 49 | const VLM1 = LicenseModelOverviewFactory.build({ |
| 50 | licenseAgreement: { |
| 51 | licenseAgreementEditor: { |
| 52 | data: LicenseAgreement.build() |
| 53 | } |
| 54 | } |
| 55 | }); |
| 56 | |
| 57 | var state = { |
| 58 | licenseModel: VLM1 |
| 59 | }; |
| 60 | |
| 61 | var props = mapStateToProps(state); |
| 62 | expect(props.isReadOnlyMode).toEqual(true); |
| 63 | expect(props.isDisplayModal).toEqual(true); |
| 64 | expect(props.modalHeader).toEqual(overviewEditorHeaders.LICENSE_AGREEMENT); |
| 65 | expect(props.licenseModelId).toEqual(VLM1.licenseModelEditor.data.id); |
| 66 | expect(props.licensingDataList).toEqual([]); |
| 67 | expect(props.selectedTab).toEqual(selectedButton.VLM_LIST_VIEW); |
| 68 | }); |
| 69 | |
| 70 | it('should mapper return overview data for show FG modal', () => { |
| 71 | |
| 72 | const VLM1 = LicenseModelOverviewFactory.build({ |
| 73 | featureGroup: { |
| 74 | featureGroupsList: [], |
| 75 | featureGroupEditor: { |
| 76 | data: FeatureGroup.build() |
| 77 | } |
| 78 | }, |
| 79 | entitlementPool: { |
| 80 | entitlementPoolsList: [] |
| 81 | }, |
| 82 | licenseKeyGroup: { |
| 83 | licenseKeyGroupsList: [] |
| 84 | }, |
| 85 | licenseModelOverview: { |
| 86 | selectedTab: selectedButton.NOT_IN_USE |
| 87 | } |
| 88 | }); |
| 89 | |
| 90 | var state = { |
| 91 | licenseModel: VLM1 |
| 92 | }; |
| 93 | |
| 94 | var props = mapStateToProps(state); |
| 95 | expect(props.isReadOnlyMode).toEqual(true); |
| 96 | expect(props.isDisplayModal).toEqual(true); |
| 97 | expect(props.modalHeader).toEqual(overviewEditorHeaders.FEATURE_GROUP); |
| 98 | expect(props.licenseModelId).toEqual(VLM1.licenseModelEditor.data.id); |
| 99 | expect(props.licensingDataList).toEqual([]); |
| 100 | expect(props.selectedTab).toEqual(selectedButton.NOT_IN_USE); |
| 101 | }); |
| 102 | |
| 103 | it('should mapper return overview data for show EP modal', () => { |
| 104 | const VLM1 = LicenseModelOverviewFactory.build({ |
| 105 | entitlementPool: { |
| 106 | entitlementPoolEditor: { |
| 107 | data: EntitlementPool.build() |
| 108 | } |
| 109 | } |
| 110 | }); |
| 111 | |
| 112 | var state = { |
| 113 | licenseModel: VLM1 |
| 114 | }; |
| 115 | |
| 116 | var props = mapStateToProps(state); |
| 117 | expect(props.isReadOnlyMode).toEqual(true); |
| 118 | expect(props.isDisplayModal).toEqual(true); |
| 119 | expect(props.modalHeader).toEqual(overviewEditorHeaders.ENTITLEMENT_POOL); |
| 120 | expect(props.licenseModelId).toEqual(VLM1.licenseModelEditor.data.id); |
| 121 | expect(props.licensingDataList).toEqual([]); |
| 122 | expect(props.selectedTab).toEqual(selectedButton.VLM_LIST_VIEW); |
| 123 | }); |
| 124 | |
| 125 | it('should mapper return overview data for show LKG modal', () => { |
| 126 | const VLM1 = LicenseModelOverviewFactory.build({ |
| 127 | licenseKeyGroup: { |
| 128 | licenseKeyGroupsList: [], |
| 129 | licenseKeyGroupsEditor: { |
| 130 | data: LicenseKeyGroup.build() |
| 131 | } |
| 132 | }, |
| 133 | entitlementPool: { |
| 134 | entitlementPoolsList: [] |
| 135 | }, |
| 136 | featureGroup: { |
| 137 | featureGroupsList: [] |
| 138 | }, |
| 139 | licenseModelOverview: { |
| 140 | selectedTab: selectedButton.NOT_IN_USE |
| 141 | } |
| 142 | }); |
| 143 | |
| 144 | var state = { |
| 145 | licenseModel: VLM1 |
| 146 | }; |
| 147 | |
| 148 | var props = mapStateToProps(state); |
| 149 | expect(props.isReadOnlyMode).toEqual(true); |
| 150 | expect(props.isDisplayModal).toEqual(true); |
| 151 | expect(props.modalHeader).toEqual(overviewEditorHeaders.LICENSE_KEY_GROUP); |
| 152 | expect(props.licenseModelId).toEqual(VLM1.licenseModelEditor.data.id); |
| 153 | expect(props.licensingDataList).toEqual([]); |
| 154 | expect(props.selectedTab).toEqual(selectedButton.NOT_IN_USE); |
| 155 | }); |
| 156 | |
| 157 | it('should mapper return overview data for Full-hierarchy list view', () => { |
| 158 | let EP1 = EntitlementPool.build(); |
| 159 | let LKG1 = LicenseKeyGroup.build(); |
| 160 | let FG1 = FeatureGroup.build({ |
| 161 | entitlementPoolsIds: [EP1.id], |
| 162 | licenseKeyGroupsIds: [LKG1.id] |
| 163 | }); |
| 164 | EP1.referencingFeatureGroups = [FG1.id]; |
| 165 | LKG1.referencingFeatureGroups = [FG1.id]; |
| 166 | let LA1 = LicenseAgreement.build({ |
| 167 | featureGroupsIds: [FG1.id] |
| 168 | }); |
| 169 | FG1.referencingLicenseAgreements = LA1.id; |
| 170 | let LA2 = LicenseAgreement.build(); |
| 171 | |
| 172 | const VLM1 = LicenseModelOverviewFactory.build({ |
| 173 | licenseAgreement: { |
| 174 | licenseAgreementList: [LA1, LA2] |
| 175 | }, |
| 176 | featureGroup: { |
| 177 | featureGroupsList: [FG1] |
| 178 | }, |
| 179 | entitlementPool: { |
| 180 | entitlementPoolsList: [EP1] |
| 181 | }, |
| 182 | licenseKeyGroup: { |
| 183 | licenseKeyGroupsList: [LKG1] |
| 184 | }, |
| 185 | }); |
| 186 | |
| 187 | const state = { |
| 188 | licenseModel: VLM1 |
| 189 | }; |
| 190 | |
| 191 | const expectedLicensingDataList = [ |
| 192 | LicenseAgreementDataListFactory.build({ |
| 193 | ...LA1, |
| 194 | children: [ |
| 195 | FeatureGroupDataListFactory.build({ |
| 196 | ...FG1, |
| 197 | children: [ |
| 198 | EntitlementPoolDataListFactory.build(EP1), |
| 199 | LicenseKeyGroupDataListFactory.build(LKG1) |
| 200 | ] |
| 201 | }) |
| 202 | ] |
| 203 | }), |
| 204 | LicenseAgreementDataListFactory.build(LA2) |
| 205 | ]; |
| 206 | |
| 207 | var props = mapStateToProps(state); |
| 208 | |
| 209 | expect(props.isReadOnlyMode).toEqual(true); |
| 210 | expect(props.isDisplayModal).toEqual(false); |
| 211 | expect(props.modalHeader).toEqual(undefined); |
| 212 | expect(props.licenseModelId).toEqual(VLM1.licenseModelEditor.data.id); |
| 213 | expect(props.licensingDataList).toEqual(expectedLicensingDataList); |
| 214 | expect(props.selectedTab).toEqual(selectedButton.VLM_LIST_VIEW); |
| 215 | }); |
| 216 | |
| 217 | it('should mapper return overview data for list view with 2 levels', () => { |
| 218 | let EP1 = EntitlementPool.build(); |
| 219 | let LKG1 = LicenseKeyGroup.build(); |
| 220 | let FG1 = FeatureGroup.build(); |
| 221 | let LA1 = LicenseAgreement.build({ |
| 222 | featureGroupsIds: [FG1.id] |
| 223 | }); |
| 224 | let LA2 = LicenseAgreement.build(); |
| 225 | FG1.referencingLicenseAgreements = [LA1.id]; |
| 226 | |
| 227 | const VLM1 = LicenseModelOverviewFactory.build({ |
| 228 | licenseAgreement: { |
| 229 | licenseAgreementList: [LA1, LA2] |
| 230 | }, |
| 231 | featureGroup: { |
| 232 | featureGroupsList: [FG1] |
| 233 | }, |
| 234 | entitlementPool: { |
| 235 | entitlementPoolsList: [EP1] |
| 236 | }, |
| 237 | licenseKeyGroup: { |
| 238 | licenseKeyGroupsList: [LKG1] |
| 239 | }, |
| 240 | }); |
| 241 | |
| 242 | const state = { |
| 243 | licenseModel: VLM1 |
| 244 | }; |
| 245 | |
| 246 | const expectedLicensingDataList = [ |
| 247 | LicenseAgreementDataListFactory.build({ |
| 248 | ...LA1, |
| 249 | children: [ |
| 250 | FeatureGroupDataListFactory.build(FG1) |
| 251 | ] |
| 252 | }), |
| 253 | LicenseAgreementDataListFactory.build(LA2) |
| 254 | ]; |
| 255 | |
| 256 | var props = mapStateToProps(state); |
| 257 | |
| 258 | expect(props.isReadOnlyMode).toEqual(true); |
| 259 | expect(props.isDisplayModal).toEqual(false); |
| 260 | expect(props.modalHeader).toEqual(undefined); |
| 261 | expect(props.licenseModelId).toEqual(VLM1.licenseModelEditor.data.id); |
| 262 | expect(props.licensingDataList).toEqual(expectedLicensingDataList); |
| 263 | expect(props.selectedTab).toEqual(selectedButton.VLM_LIST_VIEW); |
| 264 | }); |
| 265 | |
| 266 | it('should mapper return overview data for Full NOT-IN-USE list view', () => { |
| 267 | let EP1 = EntitlementPool.build(); |
| 268 | let LKG1 = LicenseKeyGroup.build(); |
| 269 | let FG1 = FeatureGroup.build(); |
| 270 | |
| 271 | const VLM1 = LicenseModelOverviewFactory.build({ |
| 272 | licenseAgreement: { licenseAgreementList: [] }, |
| 273 | featureGroup: { |
| 274 | featureGroupsList: [FG1] |
| 275 | }, |
| 276 | entitlementPool: { |
| 277 | entitlementPoolsList: [EP1] |
| 278 | }, |
| 279 | licenseKeyGroup: { |
| 280 | licenseKeyGroupsList: [LKG1] |
| 281 | }, |
| 282 | licenseModelOverview: { |
| 283 | selectedTab: selectedButton.NOT_IN_USE |
| 284 | } |
| 285 | }); |
| 286 | |
| 287 | const state = { |
| 288 | licenseModel: VLM1 |
| 289 | }; |
| 290 | |
| 291 | const expectedLicensingDataList = [ |
| 292 | FeatureGroupDataListFactory.build(FG1), |
| 293 | EntitlementPoolDataListFactory.build(EP1), |
| 294 | LicenseKeyGroupDataListFactory.build(LKG1) |
| 295 | ]; |
| 296 | |
| 297 | var props = mapStateToProps(state); |
| 298 | |
| 299 | expect(props.isReadOnlyMode).toEqual(true); |
| 300 | expect(props.isDisplayModal).toEqual(false); |
| 301 | expect(props.modalHeader).toEqual(undefined); |
| 302 | expect(props.licenseModelId).toEqual(VLM1.licenseModelEditor.data.id); |
| 303 | expect(props.licensingDataList).toEqual(expectedLicensingDataList); |
| 304 | expect(props.selectedTab).toEqual(selectedButton.NOT_IN_USE); |
| 305 | }); |
| 306 | |
| 307 | it('should mapper return overview data for NOT-IN-USE list view (FG with children)', () => { |
| 308 | let EP1 = EntitlementPool.build(); |
| 309 | let LKG1 = LicenseKeyGroup.build(); |
| 310 | let FG1 = FeatureGroup.build({ |
| 311 | entitlementPoolsIds: [EP1.id], |
| 312 | licenseKeyGroupsIds: [LKG1.id] |
| 313 | }); |
| 314 | EP1.referencingFeatureGroups = [FG1.id]; |
| 315 | LKG1.referencingFeatureGroups = [FG1.id]; |
| 316 | |
| 317 | const VLM1 = LicenseModelOverviewFactory.build({ |
| 318 | licenseAgreement: { licenseAgreementList: [] }, |
| 319 | featureGroup: { |
| 320 | featureGroupsList: [FG1] |
| 321 | }, |
| 322 | entitlementPool: { |
| 323 | entitlementPoolsList: [EP1] |
| 324 | }, |
| 325 | licenseKeyGroup: { |
| 326 | licenseKeyGroupsList: [LKG1] |
| 327 | }, |
| 328 | licenseModelOverview: { |
| 329 | selectedTab: selectedButton.NOT_IN_USE |
| 330 | } |
| 331 | }); |
| 332 | |
| 333 | const state = { |
| 334 | licenseModel: VLM1 |
| 335 | }; |
| 336 | |
| 337 | const expectedLicensingDataList = [ |
| 338 | FeatureGroupDataListFactory.build({ |
| 339 | ...FG1, |
| 340 | children: [ |
| 341 | EntitlementPoolDataListFactory.build(EP1), |
| 342 | LicenseKeyGroupDataListFactory.build(LKG1)] |
| 343 | }) |
| 344 | ]; |
| 345 | |
| 346 | var props = mapStateToProps(state); |
| 347 | |
| 348 | expect(props.isReadOnlyMode).toEqual(true); |
| 349 | expect(props.isDisplayModal).toEqual(false); |
| 350 | expect(props.modalHeader).toEqual(undefined); |
| 351 | expect(props.licenseModelId).toEqual(VLM1.licenseModelEditor.data.id); |
| 352 | expect(props.licensingDataList).toEqual(expectedLicensingDataList); |
| 353 | expect(props.selectedTab).toEqual(selectedButton.NOT_IN_USE); |
| 354 | }); |
| 355 | }); |