-
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
18 changed files
with
613 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
// components | ||
import withRequests from '../../HOC/withRequests'; | ||
import RequestHolder from './RequestHolder'; | ||
import RequestPagination from '../../common/Pagination'; | ||
|
||
// mock data | ||
import requests from '../../../tests/modules/Admin/mock/mockData'; | ||
|
||
|
||
export const Request = ({ | ||
headerText, | ||
handleChange, | ||
requests, | ||
checkedAll | ||
}) => ( | ||
<div className="request-container text-blue"> | ||
<h4>{headerText}</h4> | ||
<hr className="hr-top" /> | ||
<RequestHolder | ||
handleChange={handleChange} | ||
requests={requests} | ||
checkedAll={checkedAll} | ||
/> | ||
<RequestPagination /> | ||
|
||
<div className="admin-btn-holder"> | ||
<button className="btn blue-btn admin-btn-margin" type="button">Accept</button> | ||
<button className="btn red-btn" type="button">Reject</button> | ||
</div> | ||
|
||
</div> | ||
); | ||
|
||
Request.propTypes = { | ||
headerText: PropTypes.string.isRequired, | ||
handleChange: PropTypes.func.isRequired, | ||
requests: PropTypes.array.isRequired, | ||
checkedAll: PropTypes.bool.isRequired | ||
}; | ||
|
||
const AdminRequests = withRequests(Request, { | ||
requests: requests.data.requests, | ||
pageTitle: 'Admin Requests' | ||
}); | ||
|
||
export default AdminRequests; |
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,27 @@ | ||
import React from 'react'; | ||
|
||
const RequestCheckbox = ({ | ||
handleChange, | ||
checkOne, | ||
requests = [], | ||
checkedAll | ||
}) => { | ||
const Requests = requests.map((request, index) => ( | ||
<p key={request.id}> | ||
<label htmlFor={request.id}> | ||
<input | ||
name={request.id} | ||
id={request.id} | ||
type="checkbox" | ||
className="filled-in" | ||
onChange={(e) => handleChange(e, request)} | ||
checked={request.checked} | ||
/> | ||
<span>{`${request.user.displayName} < ${request.user.email} >`}</span> | ||
</label> | ||
</p>)); | ||
|
||
return Requests; | ||
}; | ||
|
||
export default RequestCheckbox; |
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,44 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
// component | ||
import RequestCheckbox from './RequestCheckbox'; | ||
|
||
const RequestHolder = ({ | ||
handleChange, | ||
requests, | ||
checkedAll | ||
}) => ( | ||
<div className="request-checkbox-container"> | ||
<form> | ||
<p> | ||
<label htmlFor="main-control"> | ||
<input | ||
name="main-control" | ||
id="main-control" | ||
type="checkbox" | ||
className="filled-in" | ||
onChange={(e) => handleChange(e)} | ||
checked={checkedAll} | ||
/> | ||
<span>Mark All</span> | ||
</label> | ||
</p> | ||
<hr /> | ||
{/* hold the requests */} | ||
<RequestCheckbox | ||
handleChange={handleChange} | ||
requests={requests} | ||
checkedAll={checkedAll} | ||
/> | ||
</form> | ||
</div> | ||
); | ||
|
||
RequestHolder.propTypes = { | ||
handleChange: PropTypes.func.isRequired, | ||
requests: PropTypes.array.isRequired, | ||
checkedAll: PropTypes.bool.isRequired | ||
}; | ||
|
||
export default RequestHolder; |
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,90 @@ | ||
import React, { Component, Fragment } from 'react'; | ||
|
||
// components | ||
import Navbar from '../common/Navbar'; | ||
|
||
const withRequests = (WrappedComponent, data) => { | ||
class ComponentWithData extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
checkAll: false | ||
}; | ||
|
||
this.handleInputChange = this.handleInputChange.bind(this); | ||
} | ||
|
||
componentDidMount() { | ||
this.addCheckedFieldToRequests(data.requests); | ||
} | ||
|
||
handleInputChange(event, request) { | ||
const { target } = event; | ||
const { name, checked } = target; | ||
|
||
/**to check if the mark all button was clicked | ||
* then change the checked field of all the requests | ||
*/ | ||
if (name === 'main-control') { | ||
return this.setState(previousState => { | ||
const updatedRequests = previousState.allRequests | ||
.map(request => ({ ...request, checked })); | ||
|
||
return { | ||
...previousState, | ||
checkAll: !previousState.checkAll, | ||
allRequests: updatedRequests | ||
}; | ||
}); | ||
} | ||
|
||
/** | ||
* this will handle when a single request is | ||
* selected and change the state of the mark all button | ||
*/ | ||
return this.setState(previousState => { | ||
const updatedRequest = previousState.allRequests | ||
.map(previousRequest => ((previousRequest.id === request.id) ? | ||
{ ...previousRequest, checked } : previousRequest)); | ||
|
||
return { | ||
...previousState, | ||
checkAll: false, | ||
allRequests: updatedRequest | ||
}; | ||
}); | ||
} | ||
|
||
addCheckedFieldToRequests(requests) { | ||
// take all the requests map through and add checked field | ||
const requestsWithCheckedField = requests | ||
.map(request => ({ ...request, checked: false })); | ||
|
||
return this.setState({ | ||
...this.state, | ||
allRequests: requestsWithCheckedField | ||
}); | ||
} | ||
|
||
render() { | ||
const { checkBoxes, checkAll, allRequests } = this.state; | ||
return ( | ||
<Fragment> | ||
<Navbar /> | ||
<WrappedComponent | ||
headerText={data.pageTitle} | ||
handleChange={this.handleInputChange} | ||
checkOne={checkBoxes} | ||
requests={allRequests} | ||
checkedAll={checkAll} | ||
/> | ||
</Fragment> | ||
); | ||
} | ||
} | ||
|
||
return ComponentWithData; | ||
}; | ||
|
||
export default withRequests; |
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,15 @@ | ||
import React from 'react'; | ||
import { Pagination } from 'semantic-ui-react'; | ||
|
||
const RequestPagination = () => ( | ||
<Pagination | ||
defaultActivePage={1} | ||
firstItem={null} | ||
lastItem={null} | ||
pointing | ||
secondary | ||
totalPages={10} | ||
/> | ||
); | ||
|
||
export default RequestPagination; |
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
30 changes: 30 additions & 0 deletions
30
client/src/tests/modules/Admin/components/AdminRequests.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,30 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import AdminRequests, { Request } from '../../../../modules/Admin/components/AdminRequest'; | ||
|
||
import requests from '../mock/mockData'; | ||
|
||
describe('Test for AdminRequests component', () => { | ||
const handleChange = jest.fn(); | ||
|
||
let props = { | ||
handleChange, | ||
requests: requests.data.requests | ||
}; | ||
|
||
let WrapperComponent = shallow(<AdminRequests {...props} />); | ||
|
||
it('should render properly', () => { | ||
expect(true).toBe(true); | ||
expect(WrapperComponent.length).toBe(1); | ||
}); | ||
}); | ||
|
||
describe('Test for Request component', () => { | ||
const WrapperComponent = shallow(<Request />); | ||
|
||
it('should render properly', () => { | ||
expect(WrapperComponent.length).toBe(1); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
client/src/tests/modules/Admin/components/RequestCheckbox.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,44 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import RequestCheckbox from '../../../../modules/Admin/components/RequestCheckbox'; | ||
|
||
import requests from '../mock/mockData'; | ||
|
||
describe('Test for RequestCheckbox component', () => { | ||
const handleChange = jest.fn(); | ||
|
||
let props = { | ||
handleChange, | ||
requests: requests.data.requests | ||
}; | ||
|
||
let WrapperComponent = shallow(<RequestCheckbox {...props} />); | ||
|
||
it('should render properly', () => { | ||
expect(WrapperComponent.length).toBe(props.requests.length); | ||
}); | ||
|
||
it('should render checkbox with the requests', () => { | ||
expect(WrapperComponent.find('input').get(0).props.type).toBe('checkbox'); | ||
|
||
expect(WrapperComponent.find('input').get(0).props.id).toBe(props.requests[0].id); | ||
}); | ||
|
||
it('should call the onChange event listener', () => { | ||
WrapperComponent.find('input').get(0).props.onChange(); | ||
|
||
expect(WrapperComponent.find('input').get(0).props.type).toBe('checkbox'); | ||
}); | ||
|
||
it('should render properly with no requests', () => { | ||
props = { | ||
handleChange, | ||
}; | ||
|
||
WrapperComponent = shallow(<RequestCheckbox {...props} />); | ||
|
||
expect(WrapperComponent.length).toBe(0); | ||
}); | ||
}); | ||
|
23 changes: 23 additions & 0 deletions
23
client/src/tests/modules/Admin/components/RequestHolder.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,23 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import RequestHolder from '../../../../modules/Admin/components/RequestHolder'; | ||
|
||
describe('Test for RequestHolder component', () => { | ||
const handleChange = jest.fn(); | ||
|
||
const WrapperComponent = shallow(<RequestHolder handleChange={handleChange} />); | ||
|
||
it('should render properly', () => { | ||
expect(WrapperComponent.find('.request-checkbox-container').length).toBe(1); | ||
}); | ||
|
||
it('should call the change event', () => { | ||
expect(true).toBe(true); | ||
|
||
WrapperComponent.find('#main-control').simulate('change'); | ||
|
||
expect(WrapperComponent.find('#main-control').length).toBe(1); | ||
}); | ||
}); | ||
|
Oops, something went wrong.