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

manifest.test.js

Blame
  • user avatar
    Mathias Maaß authored
    cb3ad088
    History
    manifest.test.js 4.01 KiB
    import configureMockStore from 'redux-mock-store';
    import thunk from 'redux-thunk';
    
    import * as actions from '../../../src/state/actions';
    import ActionTypes from '../../../src/state/actions/action-types';
    
    const middlewares = [thunk];
    const mockStore = configureMockStore(middlewares);
    
    describe('manifest actions', () => {
      describe('requestManifest', () => {
        it('requests a manifest given a url', () => {
          const id = 'abc123';
          const expectedAction = {
            manifestId: id,
            type: ActionTypes.REQUEST_MANIFEST,
          };
          expect(actions.requestManifest(id)).toEqual(expectedAction);
        });
      });
      describe('receiveManifest', () => {
        it('receives a manifest', () => {
          const id = 'abc123';
          const json = {
            content: 'lots of metadata, canvases, and other IIIFy things',
            id,
          };
          const expectedAction = {
            manifestId: id,
            manifestJson: json,
            type: ActionTypes.RECEIVE_MANIFEST,
          };
          expect(actions.receiveManifest(id, json)).toEqual(expectedAction);
        });
      });
      describe('fetchManifest', () => {
        let store = null;
        beforeEach(() => {
          store = mockStore({});
        });
        describe('custom resourceHeaders', () => {
          it('are sent', () => {
            store = mockStore({ config: { resourceHeaders: { Accept: 'hello' } } });
            store.dispatch(actions.fetchManifest('https://purl.stanford.edu/sn904cj3429/iiif/manifest'));
            expect(fetch.mock.calls[0][1].headers).toEqual({ Accept: 'hello' });
          });
        });
        describe('success response', () => {
          beforeEach(() => {
            fetch.mockResponseOnce(JSON.stringify({ data: '12345' })); // eslint-disable-line no-undef
          });
          it('dispatches the REQUEST_MANIFEST action', () => {
            store.dispatch(actions.fetchManifest('https://purl.stanford.edu/sn904cj3429/iiif/manifest'));
            expect(store.getActions()).toEqual([
              {
                manifestId: 'https://purl.stanford.edu/sn904cj3429/iiif/manifest',
                properties: { isFetching: true },
                type: 'mirador/REQUEST_MANIFEST',
              },
            ]);
          });
          it('dispatches the REQUEST_MANIFEST and then RECEIVE_MANIFEST', () => {
            store.dispatch(actions.fetchManifest('https://purl.stanford.edu/sn904cj3429/iiif/manifest'))
              .then(() => {
                const expectedActions = store.getActions();
                expect(expectedActions).toEqual([
                  {
                    manifestId: 'https://purl.stanford.edu/sn904cj3429/iiif/manifest',
                    properties: { isFetching: true },
                    type: 'mirador/REQUEST_MANIFEST',
                  },
                  {
                    manifestId: 'https://purl.stanford.edu/sn904cj3429/iiif/manifest',
                    manifestJson: { data: '12345' },
                    type: 'mirador/RECEIVE_MANIFEST',
                  },
                ]);
              });
          });
        });
        describe('error response', () => {
          it('dispatches the REQUEST_MANIFEST and then RECEIVE_MANIFEST', () => {
            store.dispatch(actions.fetchManifest('https://purl.stanford.edu/sn904cj3429/iiif/manifest'))
              .then(() => {
                const expectedActions = store.getActions();
                expect(expectedActions).toEqual([
                  {
                    manifestId: 'https://purl.stanford.edu/sn904cj3429/iiif/manifest',
                    properties: { isFetching: true },
                    type: 'mirador/REQUEST_MANIFEST',
                  },
                  {
                    error: 'FetchError: invalid json response body at undefined reason: Unexpected end of JSON input',
                    manifestId: 'https://purl.stanford.edu/sn904cj3429/iiif/manifest',
                    type: 'mirador/RECEIVE_MANIFEST_FAILURE',
                  },
                ]);
              });
          });
        });
      });
      describe('removeManifest', () => {
        it('removes an existing manifest', () => {
          const expectedAction = {
            manifestId: 'foo',
            type: ActionTypes.REMOVE_MANIFEST,
          };
          expect(actions.removeManifest('foo')).toEqual(expectedAction);
        });
      });
    });