diff --git a/src/components/layout/Navbar.tsx b/src/components/layout/Navbar.tsx index 874a384..26a9717 100644 --- a/src/components/layout/Navbar.tsx +++ b/src/components/layout/Navbar.tsx @@ -16,6 +16,7 @@ import { import { useState } from 'react' import { ConnectWallet } from '@/components/wallet/ConnectWallet' import { WalletInfo } from '@/components/wallet/WalletInfo' +import { DarkModeToggle } from '@/components/common/DarkModeToggle' import { NetworkBadge } from '@/components/ui/Badge' import { useWallet } from '@/hooks/useWallet' import { cn } from '@/lib/utils' @@ -58,8 +59,9 @@ export function Navbar() { {/* Spacer */}
- {/* Right side: network + address only — the Sidebar owns navigation */} + {/* Right side: network + theme toggle + address — the Sidebar owns navigation */}
+ {isConnected && } {isConnected && publicKey ? : }
@@ -95,7 +97,11 @@ export function Navbar() { {label} ))} -
+
+
+ Theme: + +
{isConnected && publicKey ? : }
diff --git a/src/pages/Settings.test.tsx b/src/pages/Settings.test.tsx new file mode 100644 index 0000000..ed8ab26 --- /dev/null +++ b/src/pages/Settings.test.tsx @@ -0,0 +1,67 @@ +import React from 'react' +import { describe, it, expect, beforeEach, vi } from 'vitest' +import { render, screen, fireEvent } from '@testing-library/react' +import { MemoryRouter } from 'react-router-dom' +import Settings from '@/pages/Settings' + +// Mock WalletContext +vi.mock('@/hooks/useWallet', () => ({ + useWallet: () => ({ + isConnected: false, + publicKey: null, + network: 'testnet', + account: null, + xlmBalance: null, + setNetwork: vi.fn(), + disconnect: vi.fn(), + }), +})) + +describe('Settings page Appearance section', () => { + beforeEach(() => { + localStorage.clear() + document.documentElement.className = '' + }) + + it('renders theme selector buttons (Light, Dark, System)', () => { + render( + + + + ) + + expect(screen.getByText('Appearance & Display')).toBeInTheDocument() + expect(screen.getByRole('button', { name: /Light/i })).toBeInTheDocument() + expect(screen.getByRole('button', { name: /Dark/i })).toBeInTheDocument() + expect(screen.getByRole('button', { name: /System/i })).toBeInTheDocument() + }) + + it('changes theme to dark when Dark button is clicked', () => { + render( + + + + ) + + const darkBtn = screen.getByRole('button', { name: /Dark/i }) + fireEvent.click(darkBtn) + + expect(document.documentElement.classList.contains('dark')).toBe(true) + expect(localStorage.getItem('ss-theme')).toBe(JSON.stringify('dark')) + }) + + it('changes theme to light when Light button is clicked', () => { + document.documentElement.classList.add('dark') + render( + + + + ) + + const lightBtn = screen.getByRole('button', { name: /Light/i }) + fireEvent.click(lightBtn) + + expect(document.documentElement.classList.contains('dark')).toBe(false) + expect(localStorage.getItem('ss-theme')).toBe(JSON.stringify('light')) + }) +}) diff --git a/src/pages/Settings.tsx b/src/pages/Settings.tsx index ee3d817..9464540 100644 --- a/src/pages/Settings.tsx +++ b/src/pages/Settings.tsx @@ -10,6 +10,9 @@ import { Copy, Check, AlertTriangle, + Sun, + Moon, + Laptop, } from 'lucide-react' import { Card, CardHeader, CardTitle } from '@/components/ui/Card' import { Button } from '@/components/ui/Button' @@ -17,6 +20,7 @@ import { Input, Select } from '@/components/ui/Input' import { NetworkBadge } from '@/components/ui/Badge' import { ConnectWallet } from '@/components/wallet/ConnectWallet' import { useWallet } from '@/hooks/useWallet' +import { useTheme } from '@/hooks/useTheme' import { truncateAddress, formatXLM } from '@/lib/stellar' import { copyToClipboard } from '@/lib/utils' import type { Network, AppSettings } from '@/types' @@ -72,6 +76,7 @@ function SettingsSection({ export default function Settings() { const { isConnected, publicKey, network, account, xlmBalance, setNetwork, disconnect } = useWallet() + const { theme, setTheme } = useTheme() const { settings, save, reset } = useSettings() const [localSettings, setLocalSettings] = useState(settings) const [saved, setSaved] = useState(false) @@ -289,26 +294,57 @@ export default function Settings() { /> - {/* Notifications (UI only) */} - }> -