Add collaboration feature
[sdc.git] / openecomp-ui / test-utils / factories / common / CurrentScreenFactory.js
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 import {Factory} from 'rosie';
17 import randomstring from 'randomstring';
18 import VersionFactory from './VersionFactory.js';
19
20 export const InitializedItemPermissionFactory = new Factory()
21         .attrs({
22                 'isCertified': false,
23                 'inMerge': false,
24                 'isCollaborator': true
25         });
26
27 export const ItemPermissionFactory = new Factory()
28         .extend(InitializedItemPermissionFactory)
29         .attrs({
30                 'isDirty': false,
31                 'isOutOfSync': false,
32                 'isUpToDate': true
33         });
34
35
36 export const CurrentScreenPropsFactory = new Factory()
37         .option('versionId', () => randomstring.generate())
38         .option('versionBaseId', () => randomstring.generate())
39         .attrs({
40                 softwareProductId: () => randomstring.generate(),
41                 licenseModelId: () => randomstring.generate(),
42                 isReadOnlyMode: false
43         })
44         .attr('version', [
45                 'versionId', 'versionBaseId'
46         ], (id, baseId) =>
47                 VersionFactory.build({id, baseId})
48         );
49
50
51 Factory.define('InitializedCurrentScreenFactory')
52         .option('isCertified', false)
53         .option('inMerge', false)
54         .option('isCollaborator', true)
55         .option('isReadOnlyMode', ['isCertified', 'inMerge', 'isCollaborator'], (isCertified, inMerge, isCollaborator) =>
56                 isCertified || inMerge || !isCollaborator
57         )
58         .attr('itemPermission', ['isCertified', 'inMerge', 'isCollaborator'], (isCertified, inMerge, isCollaborator) =>
59                 InitializedItemPermissionFactory.build({isCollaborator, isCertified, inMerge})
60         )
61         .attr('props', ['isReadOnlyMode'], (isReadOnlyMode) => {
62                 return {isReadOnlyMode};
63         });
64 export const InitializedCurrentScreenFactory = new Factory().extend('InitializedCurrentScreenFactory');
65
66
67 Factory.define('CurrentScreenFactory')
68         .extend('InitializedCurrentScreenFactory')
69         .option('isDirty', false)
70         .option('isOutOfSync', false)
71         .option('isUpToDate', true)
72         .option('version', ['isCertified'], (isCertified) => VersionFactory.build({isCertified}))
73         .attr('itemPermission', [
74                 'isCertified', 'inMerge', 'isCollaborator', 'isDirty', 'isOutOfSync', 'isUpToDate'
75         ], (isCertified, inMerge, isCollaborator, isDirty, isOutOfSync, isUpToDate) =>
76                 ItemPermissionFactory.build({isCollaborator, isCertified, inMerge, isDirty, isOutOfSync, isUpToDate})
77         )
78         .attr('props', ['isReadOnlyMode', 'version'], (isReadOnlyMode, version) => {
79                 return {isReadOnlyMode, version};
80         });
81 export default new Factory().extend('CurrentScreenFactory');
82
83
84 export const CurrentScreenFactoryWithProps = new Factory()
85         .extend('CurrentScreenFactory')
86         .option('versionId')
87         .option('versionBaseId')
88         .option('version')
89         .attr('props', [
90                 'isReadOnlyMode', 'versionId', 'versionBaseId', 'version'
91         ], (isReadOnlyMode, id, baseId, version) => {
92                 let attrs = {isReadOnlyMode};
93                 let options = {};
94
95                 if (version !== undefined) { attrs['version'] = version; }
96                 if (id !== undefined) { options['versionId'] = id; }
97                 if (baseId !== undefined) { options['versionBaseId'] = baseId; }
98
99                 return CurrentScreenPropsFactory.build(attrs, options);
100         });