Skip to content
Snippets Groups Projects
Select Git revision
  • 4e17d8d3313a1ef388fed894fd9847124b05fe18
  • main default
  • 35-cgu
  • 34-peertube-support
  • 27-add-autoplay-to-iframe
  • 33-bug-on-youtube-embed-urls
  • RC-Rekall-v1.1-fix_lpo
  • tuleap-140-go-back-to-my-capsules-page-when-i-m-on-capsule-preview-page
  • RC-Rekall-v1.2-fix10
  • RC-Rekall-v1.2-fix9
  • RC-Rekall-v1.2-fix8
  • RC-Rekall-v1.2-fix7
  • RC-Rekall-v1.2-fix6
  • RC-Rekall-v1.2-fix5
  • RC-Rekall-v1.2-fix4
  • RC-Rekall-v1.2-fix3
  • RC-Rekall-v1.2-fix2
  • RC-Rekall-v1.2-fix1
  • RC-Rekall-v1.1-fix-3
  • RC-Rekall-v1.1-fix-2
  • RC-Rekall-v1.1-fix-1
  • RC-Rekall-v1.1-delivered
  • preprod20220209-1535
23 results

README.md

Blame
  • To learn more about this project, read the wiki.
    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);
        });
      });
    });