From fb69b13e94b8d48b2cad7e7f5d50dec51ea7a097 Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Wed, 12 Aug 2020 23:18:16 +1000 Subject: [PATCH] Use the denormed params on the first story for initial options Fixes #11892 --- lib/api/src/modules/stories.ts | 2 +- lib/api/src/tests/stories.test.js | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/api/src/modules/stories.ts b/lib/api/src/modules/stories.ts index 38a65ca406b2..0dcad6daee15 100644 --- a/lib/api/src/modules/stories.ts +++ b/lib/api/src/modules/stories.ts @@ -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 { diff --git a/lib/api/src/tests/stories.test.js b/lib/api/src/tests/stories.test.js index f182c3d7b549..ab59a9ee6ede 100644 --- a/lib/api/src/tests/stories.test.js +++ b/lib/api/src/tests/stories.test.js @@ -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(); @@ -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);