mirror of
https://github.com/wassname/talk.git
synced 2026-07-31 12:50:48 +08:00
Adding update state to reducer.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {Map, List, fromJS} from 'immutable';
|
||||
import {FETCH_ASSETS_SUCCESS} from '../constants/assets';
|
||||
import {FETCH_ASSETS_SUCCESS, UPDATE_ASSET_STATE} from '../constants/assets';
|
||||
|
||||
const initialState = Map({
|
||||
byId: Map(),
|
||||
@@ -8,7 +8,10 @@ const initialState = Map({
|
||||
|
||||
export default (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case FETCH_ASSETS_SUCCESS: return replaceAssets(action, state);
|
||||
case FETCH_ASSETS_SUCCESS:
|
||||
return replaceAssets(action, state);
|
||||
case UPDATE_ASSET_STATE:
|
||||
return state.setIn(['byId', action.id, 'closedAt'], action.closedAt);
|
||||
default: return state;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Map} from 'immutable';
|
||||
import {Map, fromJS} from 'immutable';
|
||||
import {expect} from 'chai';
|
||||
import assetsReducer from '../../../../client/coral-admin/src/reducers/assets';
|
||||
|
||||
@@ -23,7 +23,6 @@ describe ('assetsReducer', () => {
|
||||
};
|
||||
const store = new Map({});
|
||||
const result = assetsReducer(store, action);
|
||||
console.log(result.getIn(['byId', '123']).toJS());
|
||||
expect(result.getIn(['byId', '123']).toJS()).to.deep.equal({
|
||||
url: 'http://test.com',
|
||||
closedAt: 'tomorrow',
|
||||
@@ -36,4 +35,30 @@ describe ('assetsReducer', () => {
|
||||
expect(result.getIn(['count'])).to.equal(200);
|
||||
});
|
||||
});
|
||||
|
||||
describe('UPDATE_ASSET_STATE', () => {
|
||||
it('should update the state of a particular asset', () => {
|
||||
const action = {
|
||||
type: 'UPDATE_ASSET_STATE',
|
||||
id: '123',
|
||||
closedAt: null
|
||||
};
|
||||
const store = new fromJS({
|
||||
byId: {
|
||||
'123': {
|
||||
id: '123',
|
||||
url: 'http://test.com',
|
||||
closedAt: Date.now()
|
||||
},
|
||||
'456': {
|
||||
id: '456',
|
||||
url: 'http://test2.com',
|
||||
closedAt: 'thursday'
|
||||
}
|
||||
}
|
||||
});
|
||||
const result = assetsReducer(store, action);
|
||||
expect(result.getIn(['byId', '123', 'closedAt'])).to.equal.null;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user