diff --git a/entry_types/scrolled/package/spec/frontend/features/changeSectionMessage-spec.js b/entry_types/scrolled/package/spec/frontend/features/changeSectionMessage-spec.js
index 6fad4768f2..1a156e5ac7 100644
--- a/entry_types/scrolled/package/spec/frontend/features/changeSectionMessage-spec.js
+++ b/entry_types/scrolled/package/spec/frontend/features/changeSectionMessage-spec.js
@@ -1,7 +1,7 @@
import 'widgets/excursionSheet';
import {renderEntry, usePageObjects} from 'support/pageObjects';
-import {fakeParentWindow} from 'support';
+import {useFakeParentWindow} from 'support/fakeWindows';
import {changeLocationHash} from 'support/changeLocationHash';
import {useFakeTranslations} from 'pageflow/testHelpers';
import 'support/viewTimelineStub';
@@ -11,16 +11,12 @@ import userEvent from '@testing-library/user-event';
describe('CHANGE_SECTION message', () => {
usePageObjects();
+ useFakeParentWindow();
useFakeTranslations({
'pageflow_scrolled.public.close': 'Close'
});
- beforeEach(() => {
- fakeParentWindow()
- window.parent.postMessage = jest.fn();
- });
-
it('is posted when section becomes active', () => {
const {getSectionByPermaId} = renderEntry({
seed: {
diff --git a/entry_types/scrolled/package/spec/frontend/features/contentElementSelection-spec.js b/entry_types/scrolled/package/spec/frontend/features/contentElementSelection-spec.js
index 335eec1cd7..85b1f21023 100644
--- a/entry_types/scrolled/package/spec/frontend/features/contentElementSelection-spec.js
+++ b/entry_types/scrolled/package/spec/frontend/features/contentElementSelection-spec.js
@@ -3,7 +3,6 @@ import {frontend} from 'frontend';
import {features} from 'pageflow/frontend';
import {useInlineEditingPageObjects, renderEntry} from 'support/pageObjects';
-import {fakeParentWindow} from 'support';
import {changeLocationHash} from 'support/changeLocationHash';
import '@testing-library/jest-dom/extend-expect'
import {act, fireEvent, waitFor} from '@testing-library/react';
@@ -12,8 +11,6 @@ describe('content element selection', () => {
useInlineEditingPageObjects();
beforeEach(() => {
- fakeParentWindow()
- window.parent.postMessage = jest.fn();
window.location.hash = '#initial';
});
diff --git a/entry_types/scrolled/package/spec/frontend/features/editorCommentBadges-spec.js b/entry_types/scrolled/package/spec/frontend/features/editorCommentBadges-spec.js
index 44abfd4fab..20bc4741ba 100644
--- a/entry_types/scrolled/package/spec/frontend/features/editorCommentBadges-spec.js
+++ b/entry_types/scrolled/package/spec/frontend/features/editorCommentBadges-spec.js
@@ -3,7 +3,6 @@ import {act, waitFor} from '@testing-library/react';
import {features} from 'pageflow/frontend';
import {useInlineEditingPageObjects, renderEntry} from 'support/pageObjects';
-import {fakeParentWindow} from 'support';
import badgeStyles from 'review/Badge.module.css';
@@ -11,8 +10,6 @@ describe('editor comment badges', () => {
useInlineEditingPageObjects();
beforeEach(() => {
- fakeParentWindow();
- window.parent.postMessage = jest.fn();
features.enable('frontend', ['commenting']);
});
diff --git a/entry_types/scrolled/package/spec/frontend/features/insertContentElementMessage-spec.js b/entry_types/scrolled/package/spec/frontend/features/insertContentElementMessage-spec.js
index 803c870a85..2a39169f91 100644
--- a/entry_types/scrolled/package/spec/frontend/features/insertContentElementMessage-spec.js
+++ b/entry_types/scrolled/package/spec/frontend/features/insertContentElementMessage-spec.js
@@ -1,14 +1,9 @@
import {useInlineEditingPageObjects, renderEntry} from 'support/pageObjects';
-import {fakeParentWindow} from 'support';
import '@testing-library/jest-dom/extend-expect'
describe('INSERT_CONTENT_ELEMENT message', () => {
useInlineEditingPageObjects();
- beforeEach(() => {
- fakeParentWindow()
- window.parent.postMessage = jest.fn();
- });
it('is posted when selection rect insert button is clicked', () => {
const {getContentElementByTestId} = renderEntry({
diff --git a/entry_types/scrolled/package/spec/frontend/features/marginIndicator-spec.js b/entry_types/scrolled/package/spec/frontend/features/marginIndicator-spec.js
index a945cb35ce..3e70c3b6fb 100644
--- a/entry_types/scrolled/package/spec/frontend/features/marginIndicator-spec.js
+++ b/entry_types/scrolled/package/spec/frontend/features/marginIndicator-spec.js
@@ -1,14 +1,9 @@
import {useInlineEditingPageObjects, renderEntry} from 'support/pageObjects';
-import {fakeParentWindow} from 'support';
import '@testing-library/jest-dom/extend-expect';
describe('MarginIndicator', () => {
useInlineEditingPageObjects();
- beforeEach(() => {
- fakeParentWindow();
- });
-
it('displays scale translation for top margin when element is selected', () => {
const {getContentElementByTestId} = renderEntry({
seed: {
diff --git a/entry_types/scrolled/package/spec/frontend/features/moveContentElementMessage-spec.js b/entry_types/scrolled/package/spec/frontend/features/moveContentElementMessage-spec.js
index 1f40326fe0..e171d3a928 100644
--- a/entry_types/scrolled/package/spec/frontend/features/moveContentElementMessage-spec.js
+++ b/entry_types/scrolled/package/spec/frontend/features/moveContentElementMessage-spec.js
@@ -1,14 +1,9 @@
import {useInlineEditingPageObjects, renderEntry} from 'support/pageObjects';
-import {fakeParentWindow} from 'support';
import '@testing-library/jest-dom/extend-expect'
describe('MOVE_CONTENT_ELEMENT message', () => {
useInlineEditingPageObjects();
- beforeEach(() => {
- fakeParentWindow()
- window.parent.postMessage = jest.fn();
- });
it('is posted when content element is dragged before other content element', () => {
const {getContentElementByTestId} = renderEntry({
diff --git a/entry_types/scrolled/package/spec/frontend/features/paddingIndicator-spec.js b/entry_types/scrolled/package/spec/frontend/features/paddingIndicator-spec.js
index 75ce0cb454..d48ac557bf 100644
--- a/entry_types/scrolled/package/spec/frontend/features/paddingIndicator-spec.js
+++ b/entry_types/scrolled/package/spec/frontend/features/paddingIndicator-spec.js
@@ -1,5 +1,4 @@
import {useInlineEditingPageObjects, renderEntry} from 'support/pageObjects';
-import {fakeParentWindow} from 'support';
import {useMotifAreaState} from 'frontend/useMotifAreaState';
import '@testing-library/jest-dom/extend-expect';
@@ -8,10 +7,6 @@ jest.mock('frontend/useMotifAreaState');
describe('PaddingIndicator', () => {
useInlineEditingPageObjects();
- beforeEach(() => {
- fakeParentWindow();
- });
-
it('displays scale translation for top padding when section is selected', () => {
const {getSectionByPermaId} = renderEntry({
seed: {
diff --git a/entry_types/scrolled/package/spec/frontend/features/scrollPointMessages-spec.js b/entry_types/scrolled/package/spec/frontend/features/scrollPointMessages-spec.js
index a0a6e08d5a..10c74d6af1 100644
--- a/entry_types/scrolled/package/spec/frontend/features/scrollPointMessages-spec.js
+++ b/entry_types/scrolled/package/spec/frontend/features/scrollPointMessages-spec.js
@@ -1,5 +1,4 @@
import {renderEntry, useInlineEditingPageObjects} from 'support/pageObjects';
-import {fakeParentWindow} from 'support';
import {asyncHandlingOf} from 'support/asyncHandlingOf';
@@ -7,8 +6,6 @@ describe('scroll point messages', () => {
useInlineEditingPageObjects();
beforeEach(() => {
- fakeParentWindow();
- window.parent.postMessage = jest.fn();
window.scrollTo = jest.fn();
});
diff --git a/entry_types/scrolled/package/spec/frontend/features/selectedMessage-spec.js b/entry_types/scrolled/package/spec/frontend/features/selectedMessage-spec.js
index 4892a5d42b..44171d4a46 100644
--- a/entry_types/scrolled/package/spec/frontend/features/selectedMessage-spec.js
+++ b/entry_types/scrolled/package/spec/frontend/features/selectedMessage-spec.js
@@ -3,17 +3,12 @@ import {frontend, WidgetSelectionRect} from 'frontend';
import {features} from 'pageflow/frontend';
import {useInlineEditingPageObjects, renderEntry} from 'support/pageObjects';
-import {fakeParentWindow} from 'support';
import {act, fireEvent, waitFor} from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect'
describe('SELECTED message', () => {
useInlineEditingPageObjects();
- beforeEach(() => {
- fakeParentWindow()
- window.parent.postMessage = jest.fn();
- });
it('is posted when content element is clicked', () => {
frontend.contentElementTypes.register('text', {
diff --git a/entry_types/scrolled/package/spec/frontend/features/useContentElementConfigurationUpdate-spec.js b/entry_types/scrolled/package/spec/frontend/features/useContentElementConfigurationUpdate-spec.js
index d84bc64e92..e4034ad6f4 100644
--- a/entry_types/scrolled/package/spec/frontend/features/useContentElementConfigurationUpdate-spec.js
+++ b/entry_types/scrolled/package/spec/frontend/features/useContentElementConfigurationUpdate-spec.js
@@ -3,16 +3,11 @@ import React, {useEffect} from 'react';
import {frontend, useContentElementConfigurationUpdate} from 'frontend';
import {renderEntry, useInlineEditingPageObjects} from 'support/pageObjects';
-import {fakeParentWindow} from 'support';
import '@testing-library/jest-dom/extend-expect'
describe('useContentElementConfigurationUpdate', () => {
useInlineEditingPageObjects();
- beforeEach(() => {
- fakeParentWindow()
- window.parent.postMessage = jest.fn();
- });
it('lets content elements use hook to update their own configuration', () => {
frontend.contentElementTypes.register('text', {
diff --git a/entry_types/scrolled/package/spec/frontend/features/useWidgetConfigurationUpdate-spec.js b/entry_types/scrolled/package/spec/frontend/features/useWidgetConfigurationUpdate-spec.js
index 84d82ab6c0..90462063cc 100644
--- a/entry_types/scrolled/package/spec/frontend/features/useWidgetConfigurationUpdate-spec.js
+++ b/entry_types/scrolled/package/spec/frontend/features/useWidgetConfigurationUpdate-spec.js
@@ -3,16 +3,11 @@ import React, {useEffect} from 'react';
import {frontend, useWidgetConfigurationUpdate} from 'frontend';
import {renderEntry, useInlineEditingPageObjects} from 'support/pageObjects';
-import {fakeParentWindow} from 'support';
import '@testing-library/jest-dom/extend-expect'
describe('useWidgetConfigurationUpdate', () => {
useInlineEditingPageObjects();
- beforeEach(() => {
- fakeParentWindow()
- window.parent.postMessage = jest.fn();
- });
it('lets widgets use hook to update their own configuration', () => {
frontend.widgetTypes.register('customNavigation', {
diff --git a/entry_types/scrolled/package/spec/frontend/inlineEditing/EditableText/features/commentHighlights-spec.js b/entry_types/scrolled/package/spec/frontend/inlineEditing/EditableText/features/commentHighlights-spec.js
index 8419614e0c..bff7c586e6 100644
--- a/entry_types/scrolled/package/spec/frontend/inlineEditing/EditableText/features/commentHighlights-spec.js
+++ b/entry_types/scrolled/package/spec/frontend/inlineEditing/EditableText/features/commentHighlights-spec.js
@@ -3,7 +3,6 @@ import React from 'react';
import {features} from 'pageflow/frontend';
import {EditableText} from 'frontend';
import {renderEntry, useInlineEditingPageObjects} from 'support/pageObjects/inlineEditing';
-import {fakeParentWindow} from 'support';
import {act, waitFor} from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
@@ -50,8 +49,6 @@ describe('inline editing EditableText comment highlights', () => {
});
it('highlights pending new thread range from editor state', async () => {
- fakeParentWindow();
-
const entry = renderEntry({
contentElement: {
ui: ,
diff --git a/entry_types/scrolled/package/spec/frontend/inlineEditing/EditableText/features/commentSelection-spec.js b/entry_types/scrolled/package/spec/frontend/inlineEditing/EditableText/features/commentSelection-spec.js
index 5e479f6d48..7bc9bf1360 100644
--- a/entry_types/scrolled/package/spec/frontend/inlineEditing/EditableText/features/commentSelection-spec.js
+++ b/entry_types/scrolled/package/spec/frontend/inlineEditing/EditableText/features/commentSelection-spec.js
@@ -3,7 +3,6 @@ import React from 'react';
import {features} from 'pageflow/frontend';
import {EditableText} from 'frontend';
import {renderEntry, useInlineEditingPageObjects} from 'support/pageObjects/inlineEditing';
-import {fakeParentWindow} from 'support';
import {act} from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
@@ -22,8 +21,6 @@ describe('inline editing EditableText comment selection messages', () => {
});
it('posts SELECTED contentElementComments with highlightedThreadId on badge click', () => {
- fakeParentWindow();
- window.parent.postMessage = jest.fn();
const value = [
{type: 'paragraph', children: [{text: 'First paragraph'}]}
@@ -57,8 +54,6 @@ describe('inline editing EditableText comment selection messages', () => {
});
it('runs badge click logic and scrolls into view on SELECT_COMMENT_THREAD message', async () => {
- fakeParentWindow();
- window.parent.postMessage = jest.fn();
const scrollIntoView = jest.fn();
Element.prototype.scrollIntoView = scrollIntoView;
diff --git a/entry_types/scrolled/package/spec/frontend/inlineEditing/useSelectLinkDestination-spec.js b/entry_types/scrolled/package/spec/frontend/inlineEditing/useSelectLinkDestination-spec.js
index 4cfde36e75..50ff367a3b 100644
--- a/entry_types/scrolled/package/spec/frontend/inlineEditing/useSelectLinkDestination-spec.js
+++ b/entry_types/scrolled/package/spec/frontend/inlineEditing/useSelectLinkDestination-spec.js
@@ -1,13 +1,12 @@
import {useSelectLinkDestination} from 'frontend/inlineEditing/useSelectLinkDestination';
import {renderHook} from '@testing-library/react-hooks';
-import {fakeParentWindow} from 'support';
+import {useFakeParentWindow} from 'support/fakeWindows';
describe('useSelectLinkDestination', () => {
- it('returns function that posts SELECT_LINK_DESTINATION message', () => {
- fakeParentWindow();
- window.parent.postMessage = jest.fn();
+ useFakeParentWindow();
+ it('returns function that posts SELECT_LINK_DESTINATION message', () => {
const {result} = renderHook(() => useSelectLinkDestination());
const selectLinkDestination = result.current;
selectLinkDestination().catch(() => {});
@@ -19,9 +18,6 @@ describe('useSelectLinkDestination', () => {
});
it('returns function returns promise which resolves on LINK_DESTINATION_SELECTED message', () => {
- fakeParentWindow();
- window.parent.postMessage = jest.fn();
-
const {result} = renderHook(() => useSelectLinkDestination());
const selectLinkDestination = result.current;
const promise = selectLinkDestination();
@@ -35,9 +31,6 @@ describe('useSelectLinkDestination', () => {
});
it('rejects promise on when function is called again', () => {
- fakeParentWindow();
- window.parent.postMessage = jest.fn();
-
const {result} = renderHook(() => useSelectLinkDestination());
const selectLinkDestination = result.current;
const promise = selectLinkDestination();
@@ -47,9 +40,6 @@ describe('useSelectLinkDestination', () => {
});
it('ignores other messages send to window', () => {
- fakeParentWindow();
- window.parent.postMessage = jest.fn();
-
const {result} = renderHook(() => useSelectLinkDestination());
const selectLinkDestination = result.current;
const promise = selectLinkDestination();
diff --git a/entry_types/scrolled/package/spec/frontend/useContentElementEditorState/inEditorPreview-spec.js b/entry_types/scrolled/package/spec/frontend/useContentElementEditorState/inEditorPreview-spec.js
index d959146e21..1b55ce5a42 100644
--- a/entry_types/scrolled/package/spec/frontend/useContentElementEditorState/inEditorPreview-spec.js
+++ b/entry_types/scrolled/package/spec/frontend/useContentElementEditorState/inEditorPreview-spec.js
@@ -1,5 +1,6 @@
import {frontend, Entry, useContentElementEditorState} from 'pageflow-scrolled/frontend';
import {renderInEntry} from 'support';
+import {useFakeParentWindow} from 'support/fakeWindows';
import {useEditorSelection} from 'frontend/inlineEditing/EditorState';
import React, {useEffect} from 'react';
@@ -10,6 +11,7 @@ import {loadInlineEditingComponents} from 'frontend/inlineEditing';
describe('useContentElementEditorState in editor preview', () => {
beforeAll(loadInlineEditingComponents);
+ useFakeParentWindow();
it('lets content elements determine whether they are selected', () => {
frontend.contentElementTypes.register('test', {
@@ -98,7 +100,6 @@ describe('useContentElementEditorState in editor preview', () => {
});
it('lets content elements publish transient state via post message', () => {
- window.parent.postMessage = jest.fn();
frontend.contentElementTypes.register('test', {
component: function Test() {
const {setTransientState} = useContentElementEditorState();
@@ -116,7 +117,7 @@ describe('useContentElementEditorState in editor preview', () => {
}
});
- expect(window.postMessage).toHaveBeenCalledWith({
+ expect(window.parent.postMessage).toHaveBeenCalledWith({
type: 'UPDATE_TRANSIENT_CONTENT_ELEMENT_STATE',
payload: {
id: 5,
@@ -126,7 +127,6 @@ describe('useContentElementEditorState in editor preview', () => {
});
it('does not send message if transient state is shallow equal to previous transient state', () => {
- window.parent.postMessage = jest.fn();
frontend.contentElementTypes.register('test', {
component: function Test() {
const {setTransientState} = useContentElementEditorState();
@@ -144,8 +144,9 @@ describe('useContentElementEditorState in editor preview', () => {
}
});
+ window.parent.postMessage.mockClear();
rerender();
- expect(window.postMessage).toHaveBeenCalledTimes(1);
+ expect(window.parent.postMessage).not.toHaveBeenCalled();
});
});
diff --git a/entry_types/scrolled/package/spec/support/fakeWindows.js b/entry_types/scrolled/package/spec/support/fakeWindows.js
index 64b95789f3..981502c861 100644
--- a/entry_types/scrolled/package/spec/support/fakeWindows.js
+++ b/entry_types/scrolled/package/spec/support/fakeWindows.js
@@ -4,6 +4,19 @@ export function fakeParentWindow() {
Object.defineProperty(window, 'parent', {value: new JSDOM('').window });
};
+export function useFakeParentWindow() {
+ beforeAll(() => {
+ Object.defineProperty(window, 'parent', {
+ value: new JSDOM('').window,
+ configurable: true
+ });
+ });
+
+ beforeEach(() => {
+ window.parent.postMessage = jest.fn();
+ });
+}
+
export function createIframeWindow() {
const dom = new JSDOM('');
dom.reconfigure({windowTop: window, url: window.location.origin});
diff --git a/entry_types/scrolled/package/spec/support/pageObjects/inlineEditing.js b/entry_types/scrolled/package/spec/support/pageObjects/inlineEditing.js
index 30f42585c3..d1b97e59d6 100644
--- a/entry_types/scrolled/package/spec/support/pageObjects/inlineEditing.js
+++ b/entry_types/scrolled/package/spec/support/pageObjects/inlineEditing.js
@@ -5,6 +5,7 @@ import {loadInlineEditingComponents} from 'frontend/inlineEditing';
import {clearExtensions} from 'frontend/extensionRegistry';
import badgeStyles from 'review/Badge.module.css';
+import {useFakeParentWindow} from '../fakeWindows';
import {
renderEntry as baseRenderEntry,
usePageObjects
@@ -24,6 +25,8 @@ export function renderEntry({commenting, ...options} = {}) {
}
export function useInlineEditingPageObjects() {
+ useFakeParentWindow();
+
beforeAll(async () => {
await loadInlineEditingComponents();
});