Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Merge release/3.2.2 #44

Merged
merged 8 commits into from
Oct 9, 2017
Merged
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sn-redux",
"version": "3.2.1",
"version": "3.2.2",
"description": "A set of redux actions, reducers and redux-ovbservable epics for Sense/Net ECM",
"main": "dist/src/sn-redux.js",
"scripts": {
Expand Down
8 changes: 7 additions & 1 deletion src/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,13 @@ export module Actions {
export const DeSelectContent = (id) => ({
type: 'DESELECT_CONTENT',
id
})
})/**
* Action creator for clearing the array of selected content
* @returns {Object} Returns a redux action.
*/
export const ClearSelection = () => ({
type: 'CLEAR_SELECTION'
})
/**
* Action creator for a request for get actions of a content by a given scenario.
* @param content {Content} The name of the scenario
Expand Down
14 changes: 10 additions & 4 deletions src/Reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,21 @@ export module Reducers {
*/
export const entities = (state = {}, action) => {
if (action.response && (
action.type !== 'USER_LOGIN_SUCCESS' &&
action.type !== 'USER_LOGIN_BUFFER' &&
action.type !== 'USER_LOGIN_SUCCESS' &&
action.type !== 'USER_LOGIN_BUFFER' &&
action.type !== 'LOAD_CONTENT_SUCCESS' &&
action.type !== 'REQUEST_CONTENT_ACTIONS_SUCCESS')) {
action.type !== 'REQUEST_CONTENT_ACTIONS_SUCCESS' &&
action.type !== 'UPDATE_CONTENT_SUCCESS')) {
return (<any>Object).assign({}, state, action.response.entities.entities);
}
switch (action.type) {
case 'DELETE_CONTENT_SUCCESS':
let res = Object.assign({}, state);
delete res[action.id];
return res;
case 'UPDATE_CONTENT_SUCCESS':
state[action.response.Id] = action.response
return state
default:
return state;
}
Expand Down Expand Up @@ -581,6 +585,8 @@ export module Reducers {
case 'DESELECT_CONTENT':
const index = state.indexOf(action.id)
return [...state.slice(0, index), ...state.slice(index + 1)]
case 'CLEAR_SELECTION':
return []
default:
return state
}
Expand Down Expand Up @@ -646,7 +652,7 @@ export module Reducers {
export const getChildrenActions = (state) => {
return state.actions
}

export const getCurrentContent = (state) => {
return state.currentcontent.content
}
Expand Down
8 changes: 8 additions & 0 deletions test/ActionsTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,14 @@ describe('Actions', () => {
expect(Actions.DeSelectContent(1)).to.deep.equal(expectedAction)
})
})
describe('ClearSelection', () => {
it('should return the clear selection action', () => {
const expectedAction = {
type: 'CLEAR_SELECTION'
}
expect(Actions.ClearSelection()).to.deep.equal(expectedAction)
})
})
describe('RequestContentActions', () => {

const content = Content.Create({ DisplayName: 'My content', Id: 123 }, ContentTypes.Task, repo)
Expand Down
34 changes: 34 additions & 0 deletions test/ReducersTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,34 @@ describe('Reducers', () => {
expect(Reducers.entities({}, { response: { entities: { entities: { a: 0, b: 2 } } } }))
.to.be.deep.eq({ a: 0, b: 2 });
});
it('should handle UPDATE_CONTENT_SUCCESS', () => {
const entities = {
5145: {
Id: 5145,
DisplayName: 'Some Article',
Status: ['Active']
},
5146: {
Id: 5146,
Displayname: 'Other Article',
Status: ['Completed']
}
};
expect(Reducers.entities(entities, { type: 'UPDATE_CONTENT_SUCCESS', response: { Id: 5145, DisplayName: 'aaa', Status: ['Active'] } })).to.be.deep.equal(
{
5145: {
Id: 5145,
DisplayName: 'aaa',
Status: ['Active']
},
5146: {
Id: 5146,
Displayname: 'Other Article',
Status: ['Completed']
}
}
);
});
});

describe('isFetching reducer', () => {
Expand Down Expand Up @@ -665,6 +693,12 @@ describe('Reducers', () => {
}
expect(Reducers.selected([1], action)).to.deep.equal([]);
})
it('should return an empty array', () => {
const action = {
type: 'CLEAR_SELECTION'
}
expect(Reducers.selected([1], action)).to.deep.equal([]);
})
})
describe('getContent', () => {
const state = {
Expand Down