AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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 | * |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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. |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 17 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 18 | import Configuration from 'sdc-app/config/Configuration.js'; |
| 19 | import VersionControllerUtils from 'nfvo-components/panel/versionController/VersionControllerUtils.js'; |
| 20 | import {statusEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 21 | import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 22 | |
| 23 | const status = 'testStatus'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 24 | const {lockingUser: currentUser, viewableVersions: defaultVersions} = VersionControllerUtilsFactory.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 25 | |
| 26 | describe('versionController UI Component', () => { |
| 27 | |
| 28 | it('function does exist', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 29 | expect(VersionControllerUtils).toBeTruthy(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 30 | }); |
| 31 | |
| 32 | it('validating getCheckOutStatusKindByUserID - without "UserID"', () => { |
| 33 | var result = VersionControllerUtils.getCheckOutStatusKindByUserID(status); |
| 34 | expect(result.status).toBe(status); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 35 | expect(result.isCheckedOut).toBe(false); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 36 | }); |
| 37 | |
| 38 | it('validating getCheckOutStatusKindByUserID - without "UserID" with locking user', () => { |
| 39 | var result = VersionControllerUtils.getCheckOutStatusKindByUserID(status, 'locking user'); |
| 40 | expect(result.status).toBe(statusEnum.LOCK_STATUS); |
| 41 | expect(result.isCheckedOut).toBe(false); |
| 42 | }); |
| 43 | |
| 44 | it('validating getCheckOutStatusKindByUserID - with "UserID" with configuration set', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 45 | const Uid = 'ecomp'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 46 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 47 | Configuration.set('UserID', Uid); |
| 48 | var result = VersionControllerUtils.getCheckOutStatusKindByUserID(status, Uid); |
| 49 | Configuration.set('UserID', undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 50 | expect(result.status).toBe(status); |
| 51 | expect(result.isCheckedOut).toBe(true); |
| 52 | }); |
| 53 | |
| 54 | |
| 55 | |
| 56 | it('validating isCheckedOutByCurrentUser - when resource is not checked out', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 57 | const resource = VersionControllerUtilsFactory.build({status: statusEnum.SUBMIT_STATUS}); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 58 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 59 | Configuration.set('UserID', currentUser); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 60 | const result = VersionControllerUtils.isCheckedOutByCurrentUser(resource); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 61 | Configuration.set('UserID', undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 62 | |
| 63 | expect(result).toBe(false); |
| 64 | }); |
| 65 | |
| 66 | it('validating isCheckedOutByCurrentUser - when resource is checked out', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 67 | const resource = VersionControllerUtilsFactory.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 68 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 69 | Configuration.set('UserID', currentUser); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 70 | const result = VersionControllerUtils.isCheckedOutByCurrentUser(resource); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 71 | Configuration.set('UserID', undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 72 | |
| 73 | expect(result).toBe(true); |
| 74 | }); |
| 75 | |
| 76 | it('validating isCheckedOutByCurrentUser - when resource is checked out by another user', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 77 | const resource = VersionControllerUtilsFactory.build({lockingUser: 'another'}); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 78 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 79 | Configuration.set('UserID', currentUser); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 80 | const result = VersionControllerUtils.isCheckedOutByCurrentUser(resource); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 81 | Configuration.set('UserID', undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 82 | |
| 83 | expect(result).toBe(false); |
| 84 | }); |
| 85 | |
| 86 | |
| 87 | |
| 88 | it('validating isReadOnly - when resource is not checked out', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 89 | const resource = VersionControllerUtilsFactory.build({status: statusEnum.SUBMIT_STATUS}); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 90 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 91 | Configuration.set('UserID', currentUser); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 92 | const result = VersionControllerUtils.isReadOnly(resource); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 93 | Configuration.set('UserID', undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 94 | |
| 95 | expect(result).toBe(true); |
| 96 | }); |
| 97 | |
| 98 | it('validating isReadOnly - when resource is checked out', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 99 | const resource = VersionControllerUtilsFactory.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 100 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 101 | Configuration.set('UserID', currentUser); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 102 | const result = VersionControllerUtils.isReadOnly(resource); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 103 | Configuration.set('UserID', undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 104 | |
| 105 | expect(result).toBe(false); |
| 106 | }); |
| 107 | |
| 108 | it('validating isReadOnly - when version of resource is not latest', () => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 109 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 110 | const resource = VersionControllerUtilsFactory.build({version: defaultVersions[defaultVersions.length - 2]}); |
| 111 | |
| 112 | Configuration.set('UserID', currentUser); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 113 | const result = VersionControllerUtils.isReadOnly(resource); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 114 | Configuration.set('UserID', undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 115 | |
| 116 | expect(result).toBe(true); |
| 117 | }); |
| 118 | |
| 119 | it('validating isReadOnly - when resource is checked out by another user', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 120 | const resource = VersionControllerUtilsFactory.build({lockingUser: 'another'}); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 121 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 122 | Configuration.set('UserID', currentUser); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 123 | const result = VersionControllerUtils.isReadOnly(resource); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 124 | Configuration.set('UserID', undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 125 | |
| 126 | expect(result).toBe(true); |
| 127 | }); |
| 128 | }); |