Skip to content
Snippets Groups Projects
Select Git revision
  • 794bad3b336298e543b9b1c6ac6b7017b8701542
  • 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

WindowSideBarAnnotationsPanel.test.js

Blame
  • miradorAnnotationPlugin.test.js 2.57 KiB
    import React from 'react';
    import { shallow } from 'enzyme';
    import { MiradorMenuButton } from 'mirador/dist/es/src/components/MiradorMenuButton';
    import LocalStorageAdapter from '../src/LocalStorageAdapter';
    import miradorAnnotationPlugin from '../src/plugins/miradorAnnotationPlugin';
    
    /** */
    function createWrapper(props) {
      return shallow(
        <miradorAnnotationPlugin.component
          canvases={[]}
          config={{}}
          TargetComponent="<div>hello</div>"
          targetProps={{}}
          addCompanionWindow={jest.fn()}
          receiveAnnotation={jest.fn()}
          {...props}
        />,
      );
    }
    
    describe('MiradorAnnotation', () => {
      let wrapper;
      it('renders a create new button', () => {
        wrapper = createWrapper();
        expect(wrapper.find(MiradorMenuButton).props()['aria-label']).toBe('Create new annotation');
      });
      it('opens a new companionWindow when clicked', () => {
        const mockAddCompanionWindow = jest.fn();
        const receiveAnnotationMock = jest.fn();
        wrapper = createWrapper({
          addCompanionWindow: mockAddCompanionWindow,
          receiveAnnotation: receiveAnnotationMock,
        });
        wrapper.find(MiradorMenuButton).simulate('click');
        expect(mockAddCompanionWindow).toHaveBeenCalledWith(
          'annotationCreation',
          {
            position: 'right',
          },
        );
      });
      it('renders no export button if export or LocalStorageAdapter are not configured', () => {
        wrapper = createWrapper();
        expect(wrapper.find(MiradorMenuButton).some({ 'aria-label': 'Export local annotations for visible items' })).toBe(false);
    
        wrapper = createWrapper({
          config: {
            annotation: {
              adapter: () => () => {},
              exportLocalStorageAnnotations: true,
            },
          },
        });
        expect(wrapper.find(MiradorMenuButton).some({ 'aria-label': 'Export local annotations for visible items' })).toBe(false);
    
        wrapper = createWrapper({
          config: {
            annotation: {
              adapter: (canvasId) => new LocalStorageAdapter(`test://?canvasId=${canvasId}`),
            },
          },
        });
        expect(wrapper.find(MiradorMenuButton).some({ 'aria-label': 'Export local annotations for visible items' })).toBe(false);
      });
      it('renders export button if export and LocalStorageAdapter are configured', () => {
        wrapper = createWrapper({
          config: {
            annotation: {
              adapter: (canvasId) => new LocalStorageAdapter(`test://?canvasId=${canvasId}`),
              exportLocalStorageAnnotations: true,
            },
          },
        });
        expect(wrapper.find(MiradorMenuButton).some({ 'aria-label': 'Export local annotations for visible items' })).toBe(true);
      });
    });