svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 1 | /* |
Einav Weiss Keidar | d2f5794 | 2018-02-14 14:00:07 +0200 | [diff] [blame] | 2 | * Copyright © 2016-2018 European Support Limited |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 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 |
Einav Weiss Keidar | d2f5794 | 2018-02-14 14:00:07 +0200 | [diff] [blame] | 7 | * |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Einav Weiss Keidar | d2f5794 | 2018-02-14 14:00:07 +0200 | [diff] [blame] | 9 | * |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 12 | * 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. |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | import React from 'react'; |
Einav Weiss Keidar | d2f5794 | 2018-02-14 14:00:07 +0200 | [diff] [blame] | 18 | import TestUtils from 'react-dom/test-utils'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 19 | |
| 20 | import {UserFactory} from 'test-utils/factories/users/UsersFactories.js'; |
| 21 | import {mapStateToProps} from 'sdc-app/onboarding/permissions/PermissionsManager.js'; |
| 22 | import PermissionsManager from 'sdc-app/onboarding/permissions/PermissionsManager.jsx'; |
| 23 | |
| 24 | |
| 25 | |
| 26 | describe('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 | |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 110 | }); |