Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the denormed params on the first story for initial options #11938

Merged
merged 1 commit into from Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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