mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
@coderabbitai ignore
## Summary
- Phase 3 of the i18n multilingual initiative — makes the karaoke-gen
frontend fully multilingual (English, Spanish, German)
- Installs `next-intl` with `[locale]` path-based routing,
LanguageSwitcher, and `Accept-Language` API header
- Extracts **1,062 strings** from ~70 components into `messages/en.json`
across 31 namespaces
- Wires `useTranslations()` into all user-facing components (landing,
dashboard, auth, job flow, lyrics review, instrumental review, audio
editor, etc.)
- Admin pages (`/admin/*`) stay outside locale routing — intentionally
excluded from i18n scope
- Static export generates `/en/`, `/es/`, `/de/` directories (45 total
pages) for Cloudflare Pages
- `es.json`/`de.json` are English placeholders — translation via Gemini
pipeline pending
- Translation pipeline (`scripts/translate.py`) and glossary (55
karaoke-specific terms) included
## Key architecture decisions
- Root layout keeps ThemeProvider/TenantProvider (needed by admin pages
outside `[locale]`)
- Only NextIntlClientProvider added to `[locale]/layout.tsx`
- `job-status.ts` labels converted to translation keys; consumers
translate via `useTranslations('jobStatus')`
- Jest mock loads actual `en.json` so existing tests validate i18n
wiring without assertion changes
## Test plan
- [x] All 707 frontend tests pass (39 suites)
- [x] Static build generates all 45 pages across 3 locales
- [x] Admin pages render at `/admin/` without locale prefix
- [x] CodeRabbit review: 4 issues fixed, 7 pre-existing noted
- [ ] Post-deploy: verify `/en/` landing page renders correctly
- [ ] Post-deploy: verify LanguageSwitcher redirects to `/es/` and
`/de/`
- [ ] Post-deploy: verify `/admin/` still works without locale context
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
278 lines
7.9 KiB
TypeScript
278 lines
7.9 KiB
TypeScript
/**
|
|
* Tests for PushNotificationPrompt component
|
|
*
|
|
* Tests the soft-ask banner for enabling push notifications,
|
|
* including iOS detection and permission handling.
|
|
*/
|
|
|
|
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
|
|
import { PushNotificationPrompt, PushNotificationToggle } from '../push-notification-prompt'
|
|
import { usePushNotifications } from '@/hooks/use-push-notifications'
|
|
|
|
// Mock the hook
|
|
jest.mock('@/hooks/use-push-notifications')
|
|
const mockUsePushNotifications = usePushNotifications as jest.MockedFunction<typeof usePushNotifications>
|
|
|
|
// Default mock return value
|
|
const defaultHookReturn = {
|
|
isLoading: false,
|
|
isPushEnabled: true,
|
|
shouldShowPrompt: true,
|
|
needsIOSInstall: false,
|
|
isIOS: false,
|
|
isPWAInstalled: false,
|
|
isSubscribed: false,
|
|
permission: 'default' as const,
|
|
subscribe: jest.fn().mockResolvedValue(true),
|
|
unsubscribe: jest.fn().mockResolvedValue(true),
|
|
dismissPrompt: jest.fn(),
|
|
error: null,
|
|
isSupported: true,
|
|
}
|
|
|
|
describe('PushNotificationPrompt', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks()
|
|
mockUsePushNotifications.mockReturnValue(defaultHookReturn)
|
|
})
|
|
|
|
describe('visibility conditions', () => {
|
|
it('renders nothing when loading', () => {
|
|
mockUsePushNotifications.mockReturnValue({
|
|
...defaultHookReturn,
|
|
isLoading: true,
|
|
})
|
|
|
|
const { container } = render(<PushNotificationPrompt />)
|
|
expect(container.firstChild).toBeNull()
|
|
})
|
|
|
|
it('renders nothing when push not enabled on server', () => {
|
|
mockUsePushNotifications.mockReturnValue({
|
|
...defaultHookReturn,
|
|
isPushEnabled: false,
|
|
})
|
|
|
|
const { container } = render(<PushNotificationPrompt />)
|
|
expect(container.firstChild).toBeNull()
|
|
})
|
|
|
|
it('renders nothing when shouldShowPrompt is false', () => {
|
|
mockUsePushNotifications.mockReturnValue({
|
|
...defaultHookReturn,
|
|
shouldShowPrompt: false,
|
|
})
|
|
|
|
const { container } = render(<PushNotificationPrompt />)
|
|
expect(container.firstChild).toBeNull()
|
|
})
|
|
|
|
it('renders prompt when shouldShowPrompt is true', () => {
|
|
render(<PushNotificationPrompt />)
|
|
|
|
expect(screen.getByText(/Get notified when your video is ready/)).toBeInTheDocument()
|
|
expect(screen.getByText('Enable Notifications')).toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
describe('iOS Add to Home Screen instructions', () => {
|
|
it('shows iOS instructions when needsIOSInstall is true', () => {
|
|
mockUsePushNotifications.mockReturnValue({
|
|
...defaultHookReturn,
|
|
needsIOSInstall: true,
|
|
})
|
|
|
|
render(<PushNotificationPrompt />)
|
|
|
|
expect(screen.getByText(/Get notifications on your iPhone/)).toBeInTheDocument()
|
|
expect(screen.getByText(/Add to Home Screen/)).toBeInTheDocument()
|
|
expect(screen.getByText(/Share button in Safari/)).toBeInTheDocument()
|
|
})
|
|
|
|
it('iOS instructions have dismiss button', () => {
|
|
mockUsePushNotifications.mockReturnValue({
|
|
...defaultHookReturn,
|
|
needsIOSInstall: true,
|
|
})
|
|
|
|
render(<PushNotificationPrompt />)
|
|
|
|
const dismissButton = screen.getByLabelText('Dismiss')
|
|
expect(dismissButton).toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
describe('user interactions', () => {
|
|
it('calls subscribe when Enable Notifications clicked', async () => {
|
|
const mockSubscribe = jest.fn().mockResolvedValue(true)
|
|
mockUsePushNotifications.mockReturnValue({
|
|
...defaultHookReturn,
|
|
subscribe: mockSubscribe,
|
|
})
|
|
|
|
render(<PushNotificationPrompt />)
|
|
|
|
fireEvent.click(screen.getByText('Enable Notifications'))
|
|
|
|
await waitFor(() => {
|
|
expect(mockSubscribe).toHaveBeenCalledTimes(1)
|
|
})
|
|
})
|
|
|
|
it('shows loading state while subscribing', async () => {
|
|
const mockSubscribe = jest.fn().mockImplementation(() => new Promise(resolve => setTimeout(() => resolve(true), 100)))
|
|
mockUsePushNotifications.mockReturnValue({
|
|
...defaultHookReturn,
|
|
subscribe: mockSubscribe,
|
|
})
|
|
|
|
render(<PushNotificationPrompt />)
|
|
|
|
fireEvent.click(screen.getByText('Enable Notifications'))
|
|
|
|
expect(screen.getByText('Enabling...')).toBeInTheDocument()
|
|
})
|
|
|
|
it('calls dismissPrompt(false) when Not now clicked', () => {
|
|
const mockDismiss = jest.fn()
|
|
mockUsePushNotifications.mockReturnValue({
|
|
...defaultHookReturn,
|
|
dismissPrompt: mockDismiss,
|
|
})
|
|
|
|
render(<PushNotificationPrompt />)
|
|
|
|
fireEvent.click(screen.getByText('Not now'))
|
|
|
|
expect(mockDismiss).toHaveBeenCalledWith(false)
|
|
})
|
|
|
|
it('calls dismissPrompt(true) when Don\'t ask again clicked', () => {
|
|
const mockDismiss = jest.fn()
|
|
mockUsePushNotifications.mockReturnValue({
|
|
...defaultHookReturn,
|
|
dismissPrompt: mockDismiss,
|
|
})
|
|
|
|
render(<PushNotificationPrompt />)
|
|
|
|
fireEvent.click(screen.getByText("Don't ask again"))
|
|
|
|
expect(mockDismiss).toHaveBeenCalledWith(true)
|
|
})
|
|
})
|
|
|
|
describe('error display', () => {
|
|
it('displays error message when error is set', () => {
|
|
mockUsePushNotifications.mockReturnValue({
|
|
...defaultHookReturn,
|
|
error: 'Permission denied',
|
|
})
|
|
|
|
render(<PushNotificationPrompt />)
|
|
|
|
expect(screen.getByText('Permission denied')).toBeInTheDocument()
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('PushNotificationToggle', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks()
|
|
mockUsePushNotifications.mockReturnValue(defaultHookReturn)
|
|
})
|
|
|
|
describe('visibility conditions', () => {
|
|
it('renders nothing when loading', () => {
|
|
mockUsePushNotifications.mockReturnValue({
|
|
...defaultHookReturn,
|
|
isLoading: true,
|
|
})
|
|
|
|
const { container } = render(<PushNotificationToggle />)
|
|
expect(container.firstChild).toBeNull()
|
|
})
|
|
|
|
it('renders nothing when push not enabled', () => {
|
|
mockUsePushNotifications.mockReturnValue({
|
|
...defaultHookReturn,
|
|
isPushEnabled: false,
|
|
})
|
|
|
|
const { container } = render(<PushNotificationToggle />)
|
|
expect(container.firstChild).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe('permission denied state', () => {
|
|
it('shows "Blocked in browser" when permission denied', () => {
|
|
mockUsePushNotifications.mockReturnValue({
|
|
...defaultHookReturn,
|
|
permission: 'denied',
|
|
})
|
|
|
|
render(<PushNotificationToggle />)
|
|
|
|
expect(screen.getByText('Blocked in browser')).toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
describe('toggle functionality', () => {
|
|
it('shows Enable button when not subscribed', () => {
|
|
mockUsePushNotifications.mockReturnValue({
|
|
...defaultHookReturn,
|
|
isSubscribed: false,
|
|
})
|
|
|
|
render(<PushNotificationToggle />)
|
|
|
|
expect(screen.getByText('Enable notifications')).toBeInTheDocument()
|
|
})
|
|
|
|
it('shows Disable button when subscribed', () => {
|
|
mockUsePushNotifications.mockReturnValue({
|
|
...defaultHookReturn,
|
|
isSubscribed: true,
|
|
})
|
|
|
|
render(<PushNotificationToggle />)
|
|
|
|
expect(screen.getByText('Disable on this device')).toBeInTheDocument()
|
|
})
|
|
|
|
it('calls subscribe when Enable clicked', async () => {
|
|
const mockSubscribe = jest.fn().mockResolvedValue(true)
|
|
mockUsePushNotifications.mockReturnValue({
|
|
...defaultHookReturn,
|
|
isSubscribed: false,
|
|
subscribe: mockSubscribe,
|
|
})
|
|
|
|
render(<PushNotificationToggle />)
|
|
|
|
fireEvent.click(screen.getByText('Enable notifications'))
|
|
|
|
await waitFor(() => {
|
|
expect(mockSubscribe).toHaveBeenCalledTimes(1)
|
|
})
|
|
})
|
|
|
|
it('calls unsubscribe when Disable clicked', async () => {
|
|
const mockUnsubscribe = jest.fn().mockResolvedValue(true)
|
|
mockUsePushNotifications.mockReturnValue({
|
|
...defaultHookReturn,
|
|
isSubscribed: true,
|
|
unsubscribe: mockUnsubscribe,
|
|
})
|
|
|
|
render(<PushNotificationToggle />)
|
|
|
|
fireEvent.click(screen.getByText('Disable on this device'))
|
|
|
|
await waitFor(() => {
|
|
expect(mockUnsubscribe).toHaveBeenCalledTimes(1)
|
|
})
|
|
})
|
|
})
|
|
})
|