-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Core: Track vision simulator state through globals and apply styles in preview #33418
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fbb8802
Synchronize vision simulator state with globals and apply vision filt…
ghengeveld 8bf98c1
Ensure error display is not affected by vision filter, and add stories
ghengeveld 74f7123
Fix import
ghengeveld db0548d
Drop unit tests in favor of story with play function assertions
ghengeveld 3830aed
Avoid splitting filter string, which may not work properly
ghengeveld 30b5a03
Merge branch 'next' into vision-simulator-global
ghengeveld b7a6c6a
Add Jest DOM types reference in A11YPanel test file
ghengeveld e3601ea
Remove invalid closing semicolon from triple-slash directives
ghengeveld 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 hidden or 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 was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
code/addons/a11y/src/components/VisionSimulator.stories.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import type { PlayFunction, PlayFunctionContext } from 'storybook/internal/types'; | ||
|
|
||
| import { ManagerContext } from 'storybook/manager-api'; | ||
| import { expect, fn, screen } from 'storybook/test'; | ||
|
|
||
| import preview from '../../../../.storybook/preview'; | ||
| import { VisionSimulator } from './VisionSimulator'; | ||
|
|
||
| const managerContext: any = { | ||
| state: {}, | ||
| api: { | ||
| getGlobals: fn(() => ({ vision: undefined })), | ||
| updateGlobals: fn(), | ||
| getStoryGlobals: fn(() => ({ vision: undefined })), | ||
| getUserGlobals: fn(() => ({ vision: undefined })), | ||
| }, | ||
| }; | ||
|
|
||
| const meta = preview.meta({ | ||
| title: 'Vision Simulator', | ||
| component: VisionSimulator, | ||
| decorators: [ | ||
| (Story: any) => ( | ||
| <ManagerContext.Provider value={managerContext}> | ||
| <Story /> | ||
| </ManagerContext.Provider> | ||
| ), | ||
| ], | ||
| }); | ||
|
|
||
| export default meta; | ||
|
|
||
| const openMenu: PlayFunction = async ({ canvas, userEvent }) => { | ||
| await userEvent.click(canvas.getByRole('button', { name: 'Vision simulator' })); | ||
| }; | ||
|
|
||
| export const Default = meta.story({ | ||
| play: openMenu, | ||
| }); | ||
|
|
||
| export const WithFilter = meta.story({ | ||
| play: openMenu, | ||
| globals: { | ||
| vision: 'achromatopsia', | ||
| }, | ||
| }); | ||
|
|
||
| export const Selection = meta.story({ | ||
| play: async (context) => { | ||
| await openMenu(context); | ||
| await context.userEvent.click(await screen.findByText('Blurred vision')); | ||
| await expect(managerContext.api.updateGlobals).toHaveBeenCalledWith({ vision: 'blurred' }); | ||
| await expect( | ||
| context.canvas.getByRole('button', { name: 'Vision simulator Blurred vision' }) | ||
| ).toBeVisible(); | ||
| }, | ||
| }); |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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.
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.
Verify the filter key exists before accessing.
The code assumes the filter key exists in the
filtersobject, but if$filteris invalid, this could throw at runtime.🔎 Proposed defensive fix
({ $filter }) => ({ - filter: filters[$filter as keyof typeof filters].filter || 'none', + filter: filters[$filter as keyof typeof filters]?.filter || 'none', }),📝 Committable suggestion
🤖 Prompt for AI Agents