diff --git a/__tests__/integration/mirador/window_actions.test.js b/__tests__/integration/mirador/window_actions.test.js index 0f62f257a2..58df7a6e33 100644 --- a/__tests__/integration/mirador/window_actions.test.js +++ b/__tests__/integration/mirador/window_actions.test.js @@ -19,5 +19,5 @@ describe('Window actions', () => { )); // only default configed windows found await page.waitFor(1000); await expect(numWindows).toBe(2); - }); + }, 10000); }); diff --git a/__tests__/src/lib/IFrameComm.test.js b/__tests__/src/lib/IFrameComm.test.js new file mode 100644 index 0000000000..d84299b879 --- /dev/null +++ b/__tests__/src/lib/IFrameComm.test.js @@ -0,0 +1,71 @@ +import React from 'react'; +import { mount } from 'enzyme'; +import { IframeComm } from '../../../src/lib/IFrameComm'; + +/** + * + * @param props + * @returns {*} + */ +function createWrapper(props) { + return mount( + {}} + handleReceiveMessage={() => {}} + postMessageData="this is a test" + {...props} + />, + ); +} + +let receivedMessage = {}; +const mockIFrameContents = { + contentWindow: { + postMessage: (postMessageData) => { + receivedMessage = postMessageData; + }, + }, +}; + +describe('IFrameComm', () => { + let wrapper; + it('renders properly', () => { + const handleReady = jest.fn(); + const handleReceiveMessage = jest.fn(); + wrapper = createWrapper({ handleReady, handleReceiveMessage }); + expect(wrapper.find(IframeComm).length).toBe(1); + wrapper.instance().setIFrameElement(mockIFrameContents); + wrapper.instance().onLoad(); + expect(handleReady).toHaveBeenCalled(); + expect(receivedMessage === 'this is a test').toBeTruthy(); + wrapper.instance().onReceiveMessage(); + expect(handleReceiveMessage).toHaveBeenCalled(); + }); + it('updates props', () => { + wrapper = createWrapper(); + wrapper.instance().setIFrameElement(mockIFrameContents); + wrapper.instance().onLoad(); + wrapper.setProps({ postMessageData: 'this is another test' }); + wrapper.instance().setIFrameElement(mockIFrameContents); + wrapper.instance().onLoad(); + expect(receivedMessage === 'this is another test').toBeTruthy(); + }); + it('returns data with no serialization option', () => { + wrapper = createWrapper({ serializeMessage: false }); + wrapper.instance().setIFrameElement(mockIFrameContents); + wrapper.instance().onLoad(); + expect(receivedMessage === 'this is a test').toBeTruthy(); + }); + it('returns data with when payload is an object', () => { + wrapper = createWrapper({ postMessageData: { object: 'this is an object' } }); + wrapper.instance().setIFrameElement(mockIFrameContents); + wrapper.instance().onLoad(); + expect(receivedMessage === '{"object":"this is an object"}').toBeTruthy(); + }); + it('ummounts', () => { + wrapper = createWrapper(); + const componentWillUnmount = jest.spyOn(wrapper.instance(), 'componentWillUnmount'); + wrapper.unmount(); + expect(componentWillUnmount).toHaveBeenCalled(); + }); +}); diff --git a/package.json b/package.json index 2c44ac5e13..59de0e2751 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,6 @@ "react-copy-to-clipboard": "^5.0.1", "react-full-screen": "^0.2.4", "react-i18next": "^10.11.4", - "react-iframe-comm": "^1.2.2", "react-image": "^2.1.3", "react-mosaic-component": "^3.2.0", "react-placeholder": "^3.0.1", diff --git a/src/components/AccessTokenSender.js b/src/components/AccessTokenSender.js index dae3bccdb3..80e87c613d 100644 --- a/src/components/AccessTokenSender.js +++ b/src/components/AccessTokenSender.js @@ -1,6 +1,6 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; -import IframeComm from 'react-iframe-comm'; +import { IframeComm } from '../lib/IFrameComm'; /** * Opens a new window for click @@ -32,6 +32,7 @@ export class AccessTokenSender extends Component { ); } diff --git a/src/components/WindowAuthenticationControl.js b/src/components/WindowAuthenticationControl.js index 87f70ab727..92786bbdc0 100644 --- a/src/components/WindowAuthenticationControl.js +++ b/src/components/WindowAuthenticationControl.js @@ -91,7 +91,7 @@ export class WindowAuthenticationControl extends Component {