Clean up tests for changing preparing state

This commit is contained in:
Tom Coleman 2021-11-11 21:51:18 +11:00
parent 2f1a732da0
commit 200d4fe552

View File

@ -1248,7 +1248,7 @@ describe('PreviewWeb', () => {
});
await waitForSetCurrentStory();
expect(preview.view.showPreparing).toHaveBeenCalled();
expect(preview.view.showPreparingStory).toHaveBeenCalled();
});
it('emits STORY_CHANGED', async () => {
@ -1662,6 +1662,19 @@ describe('PreviewWeb', () => {
);
});
it('renders preparing state', async () => {
document.location.search = '?id=component-one--a';
const preview = await createAndRenderPreview();
emitter.emit(Events.SET_CURRENT_STORY, {
storyId: 'component-one--a',
viewMode: 'docs',
});
await waitForSetCurrentStory();
expect(preview.view.showPreparingDocs).toHaveBeenCalled();
});
it('emits STORY_CHANGED', async () => {
document.location.search = '?id=component-one--a';
await createAndRenderPreview();
@ -2315,6 +2328,18 @@ describe('PreviewWeb', () => {
expect(mockChannel.emit).not.toHaveBeenCalledWith(Events.STORY_CHANGED, 'component-one--a');
});
it('clears preparing state', async () => {
document.location.search = '?id=component-one--a';
const preview = await createAndRenderPreview();
(preview.view.showMain as jest.Mock).mockClear();
mockChannel.emit.mockClear();
preview.onStoriesChanged({ importFn: newImportFn });
await waitForEvents([Events.STORY_UNCHANGED]);
expect(preview.view.showMain).toHaveBeenCalled();
});
it('does not re-render the story', async () => {
document.location.search = '?id=component-one--a';
const preview = await createAndRenderPreview();