Skip to content

Commit

Permalink
Merge pull request #18370 from storybookjs/tom/sb-393-sb18347-showpre…
Browse files Browse the repository at this point in the history
…paringdocs-applies

Preview: Default select to `viewMode` story
  • Loading branch information
shilman committed May 31, 2022
2 parents cb5b600 + 05740e6 commit b689333
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions lib/preview-web/src/PreviewWeb.test.ts
Expand Up @@ -1415,6 +1415,23 @@ describe('PreviewWeb', () => {
});
});

describe('if called on a storybook without selection', () => {
it('sets viewMode to story by default', async () => {
await createAndRenderPreview();

emitter.emit(SET_CURRENT_STORY, {
storyId: 'component-one--b',
});
await waitForSetCurrentStory();

expect(history.replaceState).toHaveBeenCalledWith(
{},
'',
'pathname?id=component-one--b&viewMode=story'
);
});
});

describe('if the selection is unchanged', () => {
it('emits STORY_UNCHANGED', async () => {
document.location.search = '?id=component-one--a';
Expand Down
2 changes: 1 addition & 1 deletion lib/preview-web/src/PreviewWeb.tsx
Expand Up @@ -200,7 +200,7 @@ export class PreviewWeb<TFramework extends AnyFramework> extends Preview<TFramew
}

onSetCurrentStory(selection: Selection) {
this.urlStore.setSelection(selection);
this.urlStore.setSelection({ viewMode: 'story', ...selection });
this.channel.emit(CURRENT_STORY_WAS_SET, this.urlStore.selection);
this.renderSelection();
}
Expand Down

0 comments on commit b689333

Please sign in to comment.