-
Notifications
You must be signed in to change notification settings - Fork 9
Add comprehensive Storybook stories for authentication components with Storybook 9 compatibility #168
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
Draft
Copilot
wants to merge
15
commits into
main
Choose a base branch
from
copilot/fix-167
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Add comprehensive Storybook stories for authentication components with Storybook 9 compatibility #168
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
769739c
Initial plan
Copilot 9927d3f
Implement comprehensive Storybook stories for authentication components
Copilot e1e3bde
format: Apply prettier --fix changes
Copilot 8a85ba8
Remove isolated components and use real auth components with mocked sβ¦
Copilot b173cba
Fix CICD error: Remove direct Firebase hook mocking from auth stories
Copilot 6c0ff0b
Fix build error: Replace @storybook/test with vitest mocking for Storβ¦
Copilot 34cd28e
fix: Resolve Vercel build errors and improve Storybook 9 compatibility
snomiao 2fb0990
format: Apply prettier --fix changes
snomiao 556b247
Merge remote-tracking branch 'origin/main' into copilot/fix-167
snomiao b0e441f
refactor: Relocate auth stories to components directory following newβ¦
snomiao 1b1cd5a
format: Apply prettier --fix changes
snomiao 835e438
Merge branch 'main' into copilot/fix-167
snomiao 4eb7839
fix: Ensure Storybook uses /_storybook/ prefix for all asset paths
snomiao 4357eb7
format: Apply prettier --fix changes
snomiao 986b630
refactor: Remove fix-storybook-paths.ts and use Vite base config
snomiao 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 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,91 @@ | ||
| import { Meta, StoryObj } from '@storybook/nextjs-vite' | ||
| import { HttpResponse, http } from 'msw' | ||
| import AuthUI from '@/components/AuthUI/AuthUI' | ||
| import { User } from '@/src/api/generated' | ||
| import { | ||
| mockFirebaseUser, | ||
| useFirebaseUser, | ||
| } from '@/src/hooks/useFirebaseUser.mock' | ||
| import { CAPI } from '@/src/mocks/apibase' | ||
| import { handlers } from '@/src/mocks/handlers' | ||
|
|
||
| const meta = { | ||
| title: 'Components/AuthUI/SignIn', | ||
| component: AuthUI, | ||
| parameters: { | ||
| layout: 'fullscreen', | ||
| backgrounds: { default: 'dark' }, | ||
| msw: { | ||
| handlers: handlers, | ||
| }, | ||
| }, | ||
| decorators: [ | ||
| (Story) => ( | ||
| <div className="bg-gray-900 min-h-screen"> | ||
| <Story /> | ||
| </div> | ||
| ), | ||
| ], | ||
| } satisfies Meta<typeof AuthUI> | ||
|
|
||
| export default meta | ||
|
|
||
| type Story = StoryObj<typeof meta> | ||
|
|
||
| // Mock user data | ||
| const mockUser: User = { | ||
| id: 'user-123', | ||
| name: 'John Doe', | ||
| email: '[email protected]', | ||
| isAdmin: false, | ||
| isApproved: true, | ||
| } | ||
|
|
||
| export const Default: Story = { | ||
| parameters: { | ||
| msw: { | ||
| handlers: [ | ||
| http.get(CAPI('/users'), () => | ||
| HttpResponse.json(null, { status: 401 }) | ||
| ), | ||
| ...handlers, | ||
| ], | ||
| }, | ||
| }, | ||
| async beforeEach() { | ||
| // Mock Firebase user as logged out | ||
| useFirebaseUser.mockReturnValue([null, false, undefined]) | ||
| }, | ||
| } | ||
|
|
||
| export const Loading: Story = { | ||
| parameters: { | ||
| msw: { | ||
| handlers: [ | ||
| http.get(CAPI('/users'), () => | ||
| HttpResponse.json(null, { status: 401 }) | ||
| ), | ||
| ...handlers, | ||
| ], | ||
| }, | ||
| }, | ||
| async beforeEach() { | ||
| // Mock Firebase user as loading | ||
| useFirebaseUser.mockReturnValue([null, true, undefined]) | ||
| }, | ||
| } | ||
|
|
||
| export const AlreadyLoggedIn: Story = { | ||
| parameters: { | ||
| msw: { | ||
| handlers: [ | ||
| http.get(CAPI('/users'), () => HttpResponse.json(mockUser)), | ||
| ...handlers, | ||
| ], | ||
| }, | ||
| }, | ||
| async beforeEach() { | ||
| // Mock Firebase user as logged in | ||
| useFirebaseUser.mockReturnValue([mockFirebaseUser, false, undefined]) | ||
| }, | ||
| } |
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,74 @@ | ||
| import { Meta, StoryObj } from '@storybook/nextjs-vite' | ||
| import { HttpResponse, http } from 'msw' | ||
| import Logout from '@/components/AuthUI/Logout' | ||
| import { User } from '@/src/api/generated' | ||
| import { | ||
| mockFirebaseUser, | ||
| useFirebaseUser, | ||
| } from '@/src/hooks/useFirebaseUser.mock' | ||
| import { CAPI } from '@/src/mocks/apibase' | ||
| import { handlers } from '@/src/mocks/handlers' | ||
|
|
||
| const meta = { | ||
| title: 'Components/AuthUI/Logout', | ||
| component: Logout, | ||
| parameters: { | ||
| layout: 'fullscreen', | ||
| backgrounds: { default: 'dark' }, | ||
| msw: { | ||
| handlers: handlers, | ||
| }, | ||
| }, | ||
| decorators: [ | ||
| (Story) => ( | ||
| <div className="bg-gray-900 min-h-screen"> | ||
| <Story /> | ||
| </div> | ||
| ), | ||
| ], | ||
| } satisfies Meta<typeof Logout> | ||
|
|
||
| export default meta | ||
|
|
||
| type Story = StoryObj<typeof meta> | ||
|
|
||
| // Mock user data | ||
| const mockUser: User = { | ||
| id: 'user-123', | ||
| name: 'John Doe', | ||
| email: '[email protected]', | ||
| isAdmin: false, | ||
| isApproved: true, | ||
| } | ||
|
|
||
| export const Default: Story = { | ||
| parameters: { | ||
| msw: { | ||
| handlers: [ | ||
| http.get(CAPI('/users'), () => HttpResponse.json(mockUser)), | ||
| ...handlers, | ||
| ], | ||
| }, | ||
| }, | ||
| async beforeEach() { | ||
| // Mock Firebase user as logged in | ||
| useFirebaseUser.mockReturnValue([mockFirebaseUser, false, undefined]) | ||
| }, | ||
| } | ||
|
|
||
| export const LoggedOut: Story = { | ||
| parameters: { | ||
| msw: { | ||
| handlers: [ | ||
| http.get(CAPI('/users'), () => | ||
| HttpResponse.json(null, { status: 401 }) | ||
| ), | ||
| ...handlers, | ||
| ], | ||
| }, | ||
| }, | ||
| async beforeEach() { | ||
| // Mock Firebase user as logged out | ||
| useFirebaseUser.mockReturnValue([null, false, undefined]) | ||
| }, | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { vi } from 'vitest' | ||
|
|
||
| // Mock the Firebase auth hooks for Storybook | ||
| export const useSignInWithGoogle = vi.fn().mockName('useSignInWithGoogle') | ||
| export const useSignInWithGithub = vi.fn().mockName('useSignInWithGithub') | ||
| export const useSignOut = vi.fn().mockName('useSignOut') | ||
| export const useAuthState = vi.fn().mockName('useAuthState') | ||
|
|
||
| // Set default return values | ||
| useSignInWithGoogle.mockReturnValue([vi.fn(), undefined, false, undefined]) | ||
| useSignInWithGithub.mockReturnValue([vi.fn(), undefined, false, undefined]) | ||
| useSignOut.mockReturnValue([vi.fn(), false, undefined]) | ||
| useAuthState.mockReturnValue([null, false, undefined]) | ||
|
|
||
| console.log('mocking react-firebase-hooks/auth', { | ||
| useSignInWithGoogle, | ||
| useSignInWithGithub, | ||
| useSignOut, | ||
| useAuthState, | ||
| }) |
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,68 @@ | ||
| #!/usr/bin/env bun | ||
|
||
| /** | ||
| * Fix Storybook paths to use /_storybook/ prefix | ||
| * This script updates index.html and iframe.html to use absolute paths | ||
| * so Storybook works correctly when deployed under /_storybook/ subdirectory | ||
| */ | ||
|
|
||
| import { readFileSync, writeFileSync } from 'fs' | ||
| import { join } from 'path' | ||
|
|
||
| const STORYBOOK_DIR = 'public/_storybook' | ||
| const BASE_PATH = '/_storybook/' | ||
|
|
||
| function fixPaths(filePath: string) { | ||
| console.log(`Fixing paths in ${filePath}...`) | ||
|
|
||
| let content = readFileSync(filePath, 'utf-8') | ||
|
|
||
| // Replace all relative paths with absolute paths using /_storybook/ prefix | ||
| // Match patterns like: href="./something" or src="./something" or import './something' | ||
| content = content.replace( | ||
| /(['"])\.\/([^'"]+)(['"])/g, | ||
| (match, quote1, path, quote2) => { | ||
| // Don't modify if it's already absolute | ||
| if (path.startsWith('/') || path.startsWith('http')) { | ||
| return match | ||
| } | ||
| return `${quote1}${BASE_PATH}${path}${quote2}` | ||
| } | ||
| ) | ||
|
|
||
| // Also fix absolute paths that should be under /_storybook/ | ||
| // Match patterns like: src="/vite-inject-mocker-entry.js" | ||
| content = content.replace( | ||
| /(['"])\/([^'"\/][^'"]*\.(?:js|css|json|svg|png|jpg|jpeg|gif|woff|woff2))(['"])/g, | ||
| (match, quote1, path, quote2) => { | ||
| // Skip if it's already under /_storybook/ or is an external URL | ||
| if ( | ||
| path.startsWith('_storybook/') || | ||
| path.startsWith('http') || | ||
| path.startsWith('//') | ||
| ) { | ||
| return match | ||
| } | ||
| return `${quote1}${BASE_PATH}${path}${quote2}` | ||
| } | ||
| ) | ||
|
|
||
| writeFileSync(filePath, content, 'utf-8') | ||
| console.log(`β Fixed ${filePath}`) | ||
| } | ||
|
|
||
| // Fix both index.html (manager UI) and iframe.html (preview frame) | ||
| const filesToFix = [ | ||
| join(process.cwd(), STORYBOOK_DIR, 'index.html'), | ||
| join(process.cwd(), STORYBOOK_DIR, 'iframe.html'), | ||
| ] | ||
|
|
||
| for (const file of filesToFix) { | ||
| try { | ||
| fixPaths(file) | ||
| } catch (error) { | ||
| console.error(`Error fixing ${file}:`, error) | ||
| process.exit(1) | ||
| } | ||
| } | ||
|
|
||
| console.log('\nβ All Storybook paths fixed successfully!') | ||
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.
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.
can you dont use this script? it can be done within .storybook configurations