Skip to content

Commit

Permalink
feat: save-cliked added
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Dec 16, 2024
1 parent 14f311d commit 091957d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/editors/AdvancedEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ describe('AdvancedEditor', () => {
expect(onCloseMock).toHaveBeenCalled();
});

it('should call onClose when receiving "save-clicked" message', () => {
const onCloseMock = jest.fn();

render(<AdvancedEditor usageKey="test" onClose={onCloseMock} />);

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();

Expand Down
2 changes: 1 addition & 1 deletion src/editors/AdvancedEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};
Expand Down

0 comments on commit 091957d

Please sign in to comment.