parent
4923cb20c7
commit
24e72aa6e0
8 changed files with 74 additions and 0 deletions
@ -0,0 +1,10 @@ |
|||||||
|
import actions from './index'; |
||||||
|
|
||||||
|
const setKeyword = (keyword) => { |
||||||
|
return { |
||||||
|
type: actions.FIND_SET_KEYWORD, |
||||||
|
keyword, |
||||||
|
}; |
||||||
|
}; |
||||||
|
|
||||||
|
export { setKeyword }; |
@ -0,0 +1,16 @@ |
|||||||
|
import actions from 'content/actions'; |
||||||
|
|
||||||
|
const defaultState = { |
||||||
|
keyword: null, |
||||||
|
}; |
||||||
|
|
||||||
|
export default function reducer(state = defaultState, action = {}) { |
||||||
|
switch (action.type) { |
||||||
|
case actions.FIND_SET_KEYWORD: |
||||||
|
return Object.assign({}, state, { |
||||||
|
keyword: action.keyword, |
||||||
|
}); |
||||||
|
default: |
||||||
|
return state; |
||||||
|
} |
||||||
|
} |
@ -1,12 +1,15 @@ |
|||||||
import settingReducer from './setting'; |
import settingReducer from './setting'; |
||||||
|
import findReducer from './find'; |
||||||
|
|
||||||
// Make setting reducer instead of re-use
|
// Make setting reducer instead of re-use
|
||||||
const defaultState = { |
const defaultState = { |
||||||
setting: settingReducer(undefined, {}), |
setting: settingReducer(undefined, {}), |
||||||
|
find: findReducer(undefined, {}), |
||||||
}; |
}; |
||||||
|
|
||||||
export default function reducer(state = defaultState, action = {}) { |
export default function reducer(state = defaultState, action = {}) { |
||||||
return Object.assign({}, state, { |
return Object.assign({}, state, { |
||||||
setting: settingReducer(state.setting, action), |
setting: settingReducer(state.setting, action), |
||||||
|
find: findReducer(state.find, action), |
||||||
}); |
}); |
||||||
} |
} |
||||||
|
@ -0,0 +1,13 @@ |
|||||||
|
import { expect } from "chai"; |
||||||
|
import actions from 'background/actions'; |
||||||
|
import * as findActions from 'background/actions/find'; |
||||||
|
|
||||||
|
describe("find actions", () => { |
||||||
|
describe("setKeyword", () => { |
||||||
|
it('create FIND_SET_KEYWORD action', () => { |
||||||
|
let action = findActions.setKeyword('banana'); |
||||||
|
expect(action.type).to.equal(actions.FIND_SET_KEYWORD); |
||||||
|
expect(action.keyword).to.equal('banana'); |
||||||
|
}); |
||||||
|
}); |
||||||
|
}); |
@ -0,0 +1,19 @@ |
|||||||
|
import { expect } from "chai"; |
||||||
|
import actions from 'background/actions'; |
||||||
|
import findReducer from 'background/reducers/find'; |
||||||
|
|
||||||
|
describe("find reducer", () => { |
||||||
|
it('return the initial state', () => { |
||||||
|
let state = findReducer(undefined, {}); |
||||||
|
expect(state).to.have.deep.property('keyword', null); |
||||||
|
}); |
||||||
|
|
||||||
|
it('return next state for FIND_SET_KEYWORD', () => { |
||||||
|
let action = { |
||||||
|
type: actions.FIND_SET_KEYWORD, |
||||||
|
keyword: 'cherry', |
||||||
|
}; |
||||||
|
let state = findReducer(undefined, action); |
||||||
|
expect(state).to.have.deep.property('keyword', 'cherry') |
||||||
|
}); |
||||||
|
}); |
Reference in new issue