2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 import {Factory} from 'rosie';
17 import randomstring from 'randomstring';
18 import VersionFactory from './VersionFactory.js';
20 export const InitializedItemPermissionFactory = new Factory()
24 'isCollaborator': true
27 export const ItemPermissionFactory = new Factory()
28 .extend(InitializedItemPermissionFactory)
36 export const CurrentScreenPropsFactory = new Factory()
37 .option('versionId', () => randomstring.generate())
38 .option('versionBaseId', () => randomstring.generate())
40 softwareProductId: () => randomstring.generate(),
41 licenseModelId: () => randomstring.generate(),
45 'versionId', 'versionBaseId'
47 VersionFactory.build({id, baseId})
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
58 .attr('itemPermission', ['isCertified', 'inMerge', 'isCollaborator'], (isCertified, inMerge, isCollaborator) =>
59 InitializedItemPermissionFactory.build({isCollaborator, isCertified, inMerge})
61 .attr('props', ['isReadOnlyMode'], (isReadOnlyMode) => {
62 return {isReadOnlyMode};
64 export const InitializedCurrentScreenFactory = new Factory().extend('InitializedCurrentScreenFactory');
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})
78 .attr('props', ['isReadOnlyMode', 'version'], (isReadOnlyMode, version) => {
79 return {isReadOnlyMode, version};
81 export default new Factory().extend('CurrentScreenFactory');
84 export const CurrentScreenFactoryWithProps = new Factory()
85 .extend('CurrentScreenFactory')
87 .option('versionBaseId')
90 'isReadOnlyMode', 'versionId', 'versionBaseId', 'version'
91 ], (isReadOnlyMode, id, baseId, version) => {
92 let attrs = {isReadOnlyMode};
95 if (version !== undefined) { attrs['version'] = version; }
96 if (id !== undefined) { options['versionId'] = id; }
97 if (baseId !== undefined) { options['versionBaseId'] = baseId; }
99 return CurrentScreenPropsFactory.build(attrs, options);