App: dodanie pomiaru w jednym miejscu (usunieto '+ Waga' z karty, zostaje topmenu)

This commit is contained in:
tisachi
2026-10-16 23:50:58 +02:00
parent b63d54d8c8
commit 09b29d7714
2 changed files with 30 additions and 25 deletions

View File

@@ -354,7 +354,7 @@ export default function ProfileBodyParameters() {
// menu top: selektor miesiąca (filtr po dacie) + akcja otwierająca modal w treści strony
useTopbar({
title: 'Profil — parametry ciała',
title: 'Parametry ciała',
back: '/profile',
dateFilter: <MonthPicker />,
filterActive: month !== '',
@@ -510,18 +510,6 @@ export default function ProfileBodyParameters() {
</span>
)
}
actions={
<Button
size="sm"
variant="secondary"
onClick={() => {
setAddTab('weight');
setAddOpen(true);
}}
>
<Plus className="w-4 h-4" />+ Waga
</Button>
}
>
{weightPoints.length === 0 ? (
<EmptyState

View File

@@ -51,13 +51,15 @@ function mockApi(
vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
const url = String(input);
const method = init?.method || 'GET';
if (url.includes('/auth/login')) return jsonResponse(200, { user: USER, accessToken: 'tok-1' });
if (url.includes('/auth/login'))
return jsonResponse(200, { user: USER, accessToken: 'tok-1' });
if (url.includes('/auth/refresh'))
return jsonResponse(401, { error: { code: 'UNAUTHORIZED', message: 'no cookie' } });
if (method === 'DELETE' && url.includes('/me/body-parameters/weight/')) {
const id = url.split('/').pop()!;
const idx = weightState.findIndex((w) => w.id === id);
if (idx < 0) return jsonResponse(404, { error: { code: 'NOT_FOUND', message: 'not found' } });
if (idx < 0)
return jsonResponse(404, { error: { code: 'NOT_FOUND', message: 'not found' } });
weightState.splice(idx, 1);
deleted.push({ kind: 'weight', id });
return new Response(null, { status: 204 });
@@ -65,13 +67,17 @@ function mockApi(
if (method === 'DELETE' && url.includes('/me/body-parameters/circumference/')) {
const id = url.split('/').pop()!;
const idx = circState.findIndex((c) => c.id === id);
if (idx < 0) return jsonResponse(404, { error: { code: 'NOT_FOUND', message: 'not found' } });
if (idx < 0)
return jsonResponse(404, { error: { code: 'NOT_FOUND', message: 'not found' } });
circState.splice(idx, 1);
deleted.push({ kind: 'circumference', id });
return new Response(null, { status: 204 });
}
if (url.includes('/me/body-parameters')) {
const byName = new Map<string, { name: string; points: { id: string; value: number; date: string }[] }>();
const byName = new Map<
string,
{ name: string; points: { id: string; value: number; date: string }[] }
>();
for (const c of circState) {
const entry = byName.get(c.name) ?? { name: c.name, points: [] };
entry.points.push({ id: c.id, value: c.value, date: c.date });
@@ -80,12 +86,18 @@ function mockApi(
return jsonResponse(200, { weight: weightState, circumferences: [...byName.values()] });
}
if (url.includes('/me/history')) return jsonResponse(200, { sessions: [] });
if (url.includes('/me/focus-chain')) return jsonResponse(200, { priorities: [], exclusions: [] });
if (url.includes('/me/focus-chain'))
return jsonResponse(200, { priorities: [], exclusions: [] });
if (url.includes('/me')) return jsonResponse(200, { user: USER, memberships: [] });
if (url.includes('/focus-areas')) return jsonResponse(200, { focusAreas: [] });
if (url.includes('/gyms')) return jsonResponse(200, { gyms: [] });
if (url.includes('/dashboard'))
return jsonResponse(200, { killstreak: 0, activePlan: null, nextTraining: null, progress: null });
return jsonResponse(200, {
killstreak: 0,
activePlan: null,
nextTraining: null,
progress: null,
});
if (url.includes('/exercises')) return jsonResponse(200, { exercises: [] });
if (url.includes('/plans')) return jsonResponse(200, { plans: [] });
if (url.includes('/calendar')) return jsonResponse(200, { month: '2026-08', days: [] });
@@ -107,8 +119,10 @@ async function loginToProfile(user: userEvent.User) {
expect(await screen.findByRole('heading', { name: 'Profil' })).toBeInTheDocument();
// body parameters live on their own subpage — open it via the tile
await user.click(await screen.findByRole('link', { name: /Parametry ciała/ }));
// tytuł podstrony jest tylko w topmenu (nagłówek Layout)
expect(await screen.findByRole('heading', { name: 'Profil — parametry ciała' })).toBeInTheDocument();
// wspólna nazwa sekcji: topbar (h1) = PageHeader (h2)
expect(
await screen.findByRole('heading', { name: 'Parametry ciała', level: 1 }),
).toBeInTheDocument();
}
function renderApp() {
@@ -268,18 +282,21 @@ describe('Profile — body parameter removal', () => {
expect(screen.getByRole('button', { name: 'Poprzedni miesiąc z danymi' })).toBeDisabled();
});
it('pokaże deltę wagi w wybranym miesiącu i szybkie „+ Waga” w nagłówku karty', async () => {
it('pokaże deltę wagi w wybranym miesiącu, a dodanie wagi jest tylko w topmenu', async () => {
mockApi();
const user = userEvent.setup();
renderApp();
await loginToProfile(user);
// delta: 81.8 (15.08) − 82.5 (01.08) = −0.7 kg (spadek)
// delta: 81.8 (15.08) − 82.5 (01.08) = −0,7 kg (spadek)
expect(await screen.findByText('82.5 kg')).toBeInTheDocument();
expect(screen.getByText('−0,7 kg w tym miesiącu')).toBeInTheDocument();
// szybkie dodanie wagi z nagłówka karty otwiera modal na zakładce Waga
await user.click(screen.getByRole('button', { name: '+ Waga' }));
// 1 kontrolka = 1 miejsce: w nagłówku karty brak przycisku „+ Waga”
expect(screen.queryByRole('button', { name: '+ Waga' })).not.toBeInTheDocument();
// dodanie wagi wyłącznie z topmenu (modal otwiera się na zakładce Waga)
await user.click(screen.getByRole('button', { name: 'Dodaj pomiar' }));
expect(await screen.findByRole('dialog')).toBeInTheDocument();
expect(screen.getByPlaceholderText('waga (kg)')).toBeInTheDocument();
});