Skip to content

Commit

Permalink
Add possibility to pass custom options to search action (#1192)
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro authored and mbarto committed Oct 24, 2016
1 parent eeb7fd5 commit 3c17884
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions web/client/components/mapcontrols/search/SearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ let SearchBar = React.createClass({
blurResetDelay: React.PropTypes.number,
typeAhead: React.PropTypes.bool,
searchText: React.PropTypes.string,
style: React.PropTypes.object
style: React.PropTypes.object,
searchOptions: React.PropTypes.object
},
contextTypes: {
messages: React.PropTypes.object
Expand Down Expand Up @@ -117,7 +118,7 @@ let SearchBar = React.createClass({
if (text === undefined || text === "") {
this.props.onSearchReset();
} else {
this.props.onSearch(text);
this.props.onSearch(text, this.props.searchOptions);
}

},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,25 @@ describe("test the SearchBar", () => {
done();
}, 50);
});

it('test that options are passed to search action', () => {
var TestUtils = React.addons.TestUtils;
var tb;
const testHandlers = {
onSearchHandler: (text, options) => { return [text, options]; },
onSearchTextChangeHandler: (text) => { tb.setProps({searchText: text}); }
};

let searchOptions = {displaycrs: "EPSG:3857"};
const spy = expect.spyOn(testHandlers, 'onSearchHandler');
tb = ReactDOM.render(<SearchBar delay={0} typeAhead={false} onSearch={testHandlers.onSearchHandler} onSearchTextChange={testHandlers.onSearchTextChangeHandler} searchOptions={searchOptions}/>, document.getElementById("container"));
let input = ReactDOM.findDOMNode(TestUtils.scryRenderedDOMComponentsWithTag(tb, "input")[0]);

expect(input).toExist();
input.value = "test";
TestUtils.Simulate.change(input);
TestUtils.Simulate.keyDown(input, {key: "Enter", keyCode: 13, which: 13});
expect(spy.calls.length).toEqual(1);
expect(spy).toHaveBeenCalledWith('test', searchOptions);
});
});

0 comments on commit 3c17884

Please sign in to comment.