Some checks failed
CI / skip-ci-check (pull_request) Successful in 1m19s
CI / lint-and-type-check (pull_request) Failing after 1m37s
CI / test (pull_request) Successful in 2m16s
CI / build (pull_request) Failing after 1m46s
CI / secret-scanning (pull_request) Successful in 1m20s
CI / dependency-scan (pull_request) Successful in 1m27s
CI / sast-scan (pull_request) Successful in 2m29s
CI / workflow-summary (pull_request) Successful in 1m18s
- Add duplicate photo detection (file hash and URL checking) - Add max attempts per photo with UI counter - Simplify penalty system (auto-enable when points > 0) - Prevent scores from going below 0 - Add admin photo deletion functionality - Improve navigation with always-visible logout - Prevent users from guessing their own photos
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
import { render, screen } from '@testing-library/react'
|
|
import { useSession } from 'next-auth/react'
|
|
import Navigation from '@/components/Navigation'
|
|
|
|
jest.mock('next-auth/react')
|
|
|
|
describe('Navigation', () => {
|
|
it('should not render when user is not logged in', () => {
|
|
;(useSession as jest.Mock).mockReturnValue({
|
|
data: null,
|
|
status: 'unauthenticated',
|
|
})
|
|
|
|
const { container } = render(<Navigation />)
|
|
expect(container.firstChild).toBeNull()
|
|
})
|
|
|
|
it('should render navigation when user is logged in', () => {
|
|
;(useSession as jest.Mock).mockReturnValue({
|
|
data: {
|
|
user: {
|
|
name: 'Test User',
|
|
email: 'test@example.com',
|
|
role: 'USER',
|
|
},
|
|
},
|
|
status: 'authenticated',
|
|
})
|
|
|
|
render(<Navigation />)
|
|
|
|
expect(screen.getByText('MirrorMatch')).toBeInTheDocument()
|
|
expect(screen.getByText('Photos')).toBeInTheDocument()
|
|
expect(screen.getByText('Upload')).toBeInTheDocument()
|
|
expect(screen.getByText('Leaderboard')).toBeInTheDocument()
|
|
expect(screen.getByText('Profile')).toBeInTheDocument()
|
|
expect(screen.getByText('Hello, Test User')).toBeInTheDocument()
|
|
})
|
|
|
|
it('should show admin link for ADMIN users', () => {
|
|
;(useSession as jest.Mock).mockReturnValue({
|
|
data: {
|
|
user: {
|
|
name: 'Admin User',
|
|
email: 'admin@example.com',
|
|
role: 'ADMIN',
|
|
},
|
|
},
|
|
status: 'authenticated',
|
|
})
|
|
|
|
render(<Navigation />)
|
|
|
|
expect(screen.getByText('Admin')).toBeInTheDocument()
|
|
})
|
|
|
|
it('should not show admin link for regular users', () => {
|
|
;(useSession as jest.Mock).mockReturnValue({
|
|
data: {
|
|
user: {
|
|
name: 'Test User',
|
|
email: 'test@example.com',
|
|
role: 'USER',
|
|
},
|
|
},
|
|
status: 'authenticated',
|
|
})
|
|
|
|
render(<Navigation />)
|
|
|
|
expect(screen.queryByText('Admin')).not.toBeInTheDocument()
|
|
})
|
|
})
|