Skip to content

Commit

Permalink
Merge pull request #24866 from storybookjs/norbert/fix-early-setStatus
Browse files Browse the repository at this point in the history
ManagerAPI: Fix setting status without index, crashes storybook
(cherry picked from commit 9c6cc6d)
  • Loading branch information
ndelangen authored and storybook-bot committed Nov 20, 2023
1 parent d1fda5e commit d41ddfb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion code/lib/manager-api/src/modules/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,9 @@ export const init: ModuleFn<SubAPI, SubState> = ({
});

await store.setState({ status: newStatus }, { persistence: 'session' });
await api.setIndex(index);
if (index) {
await api.setIndex(index);
}
},
experimental_setFilter: async (id, filterFunction) => {
const { internal_index: index } = store.getState();
Expand Down
26 changes: 26 additions & 0 deletions code/lib/manager-api/src/tests/stories.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,32 @@ describe('stories API', () => {
}
`);
});
it('skips updating index, if index is unset', async () => {
const moduleArgs = createMockModuleArgs({});
const { api } = initStories(moduleArgs as unknown as ModuleArgs);
const { store } = moduleArgs;

await expect(
api.experimental_updateStatus('a-addon-id', {
'a-story-id': {
status: 'pending',
title: 'an addon title',
description: 'an addon description',
},
})
).resolves.not.toThrow();
expect(store.getState().status).toMatchInlineSnapshot(`
Object {
"a-story-id": Object {
"a-addon-id": Object {
"description": "an addon description",
"status": "pending",
"title": "an addon title",
},
},
}
`);
});
it('updates multiple stories', async () => {
const moduleArgs = createMockModuleArgs({});
const { api } = initStories(moduleArgs as unknown as ModuleArgs);
Expand Down

0 comments on commit d41ddfb

Please sign in to comment.