Skip to content

Commit

Permalink
Fix preview test
Browse files Browse the repository at this point in the history
s
  • Loading branch information
Jondyr committed Dec 5, 2024
1 parent b3d7e4e commit 53a264d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('Preview', () => {
});

it('reloads preview when the selected form layout name changes', async () => {
const view = render();
render();
expect(appContextMock.previewIframeRef?.current?.src).toBe(
'http://localhost' +
previewPage(
Expand All @@ -99,9 +99,8 @@ describe('Preview', () => {
const newSelectedFormLayoutName = 'test';
appContextMock.selectedFormLayoutName = newSelectedFormLayoutName;

view.rerender(<Preview collapsed={false} onCollapseToggle={jest.fn()} />);

expect(appContextMock.previewIframeRef?.current?.src).toBe(
render();
expect(appContextMock.previewIframeRef.current.src).toBe(
'http://localhost' +
previewPage(
org,
Expand Down
20 changes: 11 additions & 9 deletions frontend/packages/ux-editor/src/components/Preview/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const PreviewFrame = () => {
mutate: createInstance,
data: instance,
isError: createInstanceError,
isPending: createInstancePending,
} = useCreatePreviewInstanceMutation(org, app);

useEffect(() => {
Expand All @@ -107,7 +108,7 @@ const PreviewFrame = () => {
};
}, [previewIframeRef]);

if (!instance) {
if (createInstancePending) {
return (
<StudioCenter>
{createInstanceError ? (
Expand All @@ -118,6 +119,14 @@ const PreviewFrame = () => {
</StudioCenter>
);
}
const previewURL = previewPage(
org,
app,
selectedFormLayoutSetName,
taskId,
selectedFormLayoutName,
instance?.id,
);

return (
<div className={classes.root}>
Expand All @@ -129,14 +138,7 @@ const PreviewFrame = () => {
ref={previewIframeRef}
className={cn(classes.iframe, classes[viewportToSimulate])}
title={t('ux_editor.preview')}
src={previewPage(
org,
app,
selectedFormLayoutSetName,
taskId,
selectedFormLayoutName,
instance?.id,
)}
src={previewURL}
onLoad={previewHasLoaded}
/>
</div>
Expand Down

0 comments on commit 53a264d

Please sign in to comment.