aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/reducers
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-01-06 15:42:04 +0100
committerNoah Loomans <noahloomans@gmail.com>2018-01-06 15:42:04 +0100
commitc0aa588bc8f85b13b5a55ccd6cdf11bf99048a1c (patch)
tree4914a9d09b362e222a83b0b9637ed87e11eebe7b /src/client/react/reducers
parent928edee90f4a35eea20d581e093b002be04e9b47 (diff)
Add user page
Diffstat (limited to 'src/client/react/reducers')
-rw-r--r--src/client/react/reducers/search.js20
-rw-r--r--src/client/react/reducers/search.test.js22
2 files changed, 41 insertions, 1 deletions
diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js
index 6027ed7..7c7e917 100644
--- a/src/client/react/reducers/search.js
+++ b/src/client/react/reducers/search.js
@@ -27,6 +27,22 @@ function getSearchResults(allUsers, query) {
const search = (state = DEFAULT_STATE, action) => {
switch (action.type) {
+ case 'SEARCH/SET_USER': {
+ const { user } = action;
+
+ if (user == null) {
+ return DEFAULT_STATE;
+ }
+
+ return {
+ ...state,
+ results: [],
+ searchText: users.byId[user].value,
+ selectedResult: user,
+ isExactMatch: true,
+ };
+ }
+
case 'SEARCH/INPUT_CHANGE': {
const { searchText } = action;
const results = getSearchResults(users.allUsers, action.searchText);
@@ -82,3 +98,7 @@ const search = (state = DEFAULT_STATE, action) => {
};
export default search;
+
+export const _test = {
+ DEFAULT_STATE,
+};
diff --git a/src/client/react/reducers/search.test.js b/src/client/react/reducers/search.test.js
index ddd7f9b..22d32e2 100644
--- a/src/client/react/reducers/search.test.js
+++ b/src/client/react/reducers/search.test.js
@@ -12,10 +12,30 @@ window.USERS = [
const deepFreeze = require('deep-freeze');
const search = require('./search').default;
-const { inputChange, changeSelectedResult } = require('../actions/search');
+const { _test } = require('./search');
+const {
+ setUser,
+ inputChange,
+ changeSelectedResult,
+} = require('../actions/search');
describe('reducers', () => {
describe('search', () => {
+ describe('SEARCH/SET_USER', () => {
+ it('Resets to the default state if the user is null', () => {
+ expect(search({ foo: 'bar' }, setUser(null))).toEqual(_test.DEFAULT_STATE);
+ });
+
+ it('Sets all the values of that user properly', () => {
+ expect(search(undefined, setUser('s/18561'))).toEqual({
+ results: [],
+ searchText: '18561',
+ selectedResult: 's/18561',
+ isExactMatch: true,
+ });
+ });
+ });
+
describe('SEARCH/INPUT_CHANGE', () => {
it('Returns no results when nothing is typed in', () => {
expect(search(undefined, inputChange(''))).toEqual({