Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow appending to existing search results #1159

Merged
merged 2 commits into from
Oct 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions web/client/actions/__tests__/search-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright 2016, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

var expect = require('expect');
var {
TEXT_SEARCH_RESULTS_LOADED,
searchResultLoaded
} = require('../search');

describe('Test correctness of the searc actions', () => {
it('search results loaded', () => {
const testVal = {data: ['result1', 'result2']};
const retval = searchResultLoaded(testVal);
expect(retval).toExist();
expect(retval.type).toBe(TEXT_SEARCH_RESULTS_LOADED);
expect(retval.results).toEqual(testVal.data);
expect(retval.append).toBe(false);

const retval2 = searchResultLoaded(testVal, true);
expect(retval2).toExist();
expect(retval2.type).toBe(TEXT_SEARCH_RESULTS_LOADED);
expect(retval2.results).toEqual(testVal.data);
expect(retval2.append).toBe(true);
});

});
6 changes: 4 additions & 2 deletions web/client/actions/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ const TEXT_SEARCH_RESET = 'TEXT_SEARCH_RESET';
const TEXT_SEARCH_ADD_MARKER = 'TEXT_SEARCH_ADD_MARKER';
const TEXT_SEARCH_TEXT_CHANGE = 'TEXT_SEARCH_TEXT_CHANGE';

function searchResultLoaded(results) {
function searchResultLoaded(results, append=false) {
return {
type: TEXT_SEARCH_RESULTS_LOADED,
results: results.data
results: results.data,
append: append
};
}

Expand Down Expand Up @@ -66,6 +67,7 @@ module.exports = {
TEXT_SEARCH_RESET,
TEXT_SEARCH_ADD_MARKER,
TEXT_SEARCH_TEXT_CHANGE,
searchResultLoaded,
textSearch,
resultsPurge,
resetSearch,
Expand Down
43 changes: 43 additions & 0 deletions web/client/reducers/__tests__/search-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright 2016, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var expect = require('expect');
var search = require('../search');

describe('Test the search reducer', () => {

it('search results loaded', () => {
let testAction1 = {
type: "TEXT_SEARCH_RESULTS_LOADED",
results: ["result1", "result2"]
};

let state = search({}, testAction1);
expect(state).toExist();
expect(state.results).toEqual(["result1", "result2"]);

let testAction2 = {
type: "TEXT_SEARCH_RESULTS_LOADED",
results: ["result3", "result4"]
};

state = search(state, testAction2);
expect(state).toExist();
expect(state.results).toEqual(["result3", "result4"]);

let testAction3 = {
type: "TEXT_SEARCH_RESULTS_LOADED",
results: ["result5", "result6"],
append: true
};

state = search(state, testAction3);
expect(state).toExist();
expect(state.results).toEqual(["result3", "result4", "result5", "result6"]);
});

});
6 changes: 5 additions & 1 deletion web/client/reducers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ function search(state = null, action) {
case TEXT_SEARCH_TEXT_CHANGE:
return assign({}, state, { searchText: action.searchText });
case TEXT_SEARCH_RESULTS_LOADED:
return assign({}, state, { results: action.results });
let results = action.results;
if (action.append === true && state && state.results) {
results = [...state.results, ...action.results];
}
return assign({}, state, { results: results });
case TEXT_SEARCH_RESULTS_PURGE:
return assign({}, state, { results: null });
case TEXT_SEARCH_ADD_MARKER:
Expand Down