<commit_before>import { ADD_CHILD, MOVE_CHILD, DELETE_COMPONENT, UPDATE_STYLE } from '../../app/actions/workspace';
import { ADD_STATE, ADD_PROPS, ADD_STYLES, ADD_EVENTS, DELETE_STATE, DELETE_PROPS, DELETE_STYLES, DELETE_EVENTS } from '../../app/actions/config';
import { SET_ACTIVE_COMPONENT } from '../../app/actions/FileSystemActions';
import { WORKSPACE_ID } from '../../app/constants';
import addComponent from '../../app/reducers/workspace/addComponent';
import moveComponent from '../../app/reducers/workspace/moveComponent';
import addStateValue from '../../app/reducers/workspace/addStateValue';
import addPropsValue from '../../app/reducers/workspace/addPropsValue';
import addStyleValue from '../../app/reducers/workspace/addStyleValue';
import addEvent from '../../app/reducers/workspace/addEvent';
import deleteStateValue from '../../app/reducers/workspace/deleteStateValue';
import deletePropsValue from '../../app/reducers/workspace/deletePropsValue';
import deleteStylesValue from '../../app/reducers/workspace/deleteStylesValue';
import deleteEvent from '../../app/reducers/workspace/deleteEvent';
import setActiveComponent from '../../app/reducers/workspace/setActiveComponent';
import updateStyle from '../../app/reducers/workspace/updateStyle';

import workspace from '../../app/reducers/workspace/index';

const defaultWorkspace = {
  componentCounter: 2,
  activeComponent: '0',
  components: {
    workspace: {
      id: WORKSPACE_ID,
      children: [0, 1],
    },
  },
  state: { default: 'default' },
};

defaultWorkspace.components[0] = {
  id: 0,
  name: 'BlackBox',
  children: [],
  parentID: WORKSPACE_ID,
  props: {
    style: {
      position: 'relative',
      height: '100px',
      width: '100px',
      display: 'inline-block',
      backgroundColor: 'black',
      overflow: 'auto',
    },
    testProp: null,
  },
  events: { test: 'test' }
};

defaultWorkspace.components[1] = {
  id: 1,
  name: 'BlueBox',
  children: [],
  parentID: WORKSPACE_ID,
  props: {
    style: {
      position: 'relative',
      height: '100px',
      width: '100px',
      display: 'inline-block',
      backgroundColor: 'blue',
      overflow: 'auto',
    },
  },
  events: { test: 'event test =]' }
};



