-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add stories for header and footer (#368)
- Loading branch information
1 parent
33df453
commit 72d381f
Showing
7 changed files
with
154 additions
and
36 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import Footer from "./Footer"; | ||
|
||
const meta: Meta<typeof Footer> = { | ||
title: "Components/Layout/Footer", | ||
component: Footer, | ||
tags: ["autodocs"], | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Footer>; | ||
|
||
export const Default: Story = { | ||
args: {}, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import Header from "./Header"; | ||
|
||
const meta: Meta<typeof Header> = { | ||
title: "Components/Layout/Header", | ||
component: Header, | ||
tags: ["autodocs"], | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Header>; | ||
|
||
export const SignedIn: Story = { | ||
args: {}, | ||
parameters: { | ||
auth: "signedIn", | ||
}, | ||
}; | ||
|
||
export const SignedOut: Story = { | ||
args: {}, | ||
parameters: { | ||
auth: "signedOut", | ||
}, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { Decorator } from "@storybook/react/*"; | ||
|
||
import { ClerkProvider } from "./nextjsComponents"; | ||
|
||
export const ClerkDecorator: Decorator = (Story, { parameters }) => { | ||
return ( | ||
<ClerkProvider state={parameters.auth ?? "signedIn"}> | ||
<Story /> | ||
</ClerkProvider> | ||
); | ||
}; |
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,43 +1,115 @@ | ||
import React from "react"; | ||
|
||
type Context = { | ||
isLoaded: boolean; | ||
isSignedIn: boolean | undefined; | ||
user: | ||
| Record< | ||
"id" | "firstName" | "lastName" | "emailAddresses" | "publicMetadata", | ||
unknown | ||
> | ||
| undefined; | ||
}; | ||
|
||
const mockUser = { | ||
id: "user_123", | ||
firstName: "John", | ||
lastName: "Doe", | ||
emailAddresses: [{ emailAddress: "[email protected]" }], | ||
publicMetadata: { labs: { isDemoUser: true } }, | ||
publicMetadata: { labs: { isDemoUser: false } }, | ||
// Add other user properties as needed | ||
}; | ||
|
||
export const useUser = () => ({ | ||
isLoaded: true, | ||
isSignedIn: true, | ||
user: mockUser, | ||
}); | ||
const states: Record<ClerkProviderProps["state"], Context> = { | ||
loading: { | ||
isLoaded: false, | ||
isSignedIn: undefined, | ||
user: undefined, | ||
}, | ||
signedOut: { | ||
isLoaded: true, | ||
isSignedIn: false, | ||
user: undefined, | ||
}, | ||
signedIn: { | ||
isLoaded: true, | ||
isSignedIn: true, | ||
user: mockUser, | ||
}, | ||
signedInDemo: { | ||
isLoaded: true, | ||
isSignedIn: true, | ||
user: { | ||
...mockUser, | ||
publicMetadata: { ...mockUser.publicMetadata, isDemoUser: true }, | ||
}, | ||
}, | ||
}; | ||
|
||
const ClerkContext = React.createContext<Context>(states.signedIn); | ||
|
||
type ClerkProviderProps = { | ||
state: "loading" | "signedIn" | "signedInDemo" | "signedOut"; | ||
children: React.ReactNode; | ||
}; | ||
export const ClerkProvider = ({ state, children }: ClerkProviderProps) => ( | ||
<ClerkContext.Provider value={states[state]}> | ||
{children} | ||
</ClerkContext.Provider> | ||
); | ||
|
||
export const useUser = () => { | ||
const context = React.useContext(ClerkContext); | ||
return { | ||
isLoaded: context.isLoaded, | ||
isSignedIn: context.isSignedIn, | ||
user: context.user, | ||
}; | ||
}; | ||
|
||
export const useClerk = () => ({ | ||
signOut: () => Promise.resolve(), | ||
signIn: () => Promise.resolve(), | ||
// Add other Clerk methods as needed | ||
}); | ||
|
||
export const useAuth = () => ({ | ||
isLoaded: true, | ||
isSignedIn: true, | ||
userId: mockUser.id, | ||
sessionId: "session_123", | ||
getToken: () => Promise.resolve("mock_token"), | ||
}); | ||
export const useAuth = () => { | ||
const context = React.useContext(ClerkContext); | ||
return { | ||
isLoaded: context.isLoaded, | ||
isSignedIn: context.isSignedIn, | ||
userId: mockUser?.id, | ||
sessionId: "session_123", | ||
getToken: () => Promise.resolve("mock_token"), | ||
}; | ||
}; | ||
|
||
export const SignedIn = ({ children }: { children: React.ReactNode }) => ( | ||
<>{children}</> | ||
); | ||
export const SignedOut = ({ children }: { children: React.ReactNode }) => ( | ||
<>{children}</> | ||
); | ||
export const SignedIn = ({ children }: { children: React.ReactNode }) => { | ||
const context = React.useContext(ClerkContext); | ||
return context.isSignedIn ? children : null; | ||
}; | ||
|
||
export const ClerkProvider = ({ children }: { children: React.ReactNode }) => ( | ||
<>{children}</> | ||
); | ||
export const SignedOut = ({ children }: { children: React.ReactNode }) => { | ||
const context = React.useContext(ClerkContext); | ||
return context.isSignedIn ? null : children; | ||
}; | ||
|
||
export const UserButton = () => { | ||
const context = React.useContext(ClerkContext); | ||
|
||
return context.isSignedIn ? ( | ||
<div | ||
style={{ | ||
display: "block", | ||
height: "28px", | ||
width: "28px", | ||
background: "yellowgreen", | ||
borderRadius: "50%", | ||
}} | ||
/> | ||
) : ( | ||
"Sign in" | ||
); | ||
}; | ||
|
||
// Mock other Clerk components and hooks as needed |