From 091957d4e8138e2b2c25b98a5d712a0f410a67a5 Mon Sep 17 00:00:00 2001 From: XnpioChV Date: Mon, 16 Dec 2024 13:28:16 -0500 Subject: [PATCH] feat: save-cliked added --- src/editors/AdvancedEditor.test.tsx | 15 +++++++++++++++ src/editors/AdvancedEditor.tsx | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) 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(); } };