Skip to content
Snippets Groups Projects
Select Git revision
  • 1d84b116005e2bbab8e219f38ad88459278e7aa9
  • mui5-tetras-main-stable default protected
  • mui5-tetras-main-old-stable
  • preprod protected
  • 75-dernieres-ameliorations-avant-workshop-du-7-02
  • wip-fix-xywh
  • wip-positionement-annot
  • wip-surface-transformer
  • uploads-file
  • 69-la-video-demare-quand-on-fait-glisser-le-slider-et-le-clic-creer-un-decalage-entre-le-player
  • 61-recettage-des-outils-d-annotation
  • gestion_multiple_ouverture_pannel_annotation
  • autorisation_un_pannel_annotation
  • autorisation_un_pannel_edition_annotation
  • récupération_temps_video
  • save-shapes-and-position
  • fix-error-create-annotation-pannel
  • time-saving-on-annotation
  • tetras-main protected
  • fix-poc-mirador
  • tetras-antho-test
21 results

TextEditor.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);
      });
    });