Skip to content

Commit

Permalink
Merge pull request #11938 from storybookjs/11924-initial-options
Browse files Browse the repository at this point in the history
Use the denormed params on the first story for initial options
  • Loading branch information
shilman committed Sep 26, 2020
1 parent f4a5238 commit 1ca8a98
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/api/src/modules/stories.ts
Expand Up @@ -375,7 +375,7 @@ export const init: ModuleFn = ({
}

fullAPI.setStories(stories, error);
const { options } = data.globalParameters;
const options = fullAPI.getCurrentParameter('options');
checkDeprecatedOptionParameters(options);
fullAPI.setOptions(options);
} else {
Expand Down
13 changes: 8 additions & 5 deletions lib/api/src/tests/stories.test.js
Expand Up @@ -806,6 +806,7 @@ describe('stories API', () => {
setStories: jest.fn(),
setOptions: jest.fn(),
findRef: jest.fn(),
getCurrentParameter: jest.fn(),
});
const navigate = jest.fn();
const store = createMockStore();
Expand Down Expand Up @@ -866,23 +867,25 @@ describe('stories API', () => {
);
});

it('calls setOptions with global options parameters', () => {
it('calls setOptions w/ first story parameter', () => {
const fullAPI = Object.assign(new EventEmitter(), {
setStories: jest.fn(),
setOptions: jest.fn(),
findRef: jest.fn(),
getCurrentParameter: jest.fn().mockReturnValue('options'),
});
const navigate = jest.fn();
const store = createMockStore();

const { init } = initStories({ store, navigate, provider, fullAPI });
const { init, api } = initStories({ store, navigate, provider, fullAPI });
init();

store.setState({});
const setStoriesPayload = {
v: 2,
globalParameters: { options: 'options' },
kindParameters: { a: { options: 'should-be-ignored' } },
stories: { 'a--1': { kind: 'a', parameters: { options: 'should-be-ignored-also' } } },
globalParameters: {},
kindParameters: { a: {} },
stories: { 'a--1': { kind: 'a' } },
};
fullAPI.emit(SET_STORIES, setStoriesPayload);

Expand Down

0 comments on commit 1ca8a98

Please sign in to comment.