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.
27 lines
1.2 KiB
TypeScript
27 lines
1.2 KiB
TypeScript
import { screen } from '@testing-library/react'
|
|
import { expect, test } from 'vitest'
|
|
import { json, mockFetch } from '@test/fetch'
|
|
import { renderApp } from '@test/render'
|
|
import { PublicProfileView } from '../components/PublicProfileView'
|
|
|
|
const profile = { id: 'u1', display_nick: 'loki', avatar_url: null, created_at: '2026-01-05T10:00:00Z', badges: ['early'] }
|
|
|
|
test('shows nick, early badge and the player configs', async () => {
|
|
mockFetch({
|
|
'POST /auth/refresh': () => json({}, 401),
|
|
'GET /users/u1': () => json(profile),
|
|
'GET /showcase': () => json({ items: [], page: 0, has_more: false }),
|
|
})
|
|
renderApp([{ path: '/', element: <PublicProfileView id="u1" /> }])
|
|
expect(await screen.findByText('loki')).toBeInTheDocument()
|
|
expect(screen.getByText('Один из первых 1000')).toBeInTheDocument()
|
|
})
|
|
|
|
test('unknown player shows not found', async () => {
|
|
mockFetch({
|
|
'POST /auth/refresh': () => json({}, 401),
|
|
'GET /users/nope': () => json({ error: 'no such account' }, 404),
|
|
})
|
|
renderApp([{ path: '/', element: <PublicProfileView id="nope" /> }])
|
|
expect(await screen.findByText('Такого игрока нет.')).toBeInTheDocument()
|
|
})
|