Conversation
…where unnecessary - Changed play functions in various Storybook stories from async to synchronous where applicable. - Updated imports for MockAuthWrapper to a new file for better organization. - Removed unused MockAuthWrapper and MockUnauthWrapper implementations from storybook-decorators.tsx for it mixes exporting constants and components
4 tasks
Contributor
Reviewer's GuideRefactors Storybook test infrastructure by centralizing mock auth wrappers and environment/storage setup into shared utilities, adds reusable GraphQL mock builders for App stories, and updates many Storybook stories to use the new shared decorators and helpers while making minor consistency/typing tweaks to play functions and props. Sequence diagram for AppContainer story with centralized GraphQL mockssequenceDiagram
participant SB as StorybookRunner
participant ST as AppContainerStory
participant WMAC as withMockApolloClient
participant AP as ApolloProvider
participant AC as ApolloClient(MockLink)
participant C as AppContainer
SB->>ST: Load AuthenticatedCompletedOnboarding story
ST->>WMAC: Apply decorator with mocks
WMAC->>AP: Wrap Story with ApolloProvider
AP->>AC: Initialize client with mocks
SB->>C: Render AppContainer inside providers
C->>AC: Query AppContainerCurrentUserDocument
AC-->>C: Mock response from buildCurrentUserMock
C->>AC: Query ListingsPageContainerGetListingsDocument
AC-->>C: Mock response from buildListingsMock
C->>AC: Query UseUserIsAdminDocument
AC-->>C: Mock response from buildUseUserIsAdminMock
C-->>SB: Render UI for authenticated user with listings
Class diagram for shared Storybook test utilities and helpersclassDiagram
class StorybookDecorators {
+withAuthDecorator(storyFn) JSXElement
+withMockApolloClient(storyFn, mocks) JSXElement
+withMockRouter(initialPath) Decorator
}
class StorybookMockAuthWrappers {
+MockAuthWrapper~FC~
+MockUnauthWrapper~FC~
}
class AppContainerStoriesHelpers {
+buildCurrentUserMock(id, hasCompletedOnboarding) ApolloMock
+buildListingsMock(listings) ApolloMock
+buildUseUserIsAdminMock(isAdmin) ApolloMock
}
class ApolloMock {
+request QueryRequest
+result QueryResult
}
class QueryRequest {
+query DocumentNode
+variables any
}
class QueryResult {
+data any
}
StorybookDecorators --> StorybookMockAuthWrappers : uses
StorybookDecorators --> ApolloMock : configures
AppContainerStoriesHelpers --> ApolloMock : builds
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The Storybook env/storage mocking in
storybook-decorators.tsxnow mutatesglobalThis.sessionStorage,globalThis.localStorage, andimport.meta.envat module load; consider moving these side effects into a dedicated Storybook setup (e.g., preview file) or behind a guard so simply importing the decorators in non-Storybook code doesn’t unexpectedly alter global state. - The
mockStorageimplementation is used both aswindow.localStorage/sessionStorageand as auserStoreforAuthProvider, mixing sync (DOM Storage) and async (oidc userStore) style APIs; it may be worth clearly separating these concerns or adding comments to avoid accidental reuse of this object in a context that expects only one of the interfaces.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The Storybook env/storage mocking in `storybook-decorators.tsx` now mutates `globalThis.sessionStorage`, `globalThis.localStorage`, and `import.meta.env` at module load; consider moving these side effects into a dedicated Storybook setup (e.g., preview file) or behind a guard so simply importing the decorators in non-Storybook code doesn’t unexpectedly alter global state.
- The `mockStorage` implementation is used both as `window.localStorage`/`sessionStorage` and as a `userStore` for `AuthProvider`, mixing sync (DOM Storage) and async (oidc userStore) style APIs; it may be worth clearly separating these concerns or adding comments to avoid accidental reuse of this object in a context that expects only one of the interfaces.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…cated-generatemocktoken-helper-into-shared-teststory-utility
…ed test consistency
… routing and user ID handling
… login selection stories
apps/ui-sharethrift/src/components/layouts/app/pages/home/components/listings-page.stories.tsx
Fixed
Show fixed
Hide fixed
apps/ui-sharethrift/src/components/layouts/app/pages/home/components/listings-page.stories.tsx
Fixed
Show fixed
Hide fixed
apps/ui-sharethrift/src/components/layouts/app/pages/home/components/listings-page.stories.tsx
Fixed
Show fixed
Hide fixed
…cated-generatemocktoken-helper-into-shared-teststory-utility
…cated-generatemocktoken-helper-into-shared-teststory-utility
…cated-generatemocktoken-helper-into-shared-teststory-utility
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary by Sourcery
Extract shared Storybook authentication and environment mocking into reusable utilities and standardize their usage across UI stories.
Enhancements:
Tests: