forked from Lemoncode/LeanMood
-
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.
Merge pull request Lemoncode#157 from beatrizRG/Mymaster
Edit student navigation
- Loading branch information
Showing
15 changed files
with
329 additions
and
14 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
100 changes: 100 additions & 0 deletions
100
src/pages/admin/student/edit/actions/spec/summaryStudentRequest.spec.ts
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,100 @@ | ||
import thunk from 'redux-thunk'; | ||
import configureStore from 'redux-mock-store'; | ||
|
||
import { adminActionEnums } from '../../../../../../common/actionEnums/admin'; | ||
import { summaryStudentByIdRequestCompleted, summaryStudentByIdRequestStarted } from '../summaryStudentRequest'; | ||
import { StudentSummary } from '../../../../../../model/studentSummary'; | ||
import { studentApi } from '../../../../../../rest-api'; | ||
|
||
const mockStore = configureStore([thunk]); | ||
|
||
describe('summaryStudentByIdRequestCompleted', () => { | ||
it('should be a function', () => { | ||
// Assert | ||
expect(summaryStudentByIdRequestCompleted).to.be.a('function'); | ||
}); | ||
|
||
it('contains the expected type GET_SUMMARY_STUDENT_BY_ID_REQUEST_COMPLETED', () => { | ||
// Arrange | ||
const student = new StudentSummary(); | ||
|
||
// Act | ||
const action = summaryStudentByIdRequestCompleted(student); | ||
|
||
// Assert | ||
expect(action.type).to.be.equals(adminActionEnums.GET_SUMMARY_STUDENT_BY_ID_REQUEST_COMPLETED); | ||
}); | ||
|
||
it('contains the expected payload including the student summary', () => { | ||
// Arrange | ||
const student: StudentSummary = { | ||
id: '2', | ||
fullname: 'John Doe', | ||
email: 'test@test.com', | ||
isActive: true, | ||
}; | ||
|
||
// Act | ||
const actionResult = summaryStudentByIdRequestCompleted(student); | ||
|
||
// Assert | ||
expect(actionResult.payload.fullname).to.be.equal(student.fullname); | ||
expect(actionResult.payload.email).to.be.equal(student.email); | ||
expect(actionResult.payload.isActive).to.be.equal(student.isActive); | ||
expect(actionResult.payload).eql(student); | ||
}); | ||
}); | ||
|
||
describe('summaryStudentByIdRequestStarted', () => { | ||
it('should return a function', () => { | ||
// Arrange | ||
const studentId = '1'; | ||
|
||
// Assert | ||
expect(summaryStudentByIdRequestStarted(studentId)).to.be.a('function'); | ||
}); | ||
|
||
it('should return request action type completed', sinon.test(function(done) { | ||
// Arrange | ||
const sinon: sinon.SinonStatic = this; | ||
const studentId = '1'; | ||
|
||
// Act | ||
const store = mockStore([]); | ||
store.dispatch(summaryStudentByIdRequestStarted(studentId)).then(() => { | ||
|
||
// Assert | ||
expect(store.getActions()[0].type).to.be.equal(adminActionEnums.GET_SUMMARY_STUDENT_BY_ID_REQUEST_COMPLETED); | ||
done(); | ||
}); | ||
})); | ||
|
||
it('should return expected student summary data', sinon.test(function(done) { | ||
// Arrange | ||
const sinon: sinon.SinonStatic = this; | ||
|
||
const student: StudentSummary = { | ||
id: '2', | ||
fullname: 'John Doe', | ||
email: 'test@test.com', | ||
isActive: true, | ||
}; | ||
|
||
const getSummaryStudentListStub = sinon.stub(studentApi, 'getStudentById'); | ||
|
||
getSummaryStudentListStub.returns({ | ||
then: (callback) => { | ||
callback(student); | ||
}, | ||
}); | ||
|
||
// Act | ||
const store = mockStore([]); | ||
store.dispatch(summaryStudentByIdRequestStarted(student.id)).then(() => { | ||
// Assert | ||
expect(store.getActions()[0].payload).to.be.equal(student); | ||
expect(getSummaryStudentListStub.called).to.be.true; | ||
done(); | ||
}); | ||
})); | ||
}); |
24 changes: 24 additions & 0 deletions
24
src/pages/admin/student/edit/actions/summaryStudentRequest.ts
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,24 @@ | ||
import { adminActionEnums } from '../../../../../common/actionEnums/admin'; | ||
import { StudentSummary } from '../../../../../model/studentSummary'; | ||
import { studentApi } from '../../../../../rest-api'; | ||
|
||
export const summaryStudentByIdRequestStarted = (studentId: string) => { | ||
return function(dispatcher) { | ||
const promise = studentApi.getStudentById(studentId); | ||
|
||
promise.then( | ||
(data) => { | ||
dispatcher(summaryStudentByIdRequestCompleted(data)); | ||
}, | ||
); | ||
|
||
return promise; | ||
}; | ||
}; | ||
|
||
export const summaryStudentByIdRequestCompleted = (student: StudentSummary) => { | ||
return { | ||
payload: student, | ||
type: adminActionEnums.GET_SUMMARY_STUDENT_BY_ID_REQUEST_COMPLETED, | ||
}; | ||
}; |
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 @@ | ||
export { EditStudentPageContainer } from './pageContainer'; |
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,17 +1,33 @@ | ||
import * as React from 'react'; | ||
import {Link} from 'react-router'; | ||
import {adminRouteEnums} from '../../../../common/routeEnums/admin'; | ||
import { Link } from 'react-router'; | ||
import { adminRouteEnums } from '../../../../common/routeEnums/admin'; | ||
import { StudentSummary } from '../../../../model/studentSummary'; | ||
|
||
export class EditStudentPage extends React.Component<{}, {}> { | ||
public render() { | ||
interface Props { | ||
student: StudentSummary; | ||
getStudent: (id: string) => void; | ||
studentId: string; | ||
} | ||
|
||
export class EditStudentPage extends React.Component<Props, {}> { | ||
public componentDidMount() { | ||
const studentId: string = this.props.studentId; | ||
this.props.getStudent(studentId); | ||
} | ||
|
||
public render() { | ||
return ( | ||
<div> | ||
<span> Edit Student Page: </span> | ||
<br/> | ||
<div> | ||
<span>Student name: {this.props.student.fullname}</span> | ||
<br/> | ||
<span>Email: {this.props.student.email}</span> | ||
<br/> | ||
<span>Is Active?: {this.props.student.isActive ? 'Yes' : 'No'}</span> | ||
<br/> | ||
<Link to={adminRouteEnums.student.list}>Back to student list</Link> | ||
<Link to={adminRouteEnums.default}>Back to Dashboard</Link> | ||
</div> | ||
|
||
</div> | ||
); | ||
} | ||
} |
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,18 @@ | ||
import { connect } from 'react-redux'; | ||
import { IAppState } from '../../../../reducers'; | ||
import { EditStudentPage } from './page'; | ||
import { summaryStudentByIdRequestStarted } from './actions/summaryStudentRequest'; | ||
|
||
const mapStateToProps = (state: IAppState, ownProps) => ({ | ||
studentId: ownProps.params.id.toString(), | ||
student: state.adminStudent.editingStudentSummary, | ||
}); | ||
|
||
const mapDispatchToProps = (dispatch) => ({ | ||
getStudent: (studentId: string) => dispatch(summaryStudentByIdRequestStarted(studentId)), | ||
}); | ||
|
||
export const EditStudentPageContainer = connect( | ||
mapStateToProps, | ||
mapDispatchToProps, | ||
)(EditStudentPage); |
111 changes: 111 additions & 0 deletions
111
src/pages/admin/student/edit/spec/pageContainer.spec.tsx
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,111 @@ | ||
import * as React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import configureStore from 'redux-mock-store'; | ||
import { Provider } from 'react-redux'; | ||
import * as getStudent from '../actions/summaryStudentRequest'; | ||
import { EditStudentPageContainer } from '../pageContainer'; | ||
|
||
const createStore = configureStore(); | ||
|
||
describe('EditStudentPageContainer', () => { | ||
it('should be defined', sinon.test(() => { | ||
// Arrange | ||
const sinon: sinon.SinonStatic = this; | ||
|
||
const mockStore: any = createStore({ | ||
adminStudent: { | ||
editingStudentSummary: {}, | ||
}, | ||
}); | ||
|
||
const getStudentStub = sinon.stub(getStudent, | ||
'summaryStudentByIdRequestStarted', () => ({ type: 'dummy' })); | ||
|
||
// Act | ||
const container = mount( | ||
<Provider store={mockStore}> | ||
<EditStudentPageContainer params={{ id: ''}} /> | ||
</Provider>, | ||
); | ||
|
||
// Assert | ||
expect(container).not.to.be.undefined; | ||
}).bind(this)); | ||
|
||
it('should contain a studentId property equals to the conversion to string when params is not a string', sinon.test(() => { | ||
// Arrange | ||
const sinon: sinon.SinonStatic = this; | ||
|
||
const mockStore: any = createStore({ | ||
adminStudent: { | ||
editingStudentSummary: {}, | ||
}, | ||
}); | ||
|
||
const getStudentStub = sinon.stub(getStudent, | ||
'summaryStudentByIdRequestStarted', () => ({ type: 'dummy' })); | ||
|
||
// Act | ||
const container = mount( | ||
<Provider store={mockStore}> | ||
<EditStudentPageContainer params={{ id: 2}} /> | ||
</Provider>, | ||
); | ||
|
||
// Assert | ||
const presentational = container.find('EditStudentPage'); | ||
expect(presentational).not.to.be.undefined; | ||
expect(presentational.prop('studentId')).to.equal('2'); | ||
}).bind(this)); | ||
|
||
it('should contain a studentId property equals 2 when params equals 2', sinon.test(() => { | ||
// Arrange | ||
const sinon: sinon.SinonStatic = this; | ||
|
||
const mockStore: any = createStore({ | ||
adminStudent: { | ||
editingStudentSummary: {}, | ||
}, | ||
}); | ||
|
||
const getStudentStub = sinon.stub(getStudent, | ||
'summaryStudentByIdRequestStarted', () => ({ type: 'dummy' })); | ||
|
||
// Act | ||
const container = mount( | ||
<Provider store={mockStore}> | ||
<EditStudentPageContainer params={{ id: '2'}} /> | ||
</Provider>, | ||
); | ||
|
||
// Assert | ||
const presentational = container.find('EditStudentPage'); | ||
expect(presentational).not.to.be.undefined; | ||
expect(presentational.prop('studentId')).to.equal('2'); | ||
}).bind(this)); | ||
|
||
it('should call to getStudent with expected studentId', sinon.test(() => { | ||
// Arrange | ||
const sinon: sinon.SinonStatic = this; | ||
|
||
const mockStore: any = createStore({ | ||
adminStudent: { | ||
editingStudentSummary: {}, | ||
}, | ||
}); | ||
|
||
const getStudentStub = sinon.stub( getStudent , | ||
'summaryStudentByIdRequestStarted', () => ({ type: 'dummy' })); | ||
|
||
// Act | ||
const container = mount( | ||
<Provider store={mockStore}> | ||
<EditStudentPageContainer params={{ id: '2'}} /> | ||
</Provider>, | ||
); | ||
|
||
// Assert | ||
expect(getStudentStub.calledOnce).to.be.true; | ||
expect(getStudentStub.calledWith('2')).to.be.true; | ||
}).bind(this)); | ||
}); |
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.