Skip to content
Snippets Groups Projects
Select Git revision
  • a34930def960a7c289dfaf5e0f535442adad876e
  • mui5-annotation-on-video-stable default
  • get_setter_canvasSizeInformations
  • fix-error-div-into-p
  • annotation-on-video-v2
  • detached
  • annotation-on-video-r17
  • mui5
  • mui5-react-18
  • jacob-test
  • annotation-on-video protected
  • master
  • test-antoinev1
  • 20-fetch-thumbnail-on-annotation
  • add-research-field
  • Save
  • add-plugin
  • 14-wip-no-seek-to
  • 14-bug-on-video-time-control
  • 9_wip_videotests
  • _upgrade_material_ui
  • latest-tetras-16
  • v3.3.0
  • v3.2.0
  • v3.1.1
  • v3.1.0
  • v3.0.0
  • v3.0.0-rc.7
  • v3.0.0-rc.6
  • v3.0.0-rc.5
  • v3.0.0-rc.4
  • v3.0.0-rc.3
  • v3.0.0-rc.2
  • v3.0.0-rc.1
  • v3.0.0-beta.10
  • v3.0.0-beta.9
  • v3.0.0-beta.8
  • v3.0.0-beta.7
  • v3.0.0-beta.6
  • v3.0.0-beta.5
  • v3.0.0-beta.3
41 results

windows.test.js

Blame
  • windows.test.js 5.19 KiB
    import { windowsReducer } from '../../../src/state/reducers/windows';
    import ActionTypes from '../../../src/state/actions/action-types';
    
    describe('windows reducer', () => {
      it('should handle ADD_WINDOW', () => {
        expect(windowsReducer({}, {
          type: ActionTypes.ADD_WINDOW,
          window: { id: 'abc123' },
        })).toEqual({
          abc123: {
            id: 'abc123',
          },
        });
      });
      it('should handle REMOVE_WINDOW', () => {
        expect(windowsReducer({
          abc123: {
            id: 'abc123',
          },
          def456: {
            id: 'def456',
          },
        }, {
          type: ActionTypes.REMOVE_WINDOW,
          windowId: 'abc123',
        })).toEqual({
          def456: {
            id: 'def456',
          },
        });
      });
    
      it('should handle TOGGLE_WINDOW_SIDE_BAR by toggling the sideBarOpen attribute', () => {
        const action = {
          type: ActionTypes.TOGGLE_WINDOW_SIDE_BAR,
          windowId: 'abc123',
        };
        const before = {
          abc123: { sideBarOpen: true },
          abc321: { sideBarOpen: false },
        };
        const after = {
          abc123: { sideBarOpen: false },
          abc321: { sideBarOpen: false },
        };
    
        expect(windowsReducer(before, action)).toEqual(after);
      });
    
      it('should handle SET_WINDOW_THUMBNAIL_POSITION by changing the thumbnailNavigationPosition attribute', () => {
        const action = {
          type: ActionTypes.SET_WINDOW_THUMBNAIL_POSITION,
          windowId: 'abc123',
          position: 'right',
        };
        const before = {
          abc123: { thumbnailNavigationPosition: 'bottom' },
          abc321: { thumbnailNavigationPosition: 'off' },
        };
        const after = {
          abc123: { thumbnailNavigationPosition: 'right' },
          abc321: { thumbnailNavigationPosition: 'off' },
        };
    
        expect(windowsReducer(before, action)).toEqual(after);
      });
    
      it('should handle SET_WINDOW_VIEW_TYPE by changing the view attribute', () => {
        const action = {
          type: ActionTypes.SET_WINDOW_VIEW_TYPE,
          windowId: 'abc123',
          viewType: 'book',
        };
        const before = {
          abc123: { view: 'single' },
          abc321: { view: 'book' },
        };
        const after = {
          abc123: { view: 'book' },
          abc321: { view: 'book' },
        };
    
        expect(windowsReducer(before, action)).toEqual(after);
      });
    
      describe('TOGGLE_WINDOW_SIDE_BAR_PANEL', () => {
        it('sets the sideBarPanel value to the given value when it was changed', () => {
          const action = {
            type: ActionTypes.TOGGLE_WINDOW_SIDE_BAR_PANEL,
            windowId: 'abc123',
            panelType: 'info',
          };
          const before = {
            abc123: { sideBarPanel: 'closed' },
            abc321: { sideBarPanel: 'closed' },
          };
          const after = {
            abc123: { sideBarPanel: 'info' },
            abc321: { sideBarPanel: 'closed' },
          };
    
          expect(windowsReducer(before, action)).toEqual(after);
        });
    
        it('sets the sideBarPanel value to "closed" when trying to open a panel that already is open', () => {
          const action = {
            type: ActionTypes.TOGGLE_WINDOW_SIDE_BAR_PANEL,
            windowId: 'abc123',
            panelType: 'info',
          };
          const before = {
            abc123: { sideBarPanel: 'info' },
            abc321: { sideBarPanel: 'closed' },
          };
          const after = {
            abc123: { sideBarPanel: 'closed' },
            abc321: { sideBarPanel: 'closed' },
          };
    
          expect(windowsReducer(before, action)).toEqual(after);
        });
      });
    
      it('should handle NEXT_CANVAS', () => {
        expect(windowsReducer({
          abc123: {
            id: 'abc123',
            canvasIndex: 1,
          },
          def456: {
            id: 'def456',
            canvasIndex: 1,
          },
        }, {
          type: ActionTypes.NEXT_CANVAS,
          windowId: 'abc123',
        })).toEqual({
          abc123: {
            id: 'abc123',
            canvasIndex: 2,
          },
          def456: {
            id: 'def456',
            canvasIndex: 1,
          },
        });
      });
      it('should handle PREVIOUS_CANVAS', () => {
        expect(windowsReducer({
          abc123: {
            id: 'abc123',
            canvasIndex: 4,
          },
          def456: {
            id: 'def456',
            canvasIndex: 1,
          },
        }, {
          type: ActionTypes.PREVIOUS_CANVAS,
          windowId: 'abc123',
        })).toEqual({
          abc123: {
            id: 'abc123',
            canvasIndex: 3,
          },
          def456: {
            id: 'def456',
            canvasIndex: 1,
          },
        });
      });
      it('should handle SET_CANVAS', () => {
        expect(windowsReducer({
          abc123: {
            id: 'abc123',
            canvasIndex: 1,
          },
          def456: {
            id: 'def456',
            canvasIndex: 1,
          },
        }, {
          type: ActionTypes.SET_CANVAS,
          windowId: 'abc123',
          canvasIndex: 5,
        })).toEqual({
          abc123: {
            id: 'abc123',
            canvasIndex: 5,
          },
          def456: {
            id: 'def456',
            canvasIndex: 1,
          },
        });
      });
    
      describe('UPDATE_WINDOW', () => {
        it('updates an existing window', () => {
          const action = {
            type: ActionTypes.UPDATE_WINDOW,
            id: 'abc123',
            payload: { foo: 11, baz: 33 },
          };
          const beforeState = {
            abc123: {
              foo: 1,
              bar: 2,
            },
          };
          const expectedState = {
            abc123: {
              foo: 11,
              bar: 2,
              baz: 33,
            },
          };
          expect(windowsReducer(beforeState, action)).toEqual(expectedState);
        });
      });
    });