Skip to content

Commit

Permalink
Use the denormed params on the first story for initial options
Browse files Browse the repository at this point in the history
Fixes #11892
  • Loading branch information
tmeasday committed Aug 12, 2020
1 parent ac0b690 commit fb69b13
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 fb69b13

Please sign in to comment.