-
Notifications
You must be signed in to change notification settings - Fork 4
profile link to mobile menu #2063
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
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 |
|---|---|---|
| @@ -1,80 +1,193 @@ | ||
| import { render } from '@testing-library/react'; | ||
| import NavItem from '@/components/navigation/NavItem'; | ||
| import { useViewContext } from '@/components/navigation/ViewContext'; | ||
| import { useAuth } from '@/components/auth/Auth'; | ||
| import { useTitle } from '@/contexts/TitleContext'; | ||
| import { useUnreadNotifications } from '@/hooks/useUnreadNotifications'; | ||
| import { useUnreadIndicator } from '@/hooks/useUnreadIndicator'; | ||
| import { useNotificationsContext } from '@/components/notifications/NotificationsContext'; | ||
| import { isNavItemActive } from '@/components/navigation/isNavItemActive'; | ||
| import { useWaveData } from '@/hooks/useWaveData'; | ||
| import { useWave } from '@/hooks/useWave'; | ||
| import { useRouter, useSearchParams, usePathname } from 'next/navigation'; | ||
|
|
||
| jest.mock('@/components/navigation/ViewContext', () => ({ useViewContext: jest.fn() })); | ||
| jest.mock('@/components/auth/Auth', () => ({ useAuth: jest.fn() })); | ||
| jest.mock('@/contexts/TitleContext', () => ({ useTitle: jest.fn() })); | ||
| jest.mock('@/hooks/useUnreadNotifications', () => ({ useUnreadNotifications: jest.fn() })); | ||
| jest.mock('@/hooks/useUnreadIndicator', () => ({ useUnreadIndicator: jest.fn() })); | ||
| jest.mock('@/components/notifications/NotificationsContext', () => ({ useNotificationsContext: jest.fn() })); | ||
| jest.mock('@/components/navigation/isNavItemActive', () => ({ isNavItemActive: jest.fn() })); | ||
| jest.mock('@/hooks/useWaveData', () => ({ useWaveData: jest.fn() })); | ||
| jest.mock('@/hooks/useWave', () => ({ useWave: jest.fn() })); | ||
| jest.mock('next/navigation', () => ({ | ||
| import { fireEvent, render } from "@testing-library/react"; | ||
| import NavItem from "@/components/navigation/NavItem"; | ||
| import { useViewContext } from "@/components/navigation/ViewContext"; | ||
| import { useAuth } from "@/components/auth/Auth"; | ||
| import { useSeizeConnectContext } from "@/components/auth/SeizeConnectContext"; | ||
| import { useTitle } from "@/contexts/TitleContext"; | ||
| import { useUnreadNotifications } from "@/hooks/useUnreadNotifications"; | ||
| import { useUnreadIndicator } from "@/hooks/useUnreadIndicator"; | ||
| import { useNotificationsContext } from "@/components/notifications/NotificationsContext"; | ||
| import { isNavItemActive } from "@/components/navigation/isNavItemActive"; | ||
| import { useWaveData } from "@/hooks/useWaveData"; | ||
| import { useWave } from "@/hooks/useWave"; | ||
| import { useRouter, useSearchParams, usePathname } from "next/navigation"; | ||
|
|
||
| jest.mock("@/components/navigation/ViewContext", () => ({ | ||
| useViewContext: jest.fn(), | ||
| })); | ||
| jest.mock("@/components/auth/Auth", () => ({ useAuth: jest.fn() })); | ||
| jest.mock("@/components/auth/SeizeConnectContext", () => ({ | ||
| useSeizeConnectContext: jest.fn(), | ||
| })); | ||
| jest.mock("@/contexts/TitleContext", () => ({ useTitle: jest.fn() })); | ||
| jest.mock("@/hooks/useUnreadNotifications", () => ({ | ||
| useUnreadNotifications: jest.fn(), | ||
| })); | ||
| jest.mock("@/hooks/useUnreadIndicator", () => ({ | ||
| useUnreadIndicator: jest.fn(), | ||
| })); | ||
| jest.mock("@/components/notifications/NotificationsContext", () => ({ | ||
| useNotificationsContext: jest.fn(), | ||
| })); | ||
| jest.mock("@/components/navigation/isNavItemActive", () => ({ | ||
| isNavItemActive: jest.fn(), | ||
| })); | ||
| jest.mock("@/hooks/useWaveData", () => ({ useWaveData: jest.fn() })); | ||
| jest.mock("@/hooks/useWave", () => ({ useWave: jest.fn() })); | ||
| jest.mock("next/navigation", () => ({ | ||
| useRouter: jest.fn(), | ||
| useSearchParams: jest.fn(), | ||
| usePathname: jest.fn(), | ||
| })); | ||
|
|
||
| describe('NavItem notifications', () => { | ||
| describe("NavItem notifications", () => { | ||
| const handleNavClick = jest.fn(); | ||
| const seizeConnect = jest.fn(); | ||
| const removeAllDeliveredNotifications = jest.fn(); | ||
| const setTitle = jest.fn(); | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| (useViewContext as jest.Mock).mockReturnValue({ | ||
| activeView: 'home', | ||
| activeView: "home", | ||
| handleNavClick, | ||
| }); | ||
| (useRouter as jest.Mock).mockReturnValue({ push: jest.fn() }); | ||
| (useSearchParams as jest.Mock).mockReturnValue(new URLSearchParams()); | ||
| (usePathname as jest.Mock).mockReturnValue('/'); | ||
| (usePathname as jest.Mock).mockReturnValue("/"); | ||
| (isNavItemActive as jest.Mock).mockReturnValue(false); | ||
| (useUnreadIndicator as jest.Mock).mockReturnValue({ hasUnread: false }); | ||
| (useNotificationsContext as jest.Mock).mockReturnValue({ removeAllDeliveredNotifications }); | ||
| (useAuth as jest.Mock).mockReturnValue({ connectedProfile: { handle: 'user' } }); | ||
| (useTitle as jest.Mock).mockReturnValue({ setTitle, title: '6529.io', notificationCount: 0, setNotificationCount: jest.fn(), setWaveData: jest.fn() }); | ||
| (useNotificationsContext as jest.Mock).mockReturnValue({ | ||
| removeAllDeliveredNotifications, | ||
| }); | ||
| (useAuth as jest.Mock).mockReturnValue({ | ||
| connectedProfile: { handle: "user", normalised_handle: "user" }, | ||
| }); | ||
| (useSeizeConnectContext as jest.Mock).mockReturnValue({ | ||
| address: "0xabc", | ||
| seizeConnect, | ||
| }); | ||
| (useUnreadNotifications as jest.Mock).mockReturnValue({ | ||
| notifications: { unread_count: 0 }, | ||
| haveUnreadNotifications: false, | ||
| }); | ||
| (useTitle as jest.Mock).mockReturnValue({ | ||
| setTitle, | ||
| title: "6529.io", | ||
| notificationCount: 0, | ||
| setNotificationCount: jest.fn(), | ||
| setWaveData: jest.fn(), | ||
| }); | ||
| (useWaveData as jest.Mock).mockReturnValue({ data: null }); | ||
| (useWave as jest.Mock).mockReturnValue({ isDm: false }); | ||
| }); | ||
|
|
||
| it('sets title and shows badge when there are unread notifications', () => { | ||
| (useUnreadNotifications as jest.Mock).mockReturnValue({ notifications: { unread_count: 3 }, haveUnreadNotifications: true }); | ||
| const item = { name: 'Notifications', icon: '/n' } as any; | ||
| it("sets title and shows badge when there are unread notifications", () => { | ||
| (useUnreadNotifications as jest.Mock).mockReturnValue({ | ||
| notifications: { unread_count: 3 }, | ||
| haveUnreadNotifications: true, | ||
| }); | ||
| const item = { name: "Notifications", icon: "/n" } as any; | ||
|
|
||
| const { container } = render(<NavItem item={item} />); | ||
|
|
||
| // Title is set via TitleContext hooks | ||
| expect(container.querySelector('.tw-bg-red')).not.toBeNull(); | ||
| expect(container.querySelector(".tw-bg-red")).not.toBeNull(); | ||
| expect(removeAllDeliveredNotifications).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('clears delivered notifications when none unread', () => { | ||
| (useUnreadNotifications as jest.Mock).mockReturnValue({ notifications: { unread_count: 0 }, haveUnreadNotifications: false }); | ||
| const item = { name: 'Notifications', icon: '/n' } as any; | ||
| it("clears delivered notifications when none unread", () => { | ||
| (useUnreadNotifications as jest.Mock).mockReturnValue({ | ||
| notifications: { unread_count: 0 }, | ||
| haveUnreadNotifications: false, | ||
| }); | ||
| const item = { name: "Notifications", icon: "/n" } as any; | ||
|
|
||
| const { container } = render(<NavItem item={item} />); | ||
|
|
||
| // Title is set via TitleContext hooks | ||
| expect(removeAllDeliveredNotifications).toHaveBeenCalled(); | ||
| expect(container.querySelector('.tw-bg-red')).toBeNull(); | ||
| expect(container.querySelector(".tw-bg-red")).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| it('renders disabled item when disabled flag set', () => { | ||
| (useUnreadNotifications as jest.Mock).mockReturnValue({}); | ||
| const item = { name: 'Feed', icon: '/i', disabled: true } as any; | ||
| const { getByRole } = render(<NavItem item={item} />); | ||
| const button = getByRole('button'); | ||
| expect(button).toBeDisabled(); | ||
| it("prompts connect when profile item is clicked without a connected wallet", () => { | ||
| (useSeizeConnectContext as jest.Mock).mockReturnValue({ | ||
| address: undefined, | ||
| seizeConnect, | ||
| }); | ||
| const item = { | ||
| kind: "route", | ||
| name: "Profile", | ||
| href: "/profile", | ||
| icon: "profile", | ||
| } as any; | ||
|
|
||
| const { getByRole } = render(<NavItem item={item} />); | ||
| fireEvent.click(getByRole("button", { name: "Profile" })); | ||
|
|
||
| expect(seizeConnect).toHaveBeenCalledTimes(1); | ||
| expect(handleNavClick).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("navigates to connected user profile when profile item is clicked", () => { | ||
| (useAuth as jest.Mock).mockReturnValue({ | ||
| connectedProfile: { handle: "User", normalised_handle: "my-handle" }, | ||
| }); | ||
| const item = { | ||
| kind: "route", | ||
| name: "Profile", | ||
| href: "/profile", | ||
| icon: "profile", | ||
| } as any; | ||
|
|
||
| const { getByRole } = render(<NavItem item={item} />); | ||
| fireEvent.click(getByRole("button", { name: "Profile" })); | ||
|
|
||
| expect(handleNavClick).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| kind: "route", | ||
| name: "Profile", | ||
| href: "/my-handle", | ||
| }) | ||
| ); | ||
| expect(seizeConnect).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("marks profile active only on own profile routes", () => { | ||
| (useViewContext as jest.Mock).mockReturnValue({ | ||
| activeView: null, | ||
| handleNavClick, | ||
| }); | ||
| (usePathname as jest.Mock).mockReturnValue("/my-handle/proxy"); | ||
| (useAuth as jest.Mock).mockReturnValue({ | ||
| connectedProfile: { handle: "User", normalised_handle: "my-handle" }, | ||
| }); | ||
| const item = { | ||
| kind: "route", | ||
| name: "Profile", | ||
| href: "/profile", | ||
| icon: "profile", | ||
| } as any; | ||
|
|
||
| const { getByRole, rerender } = render(<NavItem item={item} />); | ||
| expect(getByRole("button", { name: "Profile" })).toHaveAttribute( | ||
| "aria-current", | ||
| "page" | ||
| ); | ||
|
|
||
| (usePathname as jest.Mock).mockReturnValue("/other-user"); | ||
| rerender(<NavItem item={item} />); | ||
| expect(getByRole("button", { name: "Profile" })).not.toHaveAttribute( | ||
| "aria-current", | ||
| "page" | ||
| ); | ||
| }); | ||
|
|
||
| it("renders disabled item when disabled flag set", () => { | ||
| (useUnreadNotifications as jest.Mock).mockReturnValue({}); | ||
| const item = { name: "Feed", icon: "/i", disabled: true } as any; | ||
| const { getByRole } = render(<NavItem item={item} />); | ||
| const button = getByRole("button"); | ||
| expect(button).toBeDisabled(); | ||
| }); | ||
| }); |
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,22 @@ | ||
| const ProfileIcon = ({ | ||
| className, | ||
| }: { | ||
| readonly className?: string | undefined; | ||
| }) => ( | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| fill="none" | ||
| viewBox="0 0 24 24" | ||
| strokeWidth="1.65" | ||
| stroke="currentColor" | ||
| className={className} | ||
| > | ||
| <path | ||
| strokeLinecap="round" | ||
| strokeLinejoin="round" | ||
| d="M17.982 18.725A7.488 7.488 0 0 0 12 15.75a7.488 7.488 0 0 0-5.982 2.975m11.964 0a9 9 0 1 0-11.964 0m11.964 0A8.966 8.966 0 0 1 12 21a8.966 8.966 0 0 1-5.982-2.275M15 9.75A3 3 0 1 1 9 9.75a3 3 0 0 1 6 0Z" | ||
| /> | ||
| </svg> | ||
| ); | ||
|
|
||
| export default ProfileIcon; |
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
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.
Uh oh!
There was an error while loading. Please reload this page.