diff --git a/src/editors/AdvancedEditor.test.tsx b/src/editors/AdvancedEditor.test.tsx index 741ae9cfb..32ab90945 100644 --- a/src/editors/AdvancedEditor.test.tsx +++ b/src/editors/AdvancedEditor.test.tsx @@ -30,6 +30,21 @@ describe('AdvancedEditor', () => { expect(onCloseMock).toHaveBeenCalled(); }); + it('should call onClose when receiving "save-clicked" message', () => { + const onCloseMock = jest.fn(); + + render(); + + const messageEvent = new MessageEvent('message', { + data: 'save-clicked', + origin: getConfig().STUDIO_BASE_URL, + }); + + window.dispatchEvent(messageEvent); + + expect(onCloseMock).toHaveBeenCalled(); + }); + it('should not call onClose if the message is from an invalid origin', () => { const onCloseMock = jest.fn(); diff --git a/src/editors/AdvancedEditor.tsx b/src/editors/AdvancedEditor.tsx index 60f7a6547..a044e6ad9 100644 --- a/src/editors/AdvancedEditor.tsx +++ b/src/editors/AdvancedEditor.tsx @@ -16,7 +16,7 @@ const AdvancedEditor = ({ usageKey, onClose }: AdvancedEditorProps) => { return; } - if (event.data === 'cancel-clicked' && onClose) { + if (onClose && (event.data === 'cancel-clicked' || event.data === 'save-clicked')) { onClose(); } };