From e943fafcfe93e92575f95eb29104983febc078fe Mon Sep 17 00:00:00 2001 From: tisachi Date: Thu, 22 Oct 2026 23:34:42 +0200 Subject: [PATCH] App: nazwa cwiczenia w edytorze planu lamie sie zamiast byc przycinana (pelna szerokosc wiersza) --- .../plans/plan-editor/ExerciseEditor.tsx | 58 +++---------------- app/test/ExerciseEditor.test.tsx | 53 ++++------------- 2 files changed, 18 insertions(+), 93 deletions(-) diff --git a/app/src/pages/plans/plan-editor/ExerciseEditor.tsx b/app/src/pages/plans/plan-editor/ExerciseEditor.tsx index 42c5b3d..dc80959 100644 --- a/app/src/pages/plans/plan-editor/ExerciseEditor.tsx +++ b/app/src/pages/plans/plan-editor/ExerciseEditor.tsx @@ -1,8 +1,7 @@ -import { useEffect, useRef, useState } from 'react'; +import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Activity, ChevronDown, ChevronUp, Minus, Plus, X } from 'lucide-react'; import { Badge, Button } from '../../../components/ui'; -import { cn } from '../../../lib/utils'; import { MUSCLE_COLORS, muscleName } from '../../../lib/labels'; import type { Exercise, ExerciseProgressPoint, LatestExerciseResult } from '../../../api/types'; import type { EditorExercise, EditorSet } from './types'; @@ -81,62 +80,21 @@ export function ExerciseEditor({ const [advanced, setAdvanced] = useState(false); const columns = SET_COLUMNS.filter((c) => !c.advanced || advanced); - /* Długa nazwa ćwiczenia jest przycinana — kliknięcie zwija/rozwija pełną nazwę, - hover (desktop) pokazuje title. Przycisk pojawia się dopiero, gdy nazwa - realnie się nie mieści (scrollWidth > clientWidth — nie zmieści się w całości). */ - const name = exerciseName(exercise.exerciseId); - const [nameExpanded, setNameExpanded] = useState(false); - const [nameTruncated, setNameTruncated] = useState(false); - const nameRef = useRef(null); - const attachNameRef = (el: HTMLElement | null) => { - nameRef.current = el; - }; - - useEffect(() => { - setNameExpanded(false); - }, [name]); - - useEffect(() => { - const el = nameRef.current; - if (!el) return; - const check = () => setNameTruncated(el.scrollWidth > el.clientWidth + 1); - check(); - const ro = new ResizeObserver(check); - ro.observe(el); - return () => ro.disconnect(); - }, [name, nameExpanded]); - - const nameInteractive = nameTruncated || nameExpanded; - return (
-
- {nameInteractive ? ( - - ) : ( - - {name} - - )} + {/* Bez przycinania: przy małej szerokości nazwa i podsumowanie serii + łamią się na całej szerokości wiersza (flex-wrap) — nic nie znika za „…”. */} +
+ + {exerciseName(exercise.exerciseId)} + {exerciseMeta && ( {muscleName(exerciseMeta.primaryMuscle)} )} - + {setsSummary(exercise.sets)}
diff --git a/app/test/ExerciseEditor.test.tsx b/app/test/ExerciseEditor.test.tsx index 0373b0c..84b153a 100644 --- a/app/test/ExerciseEditor.test.tsx +++ b/app/test/ExerciseEditor.test.tsx @@ -1,6 +1,5 @@ import { render, screen } from '@testing-library/react'; -import userEvent from '@testing-library/user-event'; -import { describe, it, expect, afterEach } from 'vitest'; +import { describe, it, expect } from 'vitest'; import { ExerciseEditor } from '../src/pages/plans/plan-editor/ExerciseEditor'; import type { EditorExercise } from '../src/pages/plans/plan-editor/types'; @@ -35,49 +34,17 @@ function renderEditor() { ); } -/** Symulacja realnego przycięcia tekstu: scrollWidth > clientWidth (jsdom zwraca same 0). */ -function mockTruncated(truncated: boolean) { - Object.defineProperty(Element.prototype, 'scrollWidth', { - configurable: true, - get: () => (truncated ? 400 : 0), - }); -} - -const scrollWidthDescriptor = Object.getOwnPropertyDescriptor(Element.prototype, 'scrollWidth'); - -afterEach(() => { - if (scrollWidthDescriptor) { - Object.defineProperty(Element.prototype, 'scrollWidth', scrollWidthDescriptor); - } else { - delete (Element.prototype as unknown as Record).scrollWidth; - } -}); - -describe('ExerciseEditor — rozwijanie długiej nazwy ćwiczenia', () => { - it('bez przycięcia renderuje samą nazwę (bez przycisku)', () => { - mockTruncated(false); - renderEditor(); - expect(screen.getByText(LONG_NAME)).toBeInTheDocument(); - expect(screen.queryByRole('button', { name: LONG_NAME })).not.toBeInTheDocument(); - }); - - it('po przycięciu nazwa staje się przyciskiem z title i rozwija się po kliknięciu', async () => { - const user = userEvent.setup(); - mockTruncated(true); +describe('ExerciseEditor — długa nazwa ćwiczenia', () => { + it('nazwa i podsumowanie serii łamią się zamiast być przycinane', () => { renderEditor(); - const btn = screen.getByRole('button', { name: LONG_NAME }); - expect(btn).toHaveAttribute('title', LONG_NAME); - expect(btn).toHaveAttribute('aria-expanded', 'false'); - expect(btn).toHaveClass('truncate'); + const name = screen.getByText(LONG_NAME); + expect(name.tagName).toBe('STRONG'); + expect(name).toHaveClass('break-words'); + expect(name).not.toHaveClass('truncate'); - await user.click(btn); - expect(btn).toHaveAttribute('aria-expanded', 'true'); - expect(btn).toHaveClass('break-words'); - expect(btn).not.toHaveClass('truncate'); - - await user.click(btn); - expect(btn).toHaveAttribute('aria-expanded', 'false'); - expect(btn).toHaveClass('truncate'); + const summary = screen.getByText('1×10 @ 50 kg · RIR 2'); + expect(summary).toHaveClass('break-words'); + expect(summary).not.toHaveClass('truncate'); }); });