Task 12 batch around the existing crop/preview flow: - Success Notice (auto-dismiss ~2.5s) after an avatar upload. - "Reposition" re-crops the current avatar without re-picking a file. - Drag & drop an image straight onto the profile avatar circle. - Real upload progress via a new XHR-backed api.upload (fetch has none); refreshOnce now also stores the renewed token (reload-restore fix). - Local avatar history (last 5, IndexedDB, this-device-only) strip that re-uploads a stored crop. Stored as ArrayBuffer (Blob is not cloneable under structuredClone); label makes the per-device scope explicit. - Added a "success" tone to Notice. Infra (same session): registered @shared/@features/@pages/@app/@test path aliases in vite.config + tsconfigs and rewrote deep ../../../ imports; moved avatar components into components/avatar/ to keep folders at <=4 files. Tests: avatarHistory cap/order, recrop visibility, drop-opens-cropper, client upload/progress/401-retry. bun test 103 pass, lint 0 errors, build ok.
41 lines
2 KiB
TypeScript
41 lines
2 KiB
TypeScript
import { render, screen } from '@testing-library/react'
|
|
import { expect, test, vi } from 'vitest'
|
|
import { I18nextProvider } from 'react-i18next'
|
|
import { CommandHero } from '../CommandHero'
|
|
import { Hero } from '../sections/hero/Hero'
|
|
import { createMemoryRouter, RouterProvider } from 'react-router'
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
import { initI18n } from '@app/i18n'
|
|
import { SessionProvider } from '@features/auth/session'
|
|
import { json, mockFetch } from '@test/fetch'
|
|
|
|
test('reduced motion shows the full command at once', async () => {
|
|
vi.stubGlobal('matchMedia', (q: string) => ({ matches: q.includes('reduce'), addEventListener() {}, removeEventListener() {} }))
|
|
mockFetch({ 'POST /auth/refresh': () => json({}, 401) })
|
|
const router = createMemoryRouter([{ path: '/', element: <CommandHero /> }])
|
|
render(
|
|
<QueryClientProvider client={new QueryClient()}>
|
|
<SessionProvider><RouterProvider router={router} /></SessionProvider>
|
|
</QueryClientProvider>,
|
|
)
|
|
expect(await screen.findByText('%config load 7KQ3M9XA')).toBeInTheDocument()
|
|
expect(screen.getByText('[LoVisual] Конфиг «pvp» загружен')).toBeInTheDocument()
|
|
expect(screen.getByLabelText('Пример: загрузка конфига по коду в чате игры')).toBeInTheDocument()
|
|
})
|
|
|
|
test('english locale renders the landing hero headline', async () => {
|
|
vi.stubGlobal('matchMedia', (q: string) => ({ matches: q.includes('reduce'), addEventListener() {}, removeEventListener() {} }))
|
|
mockFetch({ 'POST /auth/refresh': () => json({}, 401) })
|
|
const i18n = initI18n('en')
|
|
const router = createMemoryRouter([{ path: '/', element: <Hero /> }])
|
|
render(
|
|
<I18nextProvider i18n={i18n}>
|
|
<QueryClientProvider client={new QueryClient()}>
|
|
<SessionProvider>
|
|
<RouterProvider router={router} />
|
|
</SessionProvider>
|
|
</QueryClientProvider>
|
|
</I18nextProvider>,
|
|
)
|
|
expect(await screen.findByRole('heading', { level: 1 })).toHaveTextContent("you'll fall in love with")
|
|
})
|