feat(app): profile photo — avatar upload in Mon compte, photo in the sidebar, drawer and top bar

packages/supabase assets module: closed AssetFailure kinds, begin / quarantine
upload (upsert off) / confirm / remove, own-row state read with an explicit
column list, download under the SELECT policy. App: client transport (magic
byte sniff, never SVG, createImageBitmap, canvas 1024 px, JPEG 0.9, 5 MiB
cap), AvatarSection (preview, save, 1 s polling up to 30 s, rejection and
failure messages per closed code, removal with confirmation, in-flight row
resumed at mount), auth store blob URL revoked on change and sign-out,
AvatarCircle in UserBadge and the top bar link to Mon compte (D3), FR/EN
strings, fake client extended, 27 new tests (app 300).
This commit is contained in:
bchanot committed 2026-10-13 19:32:37 +02:00
1 parent 614887470c
commit 926dd7df8c
18 files changed
+1550 -31

No files matched your search

+29 -2
View File
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { cleanup, render, screen } from '@testing-library/react'
import { cleanup, render, screen, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { MemoryRouter, Route, Routes } from 'react-router-dom'
import { createFakeSupabase, fakeProfile, fakeUser, type FakeSupabase } from '../helpers/fakeSupabase'
@@ -27,6 +27,8 @@ beforeEach(() => {
user: fakeUser(),
profile: fakeProfile({ display_name: 'Alice Local' }),
roles: [],
avatar: null,
avatarUrl: null,
})
})
afterEach(cleanup)
@@ -56,9 +58,34 @@ describe('AppLayout', () => {
expect(screen.getByText('dashboard page')).toBeInTheDocument()
})
it('links the top-bar avatar and name to the account page', async () => {
const user = userEvent.setup()
mount()
const link = screen.getByTestId('topbar-account')
expect(link).toHaveAttribute('href', '/app/account')
expect(link).toHaveTextContent('Alice Local')
expect(link).toHaveAttribute('aria-label', fr['shell.nav.account'])
await user.click(link)
expect(await screen.findByText('account page')).toBeInTheDocument()
})
it('shows the photo everywhere once the store holds a blob URL, the monogram otherwise', () => {
mount()
expect(screen.queryAllByRole('img', { name: fr['account.avatar.alt'] })).toHaveLength(0)
expect(screen.getAllByText('AL').length).toBeGreaterThan(0)
cleanup()
useAuthStore.setState({ avatarUrl: 'blob:photo' })
mount()
const imgs = screen.getAllByRole('img', { name: fr['account.avatar.alt'] })
expect(imgs.length).toBeGreaterThanOrEqual(2)
imgs.forEach((img) => expect(img).toHaveAttribute('src', 'blob:photo'))
expect(screen.queryByText('AL')).toBeNull()
})
it('marks the active destination', () => {
mount('/app/account')
const link = screen.getByRole('link', { name: new RegExp(fr['shell.nav.account']) })
const nav = screen.getByRole('navigation', { name: fr['shell.nav_label'] })
const link = within(nav).getByRole('link', { name: new RegExp(fr['shell.nav.account']) })
expect(link).toHaveAttribute('aria-current', 'page')
})