From ff421cbf08adcb0d241266f2e896454442e29c80 Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Mon, 12 Feb 2024 16:14:02 +1100 Subject: [PATCH 1/2] Don't need to semi `UPDATE_STORY_ARGS` outside of actually updating args --- .../modules/preview-web/PreviewWeb.test.ts | 41 ++++++++----------- .../preview-web/PreviewWithSelection.tsx | 7 ---- 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/code/lib/preview-api/src/modules/preview-web/PreviewWeb.test.ts b/code/lib/preview-api/src/modules/preview-web/PreviewWeb.test.ts index e20af13752a6..024e4f6bbda8 100644 --- a/code/lib/preview-api/src/modules/preview-web/PreviewWeb.test.ts +++ b/code/lib/preview-api/src/modules/preview-web/PreviewWeb.test.ts @@ -208,15 +208,19 @@ describe('PreviewWeb', () => { one: 1, }); }); - it('updates args from the URL', async () => { + + it('prepares story with args from the URL', async () => { document.location.search = '?id=component-one--a&args=foo:url'; await createAndRenderPreview(); - expect(mockChannel.emit).toHaveBeenCalledWith(STORY_ARGS_UPDATED, { - storyId: 'component-one--a', - args: { foo: 'url', one: 1 }, - }); + expect(mockChannel.emit).toHaveBeenCalledWith( + STORY_PREPARED, + expect.objectContaining({ + id: 'component-one--a', + args: { foo: 'url', one: 1 }, + }) + ); }); it('allows async getProjectAnnotations', async () => { @@ -2798,20 +2802,6 @@ describe('PreviewWeb', () => { }); }); - it('emits STORY_ARGS_UPDATED with new args', async () => { - document.location.search = '?id=component-one--a'; - const preview = await createAndRenderPreview(); - mockChannel.emit.mockClear(); - - preview.onStoriesChanged({ importFn: newImportFn }); - await waitForRender(); - - expect(mockChannel.emit).toHaveBeenCalledWith(STORY_ARGS_UPDATED, { - storyId: 'component-one--a', - args: { foo: 'edited', one: 1 }, - }); - }); - it('applies loaders with story context', async () => { document.location.search = '?id=component-one--a'; const preview = await createAndRenderPreview(); @@ -3402,7 +3392,7 @@ describe('PreviewWeb', () => { }); }); - it('emits SET_STORY_ARGS with new values', async () => { + it('emits SET_PREPARED with new args', async () => { document.location.search = '?id=component-one--a'; const preview = await createAndRenderPreview(); @@ -3410,10 +3400,13 @@ describe('PreviewWeb', () => { preview.onGetProjectAnnotationsChanged({ getProjectAnnotations: newGetProjectAnnotations }); await waitForRender(); - expect(mockChannel.emit).toHaveBeenCalledWith(STORY_ARGS_UPDATED, { - storyId: 'component-one--a', - args: { foo: 'a', one: 1, global: 'added' }, - }); + expect(mockChannel.emit).toHaveBeenCalledWith( + STORY_PREPARED, + expect.objectContaining({ + id: 'component-one--a', + args: { foo: 'a', one: 1, global: 'added' }, + }) + ); }); it('calls renderToCanvas teardown', async () => { diff --git a/code/lib/preview-api/src/modules/preview-web/PreviewWithSelection.tsx b/code/lib/preview-api/src/modules/preview-web/PreviewWithSelection.tsx index 1095ebe14620..c60382e2ace3 100644 --- a/code/lib/preview-api/src/modules/preview-web/PreviewWithSelection.tsx +++ b/code/lib/preview-api/src/modules/preview-web/PreviewWithSelection.tsx @@ -404,13 +404,6 @@ export class PreviewWithSelection extends Preview Date: Thu, 4 Apr 2024 21:55:33 +1100 Subject: [PATCH 2/2] Drop unused import --- .../preview-api/src/modules/preview-web/PreviewWithSelection.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/code/lib/preview-api/src/modules/preview-web/PreviewWithSelection.tsx b/code/lib/preview-api/src/modules/preview-web/PreviewWithSelection.tsx index c60382e2ace3..b183a7488ba9 100644 --- a/code/lib/preview-api/src/modules/preview-web/PreviewWithSelection.tsx +++ b/code/lib/preview-api/src/modules/preview-web/PreviewWithSelection.tsx @@ -5,7 +5,6 @@ import { PRELOAD_ENTRIES, PREVIEW_KEYDOWN, SET_CURRENT_STORY, - STORY_ARGS_UPDATED, STORY_CHANGED, STORY_ERRORED, STORY_MISSING,