Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen committed Apr 8, 2022
1 parent acb4303 commit c01880d
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions lib/api/src/modules/stories.ts
Expand Up @@ -322,8 +322,11 @@ export const init: ModuleFn = ({
return;
}

// eslint-disable-next-line consistent-return
return lookupList[index + direction][0];
if (lookupList[index + direction]) {
// eslint-disable-next-line consistent-return
return lookupList[index + direction][0];
}
return;
}
const lookupList = getStoriesLookupList(hash);
const index = lookupList.indexOf(storyId);
Expand Down Expand Up @@ -455,8 +458,20 @@ export const init: ModuleFn = ({
}
});

fullAPI.on(STORY_PREPARED, function handler() {
const { sourceType } = getEventMetadata(this, fullAPI);
fullAPI.on(STORY_PREPARED, function handler({ id, ...update }) {
const { ref, sourceType } = getEventMetadata(this, fullAPI);
fullAPI.updateStory(id, { ...update, prepared: true }, ref);

if (!ref) {
if (!store.getState().hasCalledSetOptions) {
const { options } = update.parameters;
checkDeprecatedOptionParameters(options);
fullAPI.setOptions(options);
store.setState({ hasCalledSetOptions: true });
}
} else {
fullAPI.updateRef(ref.id, { ready: true });
}

if (sourceType === 'local') {
const { storyId, storiesHash } = store.getState();
Expand Down Expand Up @@ -514,22 +529,6 @@ export const init: ModuleFn = ({
}
);

fullAPI.on(STORY_PREPARED, function handler({ id, ...update }) {
const { ref } = getEventMetadata(this, fullAPI);
fullAPI.updateStory(id, { ...update, prepared: true }, ref);

if (!ref) {
if (!store.getState().hasCalledSetOptions) {
const { options } = update.parameters;
checkDeprecatedOptionParameters(options);
fullAPI.setOptions(options);
store.setState({ hasCalledSetOptions: true });
}
} else {
fullAPI.updateRef(ref.id, { ready: true });
}
});

fullAPI.on(
STORY_ARGS_UPDATED,
function handleStoryArgsUpdated({ storyId, args }: { storyId: StoryId; args: Args }) {
Expand Down

0 comments on commit c01880d

Please sign in to comment.