Skip to content
Snippets Groups Projects
Select Git revision
  • 48baab94e9958b94d44dcb116a748554655f139c
  • demo_ci_gitlab_pages default
  • demo_gitlab_ci
  • 5-images-in-annotations
  • 5-final-images
  • 5-chpk-images-in-annot
  • tetras-main protected
  • 5-rebase-images-in-annot
  • 5-wip-images-in-annot
  • tmp
  • 1-edit-annotations-on-videos
  • 5-old-images-in-annotations
  • old_demo_ci_gitlab_pages
  • images_annotations
  • wip
  • devsetup
  • wip-annot-video-ui
  • wip-annotations-on-videos
  • master
  • v0.4.0_react16
  • wip-debugging-annotations
21 results

miradorAnnotationPlugin.test.js

Blame
  • Forked from IIIF / Mirador / Mirador annotations
    Source project has a limited visibility.
    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);
      });
    });