-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
94 changed files
with
1,452 additions
and
389 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
import React from 'react' | ||
import {BrowserRouter as Router, Route} from 'react-router-dom' | ||
import {Provider} from 'react-redux' | ||
import store from './store' | ||
import Page from './layout/Page' | ||
import FriendListPage from './friends/components/FriendListPage' | ||
import GroupChoosePage from './groups/components/GroupChoosePage' | ||
|
||
export default () => ( | ||
<Provider store={store}> | ||
<Page><FriendListPage/></Page> | ||
<Router> | ||
<Page> | ||
<Route exact path="/" component={GroupChoosePage}/> | ||
<Route path="/group/:groupId" component={FriendListPage}/> | ||
</Page> | ||
</Router> | ||
</Provider> | ||
) |
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,40 @@ | ||
import React from 'react' | ||
|
||
export default (WrappedComponent) => { | ||
|
||
return class extends React.Component { | ||
|
||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
submitting: false, | ||
value: '', | ||
error: undefined | ||
} | ||
} | ||
|
||
handleSubmit = () => { | ||
this.setState({submitting: true}) | ||
return this.props.submit(this.state.value) | ||
.then(() => { | ||
this.setState({submitting: false, value: ''}) | ||
}) | ||
.catch(errors => { | ||
this.setState({submitting: false, error: errors && errors.name}) | ||
}) | ||
} | ||
|
||
handleValueChange = (event) => { | ||
this.setState({value: event.target.value, error: undefined}) | ||
} | ||
|
||
render() { | ||
return <WrappedComponent submit={this.handleSubmit} | ||
valueChange={this.handleValueChange} | ||
value={this.state.value} | ||
submitting={this.state.submitting} | ||
error={this.state.error} | ||
/> | ||
} | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
kaapi/src/forms/components/SingleFieldFormContainer.test.js
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,106 @@ | ||
import {renderDecorator} from '../../support/testRender' | ||
import FriendAdderContainer from './SingleFieldFormContainer' | ||
|
||
beforeEach(() => jest.resetAllMocks()) | ||
|
||
describe('SingleFieldFormContainer', () => { | ||
|
||
const mockProps = {submit: jest.fn()} | ||
|
||
describe('when component loads', () => { | ||
const {subject, mockWrappedComponent} = renderDecorator(FriendAdderContainer, mockProps) | ||
|
||
it('should pass submitting=false', () => { | ||
expect(subject.find(mockWrappedComponent).props().submitting).toEqual(false) | ||
}) | ||
|
||
it('should pass value=""', () => { | ||
expect(subject.find(mockWrappedComponent).props().value).toEqual('') | ||
}) | ||
|
||
it('should pass error=undefined', () => { | ||
expect(subject.find(mockWrappedComponent).props().error).toBeUndefined() | ||
}) | ||
|
||
describe('when valueChange is called', () => { | ||
beforeEach(() => { | ||
subject.find(mockWrappedComponent).props().valueChange({target: {value: 'test-value-1'}}) | ||
subject.update() | ||
}) | ||
|
||
it('should update value with the valued passed', () => { | ||
expect(subject.find(mockWrappedComponent).props().value).toEqual('test-value-1') | ||
}) | ||
|
||
describe('when submit is called', () => { | ||
it('should pass submitting=true', () => { | ||
mockProps.submit.mockReturnValue(Promise.resolve()) | ||
subject.find(mockWrappedComponent).props().submit() | ||
subject.update() | ||
expect(subject.find(mockWrappedComponent).props().submitting).toEqual(true) | ||
}) | ||
|
||
it('should call submit with the value of value', () => { | ||
mockProps.submit.mockReturnValue(Promise.resolve()) | ||
subject.find(mockWrappedComponent).props().submit() | ||
expect(mockProps.submit).toHaveBeenCalledWith('test-value-1') | ||
}) | ||
|
||
describe('when the submit call completes successfully', () => { | ||
it('should pass submitting=false', () => { | ||
mockProps.submit.mockReturnValue(Promise.resolve()) | ||
return subject.find(mockWrappedComponent).props().submit().then(() => { | ||
subject.update() | ||
expect(subject.find(mockWrappedComponent).props().submitting).toEqual(false) | ||
}) | ||
}) | ||
|
||
it('should pass value=""', () => { | ||
mockProps.submit.mockReturnValue(Promise.resolve()) | ||
return subject.find(mockWrappedComponent).props().submit().then(() => { | ||
subject.update() | ||
expect(subject.find(mockWrappedComponent).props().value).toEqual('') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('when the submit call completes unsuccessfully', () => { | ||
it('should pass submitting=false', () => { | ||
mockProps.submit.mockReturnValue(Promise.reject({name: 'It did not work.'})) | ||
return subject.find(mockWrappedComponent).props().submit().then(() => { | ||
subject.update() | ||
expect(subject.find(mockWrappedComponent).props().submitting).toEqual(false) | ||
}) | ||
}) | ||
|
||
it('should not clear value', () => { | ||
mockProps.submit.mockReturnValue(Promise.reject({name: 'It did not work.'})) | ||
return subject.find(mockWrappedComponent).props().submit().then(() => { | ||
subject.update() | ||
expect(subject.find(mockWrappedComponent).props().value).toEqual('test-value-1') | ||
}) | ||
}) | ||
|
||
it('should pass the error', () => { | ||
mockProps.submit.mockReturnValue(Promise.reject({name: 'It did not work.'})) | ||
return subject.find(mockWrappedComponent).props().submit().then(() => { | ||
subject.update() | ||
expect(subject.find(mockWrappedComponent).props().error).toEqual('It did not work.') | ||
}) | ||
}) | ||
|
||
describe('when valueChange is called', () => { | ||
beforeEach(() => { | ||
subject.find(mockWrappedComponent).props().valueChange({target: {value: 'test-value-2'}}) | ||
subject.update() | ||
}) | ||
|
||
it('should clear the error', () => { | ||
expect(subject.find(mockWrappedComponent).props().error).toBeUndefined() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import friendCreate from '../api/friendCreate' | ||
import friendsLoad from './friendsLoad' | ||
|
||
export default (name) => (dispatch) => { | ||
return friendCreate({name}).then(() => dispatch(friendsLoad())) | ||
export default (friend) => (dispatch) => { | ||
return friendCreate(friend).then(() => dispatch(friendsLoad(friend.groupId))) | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import friendsReceived from './friendsReceived' | ||
import friendsGet from '../api/friendsGet' | ||
|
||
export default () => (dispatch) => { | ||
return friendsGet().then(response => dispatch(friendsReceived(response))) | ||
export default (groupId) => (dispatch) => { | ||
return friendsGet(groupId).then(friends => dispatch(friendsReceived({friends, groupId}))) | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import types from './types' | ||
|
||
export default (friends) => ({ | ||
export default ({friends, groupId}) => ({ | ||
type: types.FRIENDS_RECEIVED, | ||
data: friends | ||
data: {friends, groupId} | ||
}) |
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
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
Oops, something went wrong.