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

GalleryViewThumbnail.test.js

Blame
  • Loïs Poujade's avatar
    Loïs Poujade authored
    ran `npx @mui/codemod v5.0.0/preset-safe`
    024c592e
    History
    GalleryViewThumbnail.test.js 5.24 KiB
    import React from 'react';
    import { shallow } from 'enzyme';
    import { Utils } from 'manifesto.js';
    import Chip from '@mui/material/Chip';
    import IntersectionObserver from '@researchgate/react-intersection-observer';
    import manifestJson from '../../fixtures/version-2/019.json';
    import { GalleryViewThumbnail } from '../../../src/components/GalleryViewThumbnail';
    import IIIFThumbnail from '../../../src/containers/IIIFThumbnail';
    
    /** create wrapper */
    function createWrapper(props) {
      return shallow(
        <GalleryViewThumbnail
          canvas={Utils.parseManifest(manifestJson).getSequences()[0].getCanvases()[0]}
          classes={{ selected: 'selected' }}
          focusOnCanvas={() => {}}
          setCanvas={() => {}}
          {...props}
        />,
      );
    }
    
    describe('GalleryView', () => {
      let wrapper;
      it('sets a mirador-current-canvas-grouping class if the canvas is selected', () => {
        wrapper = createWrapper({ selected: true });
        expect(wrapper.find('div[role="button"]').at(0).prop('className')).toEqual('selected');
    
        wrapper = createWrapper({ selected: false });
        expect(wrapper.find('div[role="button"]').at(0).prop('className')).not.toEqual('selected');
      });
      it('renders the thumbnail', () => {
        wrapper = createWrapper({ config: { height: 55 } });
        expect(wrapper.find(IIIFThumbnail).length).toBe(1);
        expect(wrapper.find(IIIFThumbnail).prop('maxHeight')).toBe(55);
      });
      it('sets the selected canvas on click', () => {
        const setCanvas = jest.fn();
        wrapper = createWrapper({ setCanvas });
        wrapper.find('div[role="button"]').first().simulate('click');
        expect(setCanvas).toHaveBeenCalledWith('http://iiif.io/api/presentation/2.0/example/fixtures/canvas/24/c1.json');
      });
    
      it('sets the window mode if the selected canvas is clicked', () => {
        const focusOnCanvas = jest.fn();
        wrapper = createWrapper({ focusOnCanvas, selected: true });
        wrapper.find('div[role="button"]').first().simulate('click');
        expect(focusOnCanvas).toHaveBeenCalled();
      });
    
      it('sets the window mode if the user hits enter while on a canvas', () => {
        const focusOnCanvas = jest.fn();
        wrapper = createWrapper({ focusOnCanvas, selected: true });
        wrapper.find('div[role="button"]').first().simulate('keyUp', { key: 'Enter' });
        expect(focusOnCanvas).toHaveBeenCalled();
      });
    
      it('sets the window mode if the user hits space while on a canvas', () => {
        const focusOnCanvas = jest.fn();
        wrapper = createWrapper({ focusOnCanvas, selected: true });
        wrapper.find('div[role="button"]').first().simulate('keyUp', { key: ' ' });
        expect(focusOnCanvas).toHaveBeenCalled();
      });
    
      it('sets the canvas if the user hits a key (non-space or non-enter) while on a canvas', () => {
        const setCanvas = jest.fn();
        wrapper = createWrapper({ selected: true, setCanvas });
        wrapper.find('div[role="button"]').first().simulate('keyUp', { key: 'd' });
        expect(setCanvas).toHaveBeenCalledWith('http://iiif.io/api/presentation/2.0/example/fixtures/canvas/24/c1.json');
      });
    
      describe('on-demand annotation fetching', () => {
        it('fetches annotations', () => {
          const requestCanvasAnnotations = jest.fn();
          const canvas = {
            getHeight: () => 50,
            getWidth: () => 50,
          };
          wrapper = createWrapper({ annotationsCount: 0, canvas, requestCanvasAnnotations });
    
          wrapper.find(IntersectionObserver).simulate('change', { isIntersecting: true });
          expect(requestCanvasAnnotations).toHaveBeenCalled();
        });
        it('does nothing if there is no intersection', () => {
          const requestCanvasAnnotations = jest.fn();
          const canvas = {
            getHeight: () => 50,
            getWidth: () => 50,
          };
          wrapper = createWrapper({ canvas, requestCanvasAnnotations });
    
          wrapper.find(IntersectionObserver).simulate('change', { isIntersecting: false });
          expect(requestCanvasAnnotations).not.toHaveBeenCalled();
        });
        it('does nothing if there are already some annotations', () => {
          const requestCanvasAnnotations = jest.fn();
          const canvas = {
            getHeight: () => 50,
            getWidth: () => 50,
          };
          wrapper = createWrapper({ annotationsCount: 5, canvas, requestCanvasAnnotations });
    
          wrapper.find(IntersectionObserver).simulate('change', { isIntersecting: true });
          expect(requestCanvasAnnotations).not.toHaveBeenCalled();
        });
      });
    
      describe('annotation count chip', () => {
        it('hides the chip if there are no annotations', () => {
          wrapper = createWrapper({ annotationsCount: 0 });
          expect(wrapper.find(Chip).length).toEqual(0);
        });
    
        it('shows the number of search annotations on a canvas', () => {
          wrapper = createWrapper({ annotationsCount: 50 });
          expect(wrapper.find(Chip).length).toEqual(1);
          expect(wrapper.find(Chip).prop('label')).toEqual(50);
        });
      });
    
      describe('search annotation count chip', () => {
        it('hides the chip if there are no annotations', () => {
          wrapper = createWrapper({ searchAnnotationsCount: 0 });
          expect(wrapper.find(Chip).length).toEqual(0);
        });
    
        it('shows the number of search annotations on a canvas', () => {
          wrapper = createWrapper({ searchAnnotationsCount: 50 });
          expect(wrapper.find(Chip).length).toEqual(1);
          expect(wrapper.find(Chip).prop('label')).toEqual(50);
        });
      });
    });