Skip to content

Commit

Permalink
Add searchResultLoaded tests
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Oct 18, 2016
1 parent 265e436 commit 5a78b32
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
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 2015, 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);
});

});
1 change: 1 addition & 0 deletions web/client/actions/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,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 2015, 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('add new layer', () => {
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"]);
});

});

0 comments on commit 5a78b32

Please sign in to comment.