2019-03-28 00:27:27 +03:00
import React from 'react' ;
2019-04-23 00:15:32 +03:00
import { mount , shallow } from 'enzyme' ;
2019-03-28 00:27:27 +03:00
import SelectRoleStep from '../../src/components/AddRole/SelectRoleStep' ;
describe ( '<SelectRoleStep />' , ( ) => {
let wrapper ;
const roles = {
project _admin _role : {
id : 1 ,
name : 'Project Admin' ,
description : 'Can manage all projects of the organization'
} ,
execute _role : {
id : 2 ,
name : 'Execute' ,
description : 'May run any executable resources in the organization'
}
} ;
const selectedRoles = [
{
id : 1 ,
name : 'Project Admin' ,
description : 'Can manage all projects of the organization'
}
] ;
const selectedResourceRows = [
{
id : 1 ,
name : 'foo'
}
] ;
test ( 'initially renders without crashing' , ( ) => {
2019-04-23 00:15:32 +03:00
wrapper = shallow (
2019-03-28 00:27:27 +03:00
< SelectRoleStep
roles = { roles }
selectedResourceRows = { selectedResourceRows }
selectedRoleRows = { selectedRoles }
/ >
) ;
expect ( wrapper . length ) . toBe ( 1 ) ;
wrapper . unmount ( ) ;
} ) ;
test ( 'clicking role fires onRolesClick callback' , ( ) => {
const onRolesClick = jest . fn ( ) ;
wrapper = mount (
< SelectRoleStep
onRolesClick = { onRolesClick }
roles = { roles }
selectedResourceRows = { selectedResourceRows }
selectedRoleRows = { selectedRoles }
/ >
) ;
const CheckboxCards = wrapper . find ( 'CheckboxCard' ) ;
expect ( CheckboxCards . length ) . toBe ( 2 ) ;
CheckboxCards . first ( ) . prop ( 'onSelect' ) ( ) ;
expect ( onRolesClick ) . toBeCalledWith ( {
id : 1 ,
name : 'Project Admin' ,
description : 'Can manage all projects of the organization'
} ) ;
wrapper . unmount ( ) ;
} ) ;
} ) ;