blob: 2d880c7ce05d341d9995f4233ce21e6ccffdfcc5 [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 */
16
17import React from 'react';
18import TestUtils from 'react-addons-test-utils';
19
20import {UserFactory} from 'test-utils/factories/users/UsersFactories.js';
21import {mapStateToProps} from 'sdc-app/onboarding/permissions/PermissionsManager.js';
22import PermissionsManager from 'sdc-app/onboarding/permissions/PermissionsManager.jsx';
23
24
25
26describe('Manage Permissions: ', function () {
27 let globalItemId = '343434', usersList = [], userInfo = {}, versionsPage = {}, contributor = {}, contributorToAdd = {}, owner = {};
28 beforeAll(function() {
29 usersList = UserFactory.buildList(3);
30 userInfo = usersList[0];
31 owner = usersList[0];
32 contributor = usersList[1];
33 contributorToAdd = usersList[2];
34 versionsPage = {
35 permissions: {
36 owner: owner,
37 contributors: [contributor],
38 viewers: []
39 }
40 };
41 });
42
43 it('should mapper exist', () => {
44 expect(mapStateToProps).toBeTruthy();
45 });
46
47 it('should mapper return basic permissions page data', () => {
48 const obj = {versionsPage, users: {usersList, userInfo}};
49 const result = mapStateToProps(obj);
50 result.itemId = globalItemId;
51 expect(result.owner).toBeTruthy();
52 expect(result.itemUsers).toBeTruthy();
53 expect(result.userInfo).toBeTruthy();
54 expect(result.itemId).toBeTruthy();
55 expect(result.users).toBeTruthy();
56 });
57
58 it('permission manager basic view', () => {
59
60 const obj = {versionsPage, users: {usersList, userInfo}};
61 const params = mapStateToProps(obj);
62 let permissionsView = TestUtils.renderIntoDocument(<PermissionsManager {...params}/>);
63 expect(permissionsView).toBeTruthy();
64 });
65
66 it('permisssion manager onChange contributors test', () => {
67
68 const obj = {versionsPage, users: {usersList, userInfo}};
69 const params = mapStateToProps(obj);
70 params.itemId = globalItemId;
71 let permissionsView = TestUtils.renderIntoDocument(<PermissionsManager {...params}/>);
72 expect(permissionsView).toBeTruthy();
73 const userToAdd = {
74 value: contributorToAdd.userId,
75 label: contributorToAdd.fullName
76 };
77 let itemUsers = [{...userToAdd}];
78
79 permissionsView.onChangeItemUsers({itemUsers});
80 expect(permissionsView.state.itemUsers[0].userId).toEqual(userToAdd.value);
81 });
82
83 it('permisssion manager onSave contributors test', () => {
84
85 const obj = {versionsPage, users: {usersList, userInfo}};
86 let params = mapStateToProps(obj);
87 params.itemId = globalItemId;
88 const userToAdd = {
89 value: contributorToAdd.userId,
90 label: contributorToAdd.fullName
91 };
92 let itemUsers = [{...userToAdd}];
93
94
95 params.onSubmit = ({itemId, addedUsersIds, removedUsersIds, allUsers, owner}) => {
96 expect(itemId).toEqual(globalItemId);
97 expect(addedUsersIds[0]).toEqual(contributorToAdd.userId);
98 expect(removedUsersIds[0]).toEqual(contributor.userId);
99 expect(allUsers).toEqual(usersList);
100 expect(owner).toEqual(owner);
101 };
102 let permissionsView = TestUtils.renderIntoDocument(<PermissionsManager {...params}/>);
103 expect(permissionsView).toBeTruthy();
104 permissionsView.onChangeItemUsers({itemUsers});
105 permissionsView.onsaveItemUsers();
106 });
107
108
109
110});