-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Control amount of replications displayed (#1391)
- Loading branch information
1 parent
0f65c6f
commit 034f5aa
Showing
14 changed files
with
301 additions
and
41 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
63 changes: 63 additions & 0 deletions
63
app/addons/replication/__tests__/replication-footer.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,63 @@ | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
// use this file except in compliance with the License. You may obtain a copy of | ||
// the License at | ||
// | ||
// http:https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations under | ||
// the License. | ||
|
||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import sinon from 'sinon'; | ||
import { ReplicationFooter } from '../components/replication-footer'; | ||
|
||
describe('Replication Footer', () =>{ | ||
it('no replications to display', () => { | ||
const footer = mount(<ReplicationFooter | ||
statusDocs={[]} | ||
pageLimit={5} | ||
setPageLimit={() => {}} | ||
/>); | ||
|
||
expect(footer.find('.current-replications').text()).toBe('Showing 0 replications.'); | ||
}); | ||
|
||
it('display max # of replications', () => { | ||
const footer = mount(<ReplicationFooter | ||
statusDocs={[1, 2, 3, 4, 5]} | ||
pageLimit={5} | ||
setPageLimit={() => {}} | ||
/>); | ||
|
||
expect(footer.find('.current-replications').text()).toBe('Showing replications 1 - 5'); | ||
}); | ||
|
||
it('display replications with less than max #', () => { | ||
const footer = mount(<ReplicationFooter | ||
statusDocs={[1, 2, 3, 4, 5, 6, 7, 8]} | ||
pageLimit={10} | ||
setPageLimit={() => {}} | ||
/>); | ||
|
||
expect(footer.find('.current-replications').text()).toBe('Showing replications 1 - 8'); | ||
}); | ||
|
||
it('change max value with dropdown', () => { | ||
const spy = sinon.spy(); | ||
const footer = mount(<ReplicationFooter | ||
statusDocs={[1, 2, 3, 4, 5, 6, 7, 8]} | ||
pageLimit={5} | ||
setPageLimit={spy} | ||
/>); | ||
|
||
expect(footer.find('.current-replications').text()).toBe('Showing replications 1 - 5'); | ||
footer.find('#select-per-page').simulate('change', { | ||
target: {value: 10} | ||
}); | ||
sinon.assert.calledOnce(spy); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
// use this file except in compliance with the License. You may obtain a copy of | ||
// the License at | ||
// | ||
// http:https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations under | ||
// the License. | ||
import PropTypes from 'prop-types'; | ||
|
||
import React from 'react'; | ||
import PerPageSelector from '../../documents/index-results/components/pagination/PerPageSelector'; | ||
|
||
export class ReplicationFooter extends React.Component { | ||
|
||
getFooterText () { | ||
const { statusDocs, pageLimit } = this.props; | ||
|
||
if (statusDocs.length === 0) { | ||
return <span>Showing 0 replications.</span>; | ||
} | ||
|
||
//either page limit or total # of replications, whichever is smaller | ||
return <span>Showing replications 1 - {Math.min(pageLimit, statusDocs.length)}</span>; | ||
} | ||
|
||
perPageChange (limit) { | ||
this.props.setPageLimit(limit); | ||
} | ||
|
||
render() { | ||
const { pageLimit } = this.props; | ||
|
||
return ( | ||
<footer className="pagination-footer"> | ||
<PerPageSelector label="Max replications displayed:" options={[5, 10, 25, 50, 100, 200, 300, 400, 500]} perPageChange={this.perPageChange.bind(this)} perPage={pageLimit} /> | ||
<div className="current-replications"> | ||
{this.getFooterText()} | ||
</div> | ||
</footer> | ||
); | ||
} | ||
} | ||
|
||
ReplicationFooter.propTypes = { | ||
statusDocs: PropTypes.array.isRequired, | ||
pageLimit: PropTypes.number.isRequired, | ||
setPageLimit: PropTypes.func.isRequired | ||
}; |
Oops, something went wrong.