import { ADD_ENTITY } from '../constants/ActionTypes';

function cmsAppState(state = [], action) {
  switch (action.type) {
    case ADD_ENTITY:
      return [
        ...state, {
          id: action.id,
          text: action.text,
          published: action.published
        }
      ];
    default:
      return state;
  }
}

import expect from 'expect';
import deepFreeze from 'deep-freeze';

const testAddEntity = () => {
  const stateBefore = [];
  const action = {
    type: ADD_ENTITY,
    id: 0,
    text: 'Cms String',
    published: false
  };
  const stateAfter = [
    {
      id: 0,
      text: 'Cms String',
      published: false
    }
  ];

  deepFreeze(stateBefore);
  deepFreeze(action);

  expect(
    cmsAppState(stateBefore, action)
  ).toEqual(stateAfter);
  console.log('Passed!');
};

testAddEntity();
export default cmsAppState;

@@ -284,16 +284,249 @@
      %5D;%0A
+    case 'TOGGLE_ENTITY':%0A      return state.map(entity =%3E %7B%0A        if (entity.id !== action.id) %7B%0A          return entity;%0A        %7D%0A        return %7B%0A          ...entity,%0A          published: !entity.published%0A        %7D;%0A      %7D);%0A
     defa
@@ -555,16 +555,44 @@
 e;%0A  %7D%0A%7D
+%0Aexport default cmsAppState;
 %0A%0Aimport
@@ -1040,79 +1040,654 @@
 r);%0A
-  console.log('Passed!');%0A%7D;%0A%0AtestAddEntity();%0Aexport default cmsAppState
+%7D;%0A%0Aconst testToggleEntity = () =%3E %7B%0A  const stateBefore = %5B%0A    %7B%0A      id: 0,%0A      text: 'Some entity',%0A      published: false%0A    %7D,%0A    %7B%0A      id: 1,%0A      text: 'Another entity',%0A      published: false%0A    %7D%0A  %5D;%0A  const action = %7B%0A    type: 'TOGGLE_ENTITY',%0A    id: 1%0A  %7D;%0A  const stateAfter = %5B%0A    %7B%0A      id: 0,%0A      text: 'Some entity',%0A      published: false%0A    %7D,%0A    %7B%0A      id: 1,%0A      text: 'Another entity',%0A      published: true%0A    %7D%0A  %5D;%0A%0A  deepFreeze(stateBefore);%0A  deepFreeze(action);%0A%0A  expect(%0A    cmsAppState(stateBefore, action)%0A  ).toEqual(stateAfter);%0A%7D;%0A%0AtestAddEntity();%0AtestToggleEntity();%0Aconsole.log('Passed!')
 ;%0A

Add action to toggle entity