Skip to content

Commit

Permalink
Fix pagination text bug and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ericgio committed Aug 2, 2016
1 parent 3eaf3f7 commit 4d23def
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const Example = React.createClass({
onChange={selected => this.setState({selected})}
onInputChange={text => this.setState({text})}
options={largeDataSet ? bigData : states}
paginationText="Something different"
placeholder="Choose a state..."
ref="typeahead"
selected={selected}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-bootstrap-typeahead",
"version": "0.8.0",
"version": "0.8.1",
"description": "React-based typeahead using the Bootstrap theme",
"main": "lib/index.js",
"directories": {
Expand Down
1 change: 1 addition & 0 deletions src/Typeahead.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ const Typeahead = React.createClass({
'emptyLabel',
'maxHeight',
'newSelectionPrefix',
'paginationText',
'renderMenuItemChildren',
]);

Expand Down
28 changes: 28 additions & 0 deletions test/TypeaheadMenuSpec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {expect} from 'chai';
import {range} from 'lodash';
import React from 'react';
import ReactTestUtils from 'react/lib/ReactTestUtils';

Expand All @@ -7,6 +8,8 @@ import TypeaheadMenu from '../src/TypeaheadMenu.react';

import states from '../example/exampleData';

const bigData = range(0, 300).map(option => ({label: option.toString()}));

function getMenuInstance(props={}) {
return ReactTestUtils.renderIntoDocument(
<TypeaheadMenu
Expand Down Expand Up @@ -54,4 +57,29 @@ describe('<TypeaheadMenu>', () => {
expect(menuItems[0].props.children).to.equal('No matches found.');
});

it('paginates long data sets', () => {
const instance = getMenuInstance({options: bigData});
const paginatorNode = ReactTestUtils.findRenderedDOMComponentWithClass(
instance,
'bootstrap-typeahead-menu-paginator'
);
expect(paginatorNode).to.exist;
expect(paginatorNode.firstChild.innerHTML).to.equal(
'Display additional results...'
);
});

it('displays custom pagination text', () => {
const paginationText = 'See All';
const instance = getMenuInstance({
options: bigData,
paginationText,
});
const paginatorNode = ReactTestUtils.findRenderedDOMComponentWithClass(
instance,
'bootstrap-typeahead-menu-paginator'
);
expect(paginatorNode.firstChild.innerHTML).to.equal(paginationText);
});

});
22 changes: 22 additions & 0 deletions test/TypeaheadSpec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {expect} from 'chai';
import {range} from 'lodash';
import React from 'react';
import ReactTestUtils from 'react/lib/ReactTestUtils';

Expand Down Expand Up @@ -102,4 +103,25 @@ describe('<Typeahead>', () => {
expect(input.props.disabled).to.be.true;
});

it('should display a menu item for pagination', () => {
const options = range(0, 300).map(option => ({label: option.toString()}));
const paginationText = 'See More';
const instance = ReactTestUtils.renderIntoDocument(
<Typeahead options={options} paginationText={paginationText} />
);
const inputNode = ReactTestUtils.findRenderedDOMComponentWithClass(
instance,
'bootstrap-typeahead-input-main'
);
ReactTestUtils.Simulate.focus(inputNode);

const paginatorNode = ReactTestUtils.findRenderedDOMComponentWithClass(
instance,
'bootstrap-typeahead-menu-paginator'
);

expect(paginatorNode).to.exist;
expect(paginatorNode.firstChild.innerHTML).to.equal(paginationText);
});

});

0 comments on commit 4d23def

Please sign in to comment.