-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Core: Normalize parameters in store/channel #10373
Merged
Merged
Changes from 11 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
9ae73c7
Store parameters in the store in a normalized way
tmeasday e92b44e
Merge remote-tracking branch 'origin/next' into 10361-normalize-param…
tmeasday 7307b76
Fix bad merge
tmeasday 7adf8c0
Fix story sort tests
tmeasday 4a87d5a
Combine parameters in `fromId()`
tmeasday 198a601
We'll always define `parameters.argTypes`
tmeasday 603dfc5
Normalize parameters in the `SET_STORIES` event
tmeasday bd9dd9f
Rename `SET_STORIES` to `SET_STORY_STORE_DATA`
tmeasday 9b91f38
Pick up in the manager
tmeasday 01867f9
Duplicate types and combineParameters
tmeasday 1bdd48b
Bugfix
tmeasday febec0f
Merge branch 'next' into 10361-normalize-parameters
ndelangen cb28194
ADD rest data to ref
ndelangen 63682a2
Explicitly don't allow setting storySort any other way
tmeasday c0cdd3f
Export `combineParameters` and document in migrations
tmeasday de6d52e
Remove spurious log
tmeasday 0c6cbd6
Revert "Rename `SET_STORIES` to `SET_STORY_STORE_DATA`"
tmeasday fecf1d9
More spurious logs
tmeasday 385fe81
Update to use a single SET_STORIES event
tmeasday afdfd04
Merge branch 'next' into 10361-normalize-parameters
shilman 12a2853
Fix typo
shilman 884bb15
SET_STORY_STORE_DATA => SET_STORIES
shilman 27fadc6
Normalized parameters: Fix failing test
shilman 8390c62
Fix inclusion logic
shilman 03425f6
Fix deepscan
shilman c0f8fb2
Merge branch 'next' into 10361-normalize-parameters
shilman 241d06c
Ensure we set `parameters.argTypes` in the preview
tmeasday a1b9372
Fix failing tests
shilman e2d54f6
Update snapshots
shilman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
import EventEmitter from 'event-emitter'; | ||
import { STORY_ARGS_UPDATED, UPDATE_STORY_ARGS } from '@storybook/core-events'; | ||
import { | ||
STORY_ARGS_UPDATED, | ||
UPDATE_STORY_ARGS, | ||
SET_STORY_STORE_DATA, | ||
LEGACY_SET_STORIES, | ||
} from '@storybook/core-events'; | ||
|
||
import { init as initStories } from '../modules/stories'; | ||
|
||
|
@@ -791,4 +796,118 @@ describe('stories API', () => { | |
}); | ||
}); | ||
}); | ||
describe('SET_STORY_STORE_DATA event', () => { | ||
it('normalizes parameters and calls setStories for local stories', () => { | ||
const fullAPI = { on: jest.fn(), setStories: jest.fn(), setOptions: jest.fn() }; | ||
const navigate = jest.fn(); | ||
const store = createMockStore(); | ||
|
||
const { init } = initStories({ store, navigate, provider, fullAPI }); | ||
init(); | ||
|
||
const onSetStoryStoreData = fullAPI.on.mock.calls.find( | ||
([event]) => event === SET_STORY_STORE_DATA | ||
)[1]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a better way to do this for tests @ndelangen? |
||
|
||
const storyStoreData = { | ||
globalParameters: { global: 'global' }, | ||
kindParameters: { a: { kind: 'kind' } }, | ||
stories: { 'a--1': { kind: 'a', parameters: { story: 'story' } } }, | ||
}; | ||
onSetStoryStoreData.call({ source: 'http://localhost' }, storyStoreData); | ||
|
||
expect(fullAPI.setStories).toHaveBeenCalledWith({ | ||
'a--1': { kind: 'a', parameters: { global: 'global', kind: 'kind', story: 'story' } }, | ||
}); | ||
}); | ||
|
||
it('normalizes parameters and calls setRef for external stories', () => { | ||
const fullAPI = { | ||
on: jest.fn(), | ||
findRef: jest.fn().mockReturnValue({ id: 'ref' }), | ||
setRef: jest.fn(), | ||
}; | ||
const navigate = jest.fn(); | ||
const store = createMockStore(); | ||
|
||
const { init } = initStories({ store, navigate, provider, fullAPI }); | ||
init(); | ||
|
||
const onSetStoryStoreData = fullAPI.on.mock.calls.find( | ||
([event]) => event === SET_STORY_STORE_DATA | ||
)[1]; | ||
|
||
const storyStoreData = { | ||
globalParameters: { global: 'global' }, | ||
kindParameters: { a: { kind: 'kind' } }, | ||
stories: { 'a--1': { kind: 'a', parameters: { story: 'story' } } }, | ||
}; | ||
onSetStoryStoreData.call({ source: 'http://external' }, storyStoreData); | ||
|
||
expect(fullAPI.setRef).toHaveBeenCalledWith( | ||
'ref', | ||
{ | ||
id: 'ref', | ||
stories: { | ||
'a--1': { kind: 'a', parameters: { global: 'global', kind: 'kind', story: 'story' } }, | ||
}, | ||
}, | ||
true | ||
); | ||
}); | ||
|
||
it('calls setOptions with global options parameters', () => { | ||
const fullAPI = { on: jest.fn(), setStories: jest.fn(), setOptions: jest.fn() }; | ||
const navigate = jest.fn(); | ||
const store = createMockStore(); | ||
|
||
const { init } = initStories({ store, navigate, provider, fullAPI }); | ||
init(); | ||
|
||
const onSetStoryStoreData = fullAPI.on.mock.calls.find( | ||
([event]) => event === SET_STORY_STORE_DATA | ||
)[1]; | ||
|
||
const storyStoreData = { | ||
globalParameters: { options: 'options' }, | ||
kindParameters: { a: { options: 'should-be-ignored' } }, | ||
stories: { 'a--1': { kind: 'a', parameters: { options: 'should-be-ignored-also' } } }, | ||
}; | ||
onSetStoryStoreData.call({ source: 'http://localhost' }, storyStoreData); | ||
|
||
expect(fullAPI.setOptions).toHaveBeenCalledWith('options'); | ||
}); | ||
}); | ||
describe('LEGACY_SET_STORIES event', () => { | ||
it('calls setRef with stories', () => { | ||
const fullAPI = { | ||
on: jest.fn(), | ||
findRef: jest.fn().mockReturnValue({ id: 'ref' }), | ||
setRef: jest.fn(), | ||
}; | ||
const navigate = jest.fn(); | ||
const store = createMockStore(); | ||
|
||
const { init } = initStories({ store, navigate, provider, fullAPI }); | ||
init(); | ||
|
||
const onSetStories = fullAPI.on.mock.calls.find(([event]) => event === LEGACY_SET_STORIES)[1]; | ||
|
||
const storiesData = { | ||
stories: { 'a--1': {} }, | ||
}; | ||
onSetStories.call({ source: 'http://external' }, storiesData); | ||
|
||
expect(fullAPI.setRef).toHaveBeenCalledWith( | ||
'ref', | ||
{ | ||
id: 'ref', | ||
stories: { | ||
'a--1': {}, | ||
}, | ||
}, | ||
true | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we were using
SET_STORIES
instead ofSET_STORY_STORE_DATA
? Looks like it only got partially reverted?