describe('workspace Reducer', () => {
  describe('CASE: ADD CHILD', () => {
    it('should add a child to the workspace state', () => {
      const actionMock = {
        type: ADD_CHILD,
        newComponent: {
          id: 2,
          name: 'test',
          props: {
            style: {
              position: 'relative',
            },
          },
          events: {test: 'test'}
        },
      };
      const result = workspace(defaultWorkspace, actionMock);
      expect(result).toMatchSnapshot();
      expect(result).toHaveProperty('componentCounter', 3);
      expect(result).toHaveProperty('components.workspace.children', [0,1,2]);
        //write some more here later, this is a big object and needs to be controlled.
    });
  });
  
  describe('CASE: MOVE_CHILD', () => {
    it('should nest a component in another component', () => {
      const actionMock = {
        type: MOVE_CHILD,
        targetID: 1,
        sourceID: 0,
      };
      const result = workspace(defaultWorkspace, actionMock);
      expect(result).toMatchSnapshot();
      expect(result).toHaveProperty('componentCounter', 2);
      expect(result.components[1]).toHaveProperty('children', [0]);
    });

    it('should not move a component into itself', () => {
      const actionMock = {
        type: MOVE_CHILD,
        targetID: 1,
        sourceID: 1,
      };

      const result = workspace(defaultWorkspace, actionMock);
      expect(result).toMatchObject(defaultWorkspace);
    });

    it('should not move a component into its own parent', () => {
      const actionMock = {
        type: MOVE_CHILD,
        targetID: WORKSPACE_ID,
        sourceID: 0,
      };

      const result = workspace(defaultWorkspace, actionMock);<commit_msg>Update test/reducers/workspace to new naming convention (CHILD -> COMPONENT)<commit_after>import { ADD_COMPONENT, MOVE_COMPONENT, DELETE_COMPONENT, UPDATE_STYLE } from '../../app/actions/workspace';
import { ADD_STATE, ADD_PROPS, ADD_STYLES, ADD_EVENTS, DELETE_STATE, DELETE_PROPS, DELETE_STYLES, DELETE_EVENTS } from '../../app/actions/config';
import { SET_ACTIVE_COMPONENT } from '../../app/actions/FileSystemActions';
import { WORKSPACE_ID } from '../../app/constants';
import addComponent from '../../app/reducers/workspace/addComponent';
import moveComponent from '../../app/reducers/workspace/moveComponent';
import addStateValue from '../../app/reducers/workspace/addStateValue';
import addPropsValue from '../../app/reducers/workspace/addPropsValue';
import addStyleValue from '../../app/reducers/workspace/addStyleValue';
import addEvent from '../../app/reducers/workspace/addEvent';
import deleteStateValue from '../../app/reducers/workspace/deleteStateValue';
import deletePropsValue from '../../app/reducers/workspace/deletePropsValue';
import deleteStylesValue from '../../app/reducers/workspace/deleteStylesValue';
import deleteEvent from '../../app/reducers/workspace/deleteEvent';
import setActiveComponent from '../../app/reducers/workspace/setActiveComponent';
import updateStyle from '../../app/reducers/workspace/updateStyle';

import workspace from '../../app/reducers/workspace/index';

const defaultWorkspace = {
  componentCounter: 2,
  activeComponent: '0',
  components: {
    workspace: {
      id: WORKSPACE_ID,
      children: [0, 1],
    },
  },
  state: { default: 'default' },
};

defaultWorkspace.components[0] = {
  id: 0,
  name: 'BlackBox',
  children: [],
  parentID: WORKSPACE_ID,
  props: {
    style: {
      position: 'relative',
      height: '100px',
      width: '100px',
      display: 'inline-block',
      backgroundColor: 'black',
      overflow: 'auto',
    },
    testProp: null,
  },
  events: { test: 'test' }
};

defaultWorkspace.components[1] = {
  id: 1,
  name: 'BlueBox',
  children: [],
  parentID: WORKSPACE_ID,
  props: {
    style: {
      position: 'relative',
      height: '100px',
      width: '100px',
      display: 'inline-block',
      backgroundColor: 'blue',
      overflow: 'auto',
    },
  },
  events: { test: 'event test =]' }
};



describe('workspace Reducer', () => {
  describe('CASE: ADD CHILD', () => {
    it('should add a child to the workspace state', () => {
      const actionMock = {
        type: ADD_COMPONENT,
        newComponent: {
          id: 2,
          name: 'test',
          props: {
            style: {
              position: 'relative',
            },
          },
          events: {test: 'test'}
        },
      };
      const result = workspace(defaultWorkspace, actionMock);
      expect(result).toMatchSnapshot();
      expect(result).toHaveProperty('componentCounter', 3);
      expect(result).toHaveProperty('components.workspace.children', [0,1,2]);
        //write some more here later, this is a big object and needs to be controlled.
    });
  });
  
  describe('CASE: MOVE_CHILD', () => {
    it('should nest a component in another component', () => {
      const actionMock = {
        type: MOVE_COMPONENT,
        targetID: 1,
        sourceID: 0,
      };
      const result = workspace(defaultWorkspace, actionMock);
      expect(result).toMatchSnapshot();
      expect(result).toHaveProperty('componentCounter', 2);
      expect(result.components[1]).toHaveProperty('children', [0]);
    });

    it('should not move a component into itself', () => {
      const actionMock = {
        type: MOVE_COMPONENT,
        targetID: 1,
        sourceID: 1,
      };

      const result = workspace(defaultWorkspace, actionMock);
      expect(result).toMatchObject(defaultWorkspace);
    });

    it('should not move a component into its own parent', () => {
      const actionMock = {
        type: MOVE_COMPONENT,
        targetID: WORKSPACE_ID,
        sourceID: 0,
      };

      const result = workspace(defaultWorkspace, actionMock);
{'fraction_non_alphanumeric': 0.15077881619937694, 'fraction_numerical': 0.00822429906542056, 'mean_word_length': 2.9113060428849904, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6623332', 'n_tokens_mistral': 2428, 'n_tokens_neox': 2394, 'n_words': 540}