blob: ee94ba988df17de44cd769382eb94a392e116bd4 [file] [log] [blame]
talig8e9c0652017-12-20 14:30:43 +02001/*!
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 */
16import {Factory} from 'rosie';
17import randomstring from 'randomstring';
18import VersionFactory from './VersionFactory.js';
19
20export const InitializedItemPermissionFactory = new Factory()
21 .attrs({
22 'isCertified': false,
23 'inMerge': false,
24 'isCollaborator': true
25 });
26
27export const ItemPermissionFactory = new Factory()
28 .extend(InitializedItemPermissionFactory)
29 .attrs({
30 'isDirty': false,
31 'isOutOfSync': false,
svishnev091edfd2018-03-19 12:15:19 +020032 'isArchived': false,
talig8e9c0652017-12-20 14:30:43 +020033 'isUpToDate': true
34 });
35
36
37export const CurrentScreenPropsFactory = new Factory()
38 .option('versionId', () => randomstring.generate())
39 .option('versionBaseId', () => randomstring.generate())
40 .attrs({
41 softwareProductId: () => randomstring.generate(),
42 licenseModelId: () => randomstring.generate(),
43 isReadOnlyMode: false
44 })
45 .attr('version', [
46 'versionId', 'versionBaseId'
47 ], (id, baseId) =>
48 VersionFactory.build({id, baseId})
49 );
50
51
52Factory.define('InitializedCurrentScreenFactory')
53 .option('isCertified', false)
54 .option('inMerge', false)
55 .option('isCollaborator', true)
svishnev091edfd2018-03-19 12:15:19 +020056 .option('isArchived', false)
57 .option('isReadOnlyMode', ['isCertified', 'inMerge', 'isCollaborator', 'isArchived'], (isCertified, inMerge, isCollaborator, isArchived) =>
talig8e9c0652017-12-20 14:30:43 +020058 isCertified || inMerge || !isCollaborator
59 )
60 .attr('itemPermission', ['isCertified', 'inMerge', 'isCollaborator'], (isCertified, inMerge, isCollaborator) =>
61 InitializedItemPermissionFactory.build({isCollaborator, isCertified, inMerge})
62 )
63 .attr('props', ['isReadOnlyMode'], (isReadOnlyMode) => {
64 return {isReadOnlyMode};
65 });
66export const InitializedCurrentScreenFactory = new Factory().extend('InitializedCurrentScreenFactory');
67
68
69Factory.define('CurrentScreenFactory')
70 .extend('InitializedCurrentScreenFactory')
71 .option('isDirty', false)
72 .option('isOutOfSync', false)
73 .option('isUpToDate', true)
74 .option('version', ['isCertified'], (isCertified) => VersionFactory.build({isCertified}))
75 .attr('itemPermission', [
svishnev091edfd2018-03-19 12:15:19 +020076 'isCertified', 'inMerge', 'isCollaborator', 'isDirty', 'isOutOfSync', 'isUpToDate', 'isArchived'
77 ], (isCertified, inMerge, isCollaborator, isDirty, isOutOfSync, isUpToDate, isArchived) =>
78 ItemPermissionFactory.build({isCollaborator, isCertified, inMerge, isDirty, isOutOfSync, isUpToDate, isArchived})
talig8e9c0652017-12-20 14:30:43 +020079 )
80 .attr('props', ['isReadOnlyMode', 'version'], (isReadOnlyMode, version) => {
81 return {isReadOnlyMode, version};
82 });
83export default new Factory().extend('CurrentScreenFactory');
84
85
86export const CurrentScreenFactoryWithProps = new Factory()
87 .extend('CurrentScreenFactory')
88 .option('versionId')
89 .option('versionBaseId')
90 .option('version')
91 .attr('props', [
92 'isReadOnlyMode', 'versionId', 'versionBaseId', 'version'
93 ], (isReadOnlyMode, id, baseId, version) => {
94 let attrs = {isReadOnlyMode};
95 let options = {};
96
97 if (version !== undefined) { attrs['version'] = version; }
98 if (id !== undefined) { options['versionId'] = id; }
99 if (baseId !== undefined) { options['versionBaseId'] = baseId; }
100
101 return CurrentScreenPropsFactory.build(attrs, options);
102 });