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

LayersPanel.js

Blame
  • IIIFAuthentication.test.js 4.29 KiB
    import { shallow } from 'enzyme';
    import WindowAuthenticationBar from '../../../src/containers/WindowAuthenticationBar';
    import { NewWindow } from '../../../src/components/NewWindow';
    import { AccessTokenSender } from '../../../src/components/AccessTokenSender';
    import { IIIFAuthentication } from '../../../src/components/IIIFAuthentication';
    
    /**
     * Helper function to create a shallow wrapper around IIIFAuthentication
     */
    function createWrapper(props) {
      return shallow(
        <IIIFAuthentication
          accessTokenServiceId="http://example.com/token"
          authServiceId="http://example.com/auth"
          failureDescription="... and this is why."
          failureHeader="Login failed"
          handleAuthInteraction={() => {}}
          isInteractive
          logoutServiceId="http://example.com/logout"
          resetAuthenticationState={() => {}}
          resolveAccessTokenRequest={() => {}}
          resolveAuthenticationRequest={() => {}}
          t={key => key}
          windowId="w"
          {...props}
        />,
      );
    }
    
    describe('IIIFAuthentication', () => {
      describe('without an auth service', () => {
        it('renders nothing', () => {
          const wrapper = createWrapper({ authServiceId: null });
          expect(wrapper.isEmptyRender()).toBe(true);
        });
      });
      describe('with an available auth service', () => {
        it('renders a login bar', () => {
          const handleAuthInteraction = jest.fn();
          const wrapper = createWrapper({ handleAuthInteraction });
          expect(wrapper.find(WindowAuthenticationBar).length).toBe(1);
          expect(wrapper.find(WindowAuthenticationBar).simulate('confirm'));
          expect(handleAuthInteraction).toHaveBeenCalledWith('w', 'http://example.com/auth');
        });
        it('renders nothing for a non-interactive login', () => {
          const wrapper = createWrapper({ isInteractive: false });
          expect(wrapper.isEmptyRender()).toBe(true);
        });
      });
      describe('with a failed authentication', () => {
        it('renders with an error message', () => {
          const handleAuthInteraction = jest.fn();
          const wrapper = createWrapper({ handleAuthInteraction, status: 'failed' });
          expect(wrapper.find(WindowAuthenticationBar).length).toBe(1);
          expect(wrapper.find(WindowAuthenticationBar).prop('confirmButton')).toEqual('retry');
          expect(wrapper.find(WindowAuthenticationBar).prop('status')).toEqual('failed');
          expect(wrapper.find(WindowAuthenticationBar).prop('header')).toEqual('Login failed');
          expect(wrapper.find(WindowAuthenticationBar).prop('description')).toEqual('... and this is why.');
          expect(wrapper.find(WindowAuthenticationBar).simulate('confirm'));
          expect(handleAuthInteraction).toHaveBeenCalledWith('w', 'http://example.com/auth');
        });
      });
      describe('in the middle of authenicating', () => {
        it('does the IIIF access cookie behavior', () => {
          const wrapper = createWrapper({ status: 'cookie' });
          expect(wrapper.find(WindowAuthenticationBar).length).toBe(1);
          expect(wrapper.find(NewWindow).length).toBe(1);
          expect(wrapper.find(NewWindow).prop('url')).toContain('http://example.com/auth?origin=');
        });
        it('does the IIIF access token behavior', () => {
          const wrapper = createWrapper({ status: 'token' });
          expect(wrapper.find(WindowAuthenticationBar).length).toBe(1);
          expect(wrapper.find(AccessTokenSender).length).toBe(1);
          expect(wrapper.find(AccessTokenSender).prop('url')).toEqual('http://example.com/token');
        });
      });
      describe('when logged in', () => {
        it('renders a logout button', () => {
          const openWindow = jest.fn();
          const resetAuthenticationState = jest.fn();
          const wrapper = createWrapper({
            logoutConfirm: 'exit',
            openWindow,
            resetAuthenticationState,
            status: 'ok',
          });
    
          expect(wrapper.find(WindowAuthenticationBar).length).toBe(1);
          expect(wrapper.find(WindowAuthenticationBar).prop('confirmButton')).toEqual('exit');
          expect(wrapper.find(WindowAuthenticationBar).prop('hasLogoutService')).toEqual(true);
    
          wrapper.find(WindowAuthenticationBar).simulate('confirm');
    
          expect(openWindow).toHaveBeenCalledWith('http://example.com/logout', undefined, 'centerscreen');
          expect(resetAuthenticationState).toHaveBeenCalledWith({
            authServiceId: 'http://example.com/auth', tokenServiceId: 'http://example.com/token',
          });
        });
      });
    });