Skip to content
Snippets Groups Projects
Select Git revision
  • dd6eaca6d0ff64d8c1eadd53b68f55b5b83d6dc9
  • main default protected
  • export
  • 28-conversion-tests
  • extraction
  • exploration
  • exploration-old
  • 2-encoding-fix
  • main-old
9 results

mcli

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