This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate team members modal to be pure and use Redux (#253)
* Migrate team members modal to be pure and use Redux * Add component tests
- Loading branch information
1 parent
475236a
commit f80656d
Showing
7 changed files
with
166 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
import {connect} from 'react-redux'; | ||
|
||
import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; | ||
|
||
import TeamMembersModal from './team_members_modal.jsx'; | ||
|
||
function mapStateToProps(state, ownProps) { | ||
return { | ||
...ownProps, | ||
currentTeam: getCurrentTeam(state) | ||
}; | ||
} | ||
|
||
export default connect(mapStateToProps)(TeamMembersModal); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
tests/components/team_members_modal/__snapshots__/team_members_modal.test.jsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`components/TeamMembersModal should match snapshot 1`] = ` | ||
<Modal | ||
animation={true} | ||
autoFocus={true} | ||
backdrop={true} | ||
bsClass="modal" | ||
dialogClassName="more-modal" | ||
dialogComponentClass={[Function]} | ||
enforceFocus={true} | ||
keyboard={true} | ||
manager={ | ||
ModalManager { | ||
"add": [Function], | ||
"containers": Array [], | ||
"data": Array [], | ||
"handleContainerOverflow": true, | ||
"hideSiblingNodes": true, | ||
"isTopModal": [Function], | ||
"modals": Array [], | ||
"remove": [Function], | ||
} | ||
} | ||
onExited={[Function]} | ||
onHide={[Function]} | ||
renderBackdrop={[Function]} | ||
restoreFocus={true} | ||
show={true} | ||
> | ||
<ModalHeader | ||
bsClass="modal-header" | ||
closeButton={true} | ||
closeLabel="Close" | ||
> | ||
<ModalTitle | ||
bsClass="modal-title" | ||
componentClass="h4" | ||
> | ||
<FormattedMessage | ||
defaultMessage="{team} Members" | ||
id="team_member_modal.members" | ||
values={ | ||
Object { | ||
"team": "display name", | ||
} | ||
} | ||
/> | ||
</ModalTitle> | ||
</ModalHeader> | ||
<ModalBody | ||
bsClass="modal-body" | ||
componentClass="div" | ||
> | ||
<Connect(MemberListTeam) | ||
isAdmin={false} | ||
/> | ||
</ModalBody> | ||
</Modal> | ||
`; |
59 changes: 59 additions & 0 deletions
59
tests/components/team_members_modal/team_members_modal.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
import React from 'react'; | ||
import {shallow} from 'enzyme'; | ||
|
||
import {Modal} from 'react-bootstrap'; | ||
|
||
import TeamMembersModal from 'components/team_members_modal/team_members_modal.jsx'; | ||
|
||
describe('components/TeamMembersModal', () => { | ||
test('should match snapshot', () => { | ||
function emptyFunction() {} //eslint-disable-line no-empty-function | ||
|
||
const wrapper = shallow( | ||
<TeamMembersModal | ||
currentTeam={{display_name: 'display name'}} | ||
onHide={emptyFunction} | ||
onLoad={emptyFunction} | ||
isAdmin={false} | ||
/> | ||
); | ||
|
||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
test('should set show to false on Modal\'s onHide', () => { | ||
function emptyFunction() {} //eslint-disable-line no-empty-function | ||
|
||
const wrapper = shallow( | ||
<TeamMembersModal | ||
currentTeam={{display_name: 'display name'}} | ||
onHide={emptyFunction} | ||
onLoad={emptyFunction} | ||
isAdmin={false} | ||
/> | ||
); | ||
|
||
wrapper.find(Modal).first().props().onHide(); | ||
expect(wrapper.state('show')).toBe(false); | ||
}); | ||
|
||
test('should call onHide on Modal\'s onExited', () => { | ||
function emptyFunction() {} //eslint-disable-line no-empty-function | ||
const onHide = jest.fn(); | ||
|
||
const wrapper = shallow( | ||
<TeamMembersModal | ||
currentTeam={{display_name: 'display name'}} | ||
onHide={onHide} | ||
onLoad={emptyFunction} | ||
isAdmin={false} | ||
/> | ||
); | ||
|
||
wrapper.find(Modal).first().props().onExited(); | ||
expect(onHide).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |