blob: d654e16ddf101f427e97e0959a114d6880e7f6e2 [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
Michael Landoefa037d2017-02-19 12:57:33 +02002 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
AviZi280f8012017-06-09 02:39:56 +03003 *
Michael Landoefa037d2017-02-19 12:57:33 +02004 * 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 *
AviZi280f8012017-06-09 02:39:56 +03008 * http://www.apache.org/licenses/LICENSE-2.0
Michael Landoefa037d2017-02-19 12:57:33 +02009 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
AviZi280f8012017-06-09 02:39:56 +030012 * 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 Landoefa037d2017-02-19 12:57:33 +020015 */
16
AviZi280f8012017-06-09 02:39:56 +030017
Michael Landoefa037d2017-02-19 12:57:33 +020018import Configuration from 'sdc-app/config/Configuration.js';
19import VersionControllerUtils from 'nfvo-components/panel/versionController/VersionControllerUtils.js';
20import {statusEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
AviZi280f8012017-06-09 02:39:56 +030021import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js';
Michael Landoefa037d2017-02-19 12:57:33 +020022
23const status = 'testStatus';
AviZi280f8012017-06-09 02:39:56 +030024const {lockingUser: currentUser, viewableVersions: defaultVersions} = VersionControllerUtilsFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +020025
26describe('versionController UI Component', () => {
27
28 it('function does exist', () => {
AviZi280f8012017-06-09 02:39:56 +030029 expect(VersionControllerUtils).toBeTruthy();
Michael Landoefa037d2017-02-19 12:57:33 +020030 });
31
32 it('validating getCheckOutStatusKindByUserID - without "UserID"', () => {
33 var result = VersionControllerUtils.getCheckOutStatusKindByUserID(status);
34 expect(result.status).toBe(status);
AviZi280f8012017-06-09 02:39:56 +030035 expect(result.isCheckedOut).toBe(false);
Michael Landoefa037d2017-02-19 12:57:33 +020036 });
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', () => {
AviZi280f8012017-06-09 02:39:56 +030045 const Uid = 'ecomp';
Michael Landoefa037d2017-02-19 12:57:33 +020046
AviZi280f8012017-06-09 02:39:56 +030047 Configuration.set('UserID', Uid);
48 var result = VersionControllerUtils.getCheckOutStatusKindByUserID(status, Uid);
49 Configuration.set('UserID', undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020050 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', () => {
AviZi280f8012017-06-09 02:39:56 +030057 const resource = VersionControllerUtilsFactory.build({status: statusEnum.SUBMIT_STATUS});
Michael Landoefa037d2017-02-19 12:57:33 +020058
AviZi280f8012017-06-09 02:39:56 +030059 Configuration.set('UserID', currentUser);
Michael Landoefa037d2017-02-19 12:57:33 +020060 const result = VersionControllerUtils.isCheckedOutByCurrentUser(resource);
AviZi280f8012017-06-09 02:39:56 +030061 Configuration.set('UserID', undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020062
63 expect(result).toBe(false);
64 });
65
66 it('validating isCheckedOutByCurrentUser - when resource is checked out', () => {
AviZi280f8012017-06-09 02:39:56 +030067 const resource = VersionControllerUtilsFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +020068
AviZi280f8012017-06-09 02:39:56 +030069 Configuration.set('UserID', currentUser);
Michael Landoefa037d2017-02-19 12:57:33 +020070 const result = VersionControllerUtils.isCheckedOutByCurrentUser(resource);
AviZi280f8012017-06-09 02:39:56 +030071 Configuration.set('UserID', undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020072
73 expect(result).toBe(true);
74 });
75
76 it('validating isCheckedOutByCurrentUser - when resource is checked out by another user', () => {
AviZi280f8012017-06-09 02:39:56 +030077 const resource = VersionControllerUtilsFactory.build({lockingUser: 'another'});
Michael Landoefa037d2017-02-19 12:57:33 +020078
AviZi280f8012017-06-09 02:39:56 +030079 Configuration.set('UserID', currentUser);
Michael Landoefa037d2017-02-19 12:57:33 +020080 const result = VersionControllerUtils.isCheckedOutByCurrentUser(resource);
AviZi280f8012017-06-09 02:39:56 +030081 Configuration.set('UserID', undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020082
83 expect(result).toBe(false);
84 });
85
86
87
88 it('validating isReadOnly - when resource is not checked out', () => {
AviZi280f8012017-06-09 02:39:56 +030089 const resource = VersionControllerUtilsFactory.build({status: statusEnum.SUBMIT_STATUS});
Michael Landoefa037d2017-02-19 12:57:33 +020090
AviZi280f8012017-06-09 02:39:56 +030091 Configuration.set('UserID', currentUser);
Michael Landoefa037d2017-02-19 12:57:33 +020092 const result = VersionControllerUtils.isReadOnly(resource);
AviZi280f8012017-06-09 02:39:56 +030093 Configuration.set('UserID', undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020094
95 expect(result).toBe(true);
96 });
97
98 it('validating isReadOnly - when resource is checked out', () => {
AviZi280f8012017-06-09 02:39:56 +030099 const resource = VersionControllerUtilsFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200100
AviZi280f8012017-06-09 02:39:56 +0300101 Configuration.set('UserID', currentUser);
Michael Landoefa037d2017-02-19 12:57:33 +0200102 const result = VersionControllerUtils.isReadOnly(resource);
AviZi280f8012017-06-09 02:39:56 +0300103 Configuration.set('UserID', undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200104
105 expect(result).toBe(false);
106 });
107
108 it('validating isReadOnly - when version of resource is not latest', () => {
Michael Landoefa037d2017-02-19 12:57:33 +0200109
AviZi280f8012017-06-09 02:39:56 +0300110 const resource = VersionControllerUtilsFactory.build({version: defaultVersions[defaultVersions.length - 2]});
111
112 Configuration.set('UserID', currentUser);
Michael Landoefa037d2017-02-19 12:57:33 +0200113 const result = VersionControllerUtils.isReadOnly(resource);
AviZi280f8012017-06-09 02:39:56 +0300114 Configuration.set('UserID', undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200115
116 expect(result).toBe(true);
117 });
118
119 it('validating isReadOnly - when resource is checked out by another user', () => {
AviZi280f8012017-06-09 02:39:56 +0300120 const resource = VersionControllerUtilsFactory.build({lockingUser: 'another'});
Michael Landoefa037d2017-02-19 12:57:33 +0200121
AviZi280f8012017-06-09 02:39:56 +0300122 Configuration.set('UserID', currentUser);
Michael Landoefa037d2017-02-19 12:57:33 +0200123 const result = VersionControllerUtils.isReadOnly(resource);
AviZi280f8012017-06-09 02:39:56 +0300124 Configuration.set('UserID', undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200125
126 expect(result).toBe(true);
127 });
128});