blob: 4f3fac9e0ddd5c63b64dc654e0511517ea3d97bf [file] [log] [blame]
svishnev1eb66b72018-01-11 14:39:45 +02001/*
Einav Weiss Keidard2f57942018-02-14 14:00:07 +02002 * Copyright © 2016-2018 European Support Limited
talig8e9c0652017-12-20 14:30:43 +02003 *
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
Einav Weiss Keidard2f57942018-02-14 14:00:07 +02007 *
svishnev1eb66b72018-01-11 14:39:45 +02008 * http://www.apache.org/licenses/LICENSE-2.0
Einav Weiss Keidard2f57942018-02-14 14:00:07 +02009 *
talig8e9c0652017-12-20 14:30:43 +020010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
svishnev1eb66b72018-01-11 14:39:45 +020012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
talig8e9c0652017-12-20 14:30:43 +020015 */
16
17import React from 'react';
Einav Weiss Keidard2f57942018-02-14 14:00:07 +020018import TestUtils from 'react-dom/test-utils';
talig8e9c0652017-12-20 14:30:43 +020019
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
svishnev1eb66b72018-01-11 14:39:45 +0200110});