Workout Management tests ready

This commit is contained in:
AG
2025-12-08 22:21:10 +02:00
parent d2dc474f0f
commit f32661d892
7 changed files with 183 additions and 55 deletions

Binary file not shown.

View File

@@ -66,10 +66,14 @@ const ExerciseModal: React.FC<ExerciseModalProps> = ({ isOpen, onClose, onSave,
return (
<Modal
isOpen={isOpen}
onClose={onClose}
onClose={() => {
console.log('ExerciseModal onClose');
onClose();
}}
title={t('create_exercise', lang)}
maxWidth="sm"
>
{console.log('ExerciseModal Rendering. isOpen:', isOpen)}
<div className="space-y-6">
<div>
<FilledInput

View File

@@ -32,7 +32,7 @@ const FilledInput: React.FC<FilledInputProps> = ({ label, value, onChange, onCle
return (
<div className="relative group bg-surface-container-high rounded-t-lg border-b border-outline-variant hover:bg-white/5 focus-within:border-primary transition-colors">
<label htmlFor={id} className="absolute top-2 left-4 text-[10px] font-medium text-on-surface-variant flex items-center gap-1">
{icon} {label}
{icon ? <>{icon} {label}</> : label}
</label>
<input
id={id}

View File

@@ -138,11 +138,12 @@ const Plans: React.FC<PlansProps> = ({ lang }) => {
};
const onDragStart = (index: number) => {
console.log('Drag Start:', index);
dragItem.current = index;
setDraggingIndex(index);
};
const onDragEnter = (index: number) => {
console.log('Drag Enter:', index);
if (dragItem.current === null) return;
if (dragItem.current === index) return;
@@ -153,6 +154,7 @@ const Plans: React.FC<PlansProps> = ({ lang }) => {
setSteps(newSteps);
dragItem.current = index;
setDraggingIndex(index);
console.log(`Swapped ${draggedItemContent.id} to ${index}`);
};
const onDragEnd = () => {

View File

@@ -364,7 +364,10 @@ const Profile: React.FC<ProfileProps> = ({ user, onLogout, lang, onLanguageChang
{/* EXERCISE MANAGER */}
<Card>
<button
onClick={() => setShowExercises(!showExercises)}
onClick={() => {
console.log('Toggling showExercises', !showExercises);
setShowExercises(!showExercises);
}}
className="w-full flex justify-between items-center text-sm font-bold text-primary"
>
<span className="flex items-center gap-2"><Dumbbell size={14} /> {t('manage_exercises', lang)}</span>
@@ -374,7 +377,10 @@ const Profile: React.FC<ProfileProps> = ({ user, onLogout, lang, onLanguageChang
{showExercises && (
<div className="mt-4 space-y-4">
<button
onClick={() => setIsCreatingEx(true)}
onClick={() => {
console.log('Clicking New Exercise');
setIsCreatingEx(true);
}}
className="w-full py-2 border border-outline border-dashed rounded-lg text-sm text-on-surface-variant hover:bg-surface-container-high flex items-center justify-center gap-2"
>
<Plus size={16} /> {t('create_exercise', lang)}
@@ -414,13 +420,15 @@ const Profile: React.FC<ProfileProps> = ({ user, onLogout, lang, onLanguageChang
</div>
</div>
<div className="flex items-center gap-1 shrink-0">
<button onClick={() => setEditingExercise(ex)} className="p-2 text-on-surface-variant hover:text-primary hover:bg-white/5 rounded-full">
<button onClick={() => setEditingExercise(ex)} className="p-2 text-on-surface-variant hover:text-primary hover:bg-white/5 rounded-full" role="button" aria-label="Edit Exercise">
<Pencil size={16} />
</button>
<button
onClick={() => handleArchiveExercise(ex, !ex.isArchived)}
className={`p-2 rounded-full hover:bg-white/5 ${ex.isArchived ? 'text-primary' : 'text-on-surface-variant'}`}
title={ex.isArchived ? t('unarchive', lang) : t('archive', lang)}
role="button"
aria-label={ex.isArchived ? 'Unarchive Exercise' : 'Archive Exercise'}
>
{ex.isArchived ? <ArchiveRestore size={16} /> : <Archive size={16} />}
</button>

View File

@@ -41,7 +41,11 @@ export const Modal: React.FC<ModalProps> = ({ isOpen, onClose, title, children,
className="absolute inset-0 bg-black/60 backdrop-blur-sm transition-opacity"
onClick={onClose}
/>
<div className={`relative bg-surface-container w-full ${maxWidthClasses[maxWidth]} rounded-[28px] shadow-elevation-3 animate-in slide-in-from-bottom-10 zoom-in-95 duration-200 flex flex-col max-h-[90vh]`}>
<div
className={`relative bg-surface-container w-full ${maxWidthClasses[maxWidth]} rounded-[28px] shadow-elevation-3 animate-in slide-in-from-bottom-10 zoom-in-95 duration-200 flex flex-col max-h-[90vh]`}
role="dialog"
aria-modal="true"
>
<div className="flex items-center justify-between p-6 pb-2 shrink-0">
<h3 className="text-xl font-normal text-on-surface">{title}</h3>
<button

View File

@@ -94,7 +94,7 @@ test.describe('II. Workout Management', () => {
await expect(page.getByText('Plan To Delete')).not.toBeVisible();
});
test.skip('2.4 A. Workout Plans - Reorder Exercises', async ({ page, createUniqueUser, request }) => {
test('2.4 A. Workout Plans - Reorder Exercises', async ({ page, createUniqueUser, request }) => {
page.on('console', msg => console.log('PAGE LOG:', msg.text()));
const user = await loginAndSetup(page, createUniqueUser);
// Need exercises
@@ -133,9 +133,43 @@ test.describe('II. Workout Management', () => {
.last();
await card.getByRole('button', { name: 'Edit Plan' }).click();
// Check initial order by visibility for now
await expect(page.locator('div').filter({ hasText: 'Ex One' }).first()).toBeVisible();
await expect(page.locator('div').filter({ hasText: 'Ex Two' }).last()).toBeVisible();
const card1 = page.locator('[draggable="true"]').filter({ hasText: 'Ex One' });
const card2 = page.locator('[draggable="true"]').filter({ hasText: 'Ex Two' });
// Initial state check
await expect(page.locator('[draggable="true"]').first()).toContainText('Ex One');
// Drag using handles with explicit wait
const sourceHandle = card1.locator('.lucide-grip-vertical');
const targetHandle = card2.locator('.lucide-grip-vertical');
await expect(sourceHandle).toBeVisible();
await expect(targetHandle).toBeVisible();
console.log('Starting Drag...');
await sourceHandle.dragTo(targetHandle);
console.log('Drag complete');
// Wait for reorder to settle
await page.waitForTimeout(1000);
// Verify Swap immediately
await expect(page.locator('[draggable="true"]').first()).toContainText('Ex Two');
await page.getByRole('button', { name: 'Save' }).click();
// Reload and verify persistence
await page.reload();
await page.getByRole('button', { name: 'Plans' }).first().click();
const cardRevisit = page.locator('div')
.filter({ hasText: 'Reorder Plan' })
.filter({ has: page.getByRole('button', { name: 'Edit Plan' }) })
.last();
await cardRevisit.getByRole('button', { name: 'Edit Plan' }).click();
await expect(page.locator('[draggable="true"]').first()).toContainText('Ex Two');
await expect(page.locator('[draggable="true"]').last()).toContainText('Ex One');
});
test('2.5 A. Workout Plans - Start Session from Plan', async ({ page, createUniqueUser, request }) => {
@@ -149,6 +183,7 @@ test.describe('II. Workout Management', () => {
},
headers: { 'Authorization': `Bearer ${user.token}` }
});
console.log(await resp.json());
expect(resp.ok()).toBeTruthy();
await page.reload();
@@ -171,19 +206,22 @@ test.describe('II. Workout Management', () => {
await loginAndSetup(page, createUniqueUser);
await page.getByRole('button', { name: 'Profile' }).click();
await page.getByRole('button', { name: /Manage Exercises/i }).click();
await page.locator('button:has-text("Manage Exercises")').click();
await page.getByRole('button', { name: /New Exercise/i }).click();
// Use force click as button might be obstructed or animating
await page.getByRole('button', { name: /New Exercise/i }).click({ force: true });
await page.getByLabel('Name').fill('Custom Bicep Curl');
await expect(page.getByText('Free Weights & Machines', { exact: false })).toBeVisible();
await expect(page.locator('div[role="dialog"]')).toBeVisible();
await page.locator('div[role="dialog"]').getByLabel('Name').fill('Custom Bicep Curl');
await expect(page.locator('div[role="dialog"]').getByText('Free Weights & Machines', { exact: false })).toBeVisible();
await page.getByRole('button', { name: 'Create' }).click();
await page.locator('div[role="dialog"]').getByRole('button', { name: 'Create' }).click();
await page.waitForTimeout(1000);
// Reload and filter
await page.reload();
await page.getByRole('button', { name: 'Profile' }).click();
await page.getByRole('button', { name: /Manage Exercises/i }).click();
await page.locator('button:has-text("Manage Exercises")').click();
await page.getByLabel(/Filter by name/i).fill('Custom Bicep Curl');
await expect(page.getByText('Custom Bicep Curl')).toBeVisible();
@@ -195,15 +233,18 @@ test.describe('II. Workout Management', () => {
await page.getByRole('button', { name: 'Profile' }).click();
await page.getByRole('button', { name: /Manage Exercises/i }).click();
await page.getByRole('button', { name: /New Exercise/i }).click();
await page.getByRole('button', { name: /New Exercise/i }).click({ force: true });
await page.getByLabel('Name').fill('Adv Pushup');
// Scope to dialog to avoid background matches
await page.locator('div[role="dialog"] button').filter({ hasText: /Bodyweight/i }).click();
await expect(page.locator('div[role="dialog"]')).toBeVisible();
await page.locator('div[role="dialog"]').getByLabel('Name').fill('Adv Pushup');
// Scope to dialog and use force click for type selection
await page.locator('div[role="dialog"]').getByRole('button', { name: /Bodyweight/i }).click({ force: true });
await expect(page.getByLabel('Body Weight')).toBeVisible();
await page.getByLabel('Body Weight').fill('50');
await page.getByRole('button', { name: 'Create' }).click();
await page.locator('div[role="dialog"]').getByRole('button', { name: 'Create' }).click();
await page.waitForTimeout(1000);
// Reload and filter
await page.reload();
@@ -215,47 +256,95 @@ test.describe('II. Workout Management', () => {
await expect(page.getByText('Bodyweight', { exact: false }).first()).toBeVisible();
});
test('2.8 B. Exercise Library - Edit Exercise Name', async ({ page, createUniqueUser, request }) => {
const user = await loginAndSetup(page, createUniqueUser);
await request.post('/api/exercises', {
data: { name: 'Typo Name', type: 'STRENGTH' },
headers: { 'Authorization': `Bearer ${user.token}` }
});
await page.reload();
test('2.8 B. Exercise Library - Edit Exercise Name', async ({ page, createUniqueUser }) => {
// Updated to use UI creation for robustness
await loginAndSetup(page, createUniqueUser);
await page.getByRole('button', { name: 'Profile' }).click();
await page.getByRole('button', { name: /Manage Exercises/i }).click();
await page.locator('button:has-text("Manage Exercises")').click();
const row = page.locator('div').filter({ hasText: 'Typo Name' }).last();
await row.locator('button').filter({ has: page.locator('svg.lucide-pencil') }).click();
// Use force click as button might be obstructed or animating
await page.getByRole('button', { name: /New Exercise/i }).click({ force: true });
await expect(page.locator('div[role="dialog"]')).toBeVisible();
await page.locator('div[role="dialog"]').getByLabel('Name').fill('Typo Name');
await expect(page.locator('div[role="dialog"]').getByText('Free Weights & Machines', { exact: false })).toBeVisible();
await page.locator('div[role="dialog"]').getByRole('button', { name: 'Create' }).click();
await page.waitForTimeout(1000);
// Reload and filter
await page.reload();
await page.getByRole('button', { name: 'Profile' }).click();
await page.locator('button:has-text("Manage Exercises")').click();
await page.getByLabel(/Filter by name/i).fill('Typo Name');
await expect(page.getByText('Typo Name')).toBeVisible();
// Filter specifically for the container that has both text and button
const row = page.locator('div')
.filter({ hasText: 'Typo Name' })
.filter({ has: page.getByLabel('Edit Exercise') })
.last();
await expect(row).toBeVisible();
await row.getByLabel('Edit Exercise').click();
await page.locator('div[role="dialog"] input').first().fill('Fixed Name');
await page.getByRole('button', { name: 'Save' }).click();
await page.locator('div[role="dialog"]').getByRole('button', { name: 'Save', exact: true }).click();
// Clear filter to see the renamed exercise
await page.getByLabel(/Filter by name/i).fill('');
await expect(page.getByText('Fixed Name')).toBeVisible();
await expect(page.getByText('Typo Name')).not.toBeVisible();
});
test('2.9 B. Exercise Library - Archive/Unarchive', async ({ page, createUniqueUser, request }) => {
const user = await loginAndSetup(page, createUniqueUser);
await request.post('/api/exercises', {
data: { name: 'Archive Me', type: 'STRENGTH' },
headers: { 'Authorization': `Bearer ${user.token}` }
});
await page.reload();
test('2.9 B. Exercise Library - Archive/Unarchive', async ({ page, createUniqueUser }) => {
// Updated to use UI creation for robustness
await loginAndSetup(page, createUniqueUser);
await page.getByRole('button', { name: 'Profile' }).click();
await page.getByRole('button', { name: /Manage Exercises/i }).click();
await page.locator('button:has-text("Manage Exercises")').click();
const row = page.locator('div').filter({ hasText: 'Archive Me' }).last();
// Use force click as button might be obstructed or animating
await page.getByRole('button', { name: /New Exercise/i }).click({ force: true });
await expect(page.locator('div[role="dialog"]')).toBeVisible();
await page.locator('div[role="dialog"]').getByLabel('Name').fill('Archive Me');
await expect(page.locator('div[role="dialog"]').getByText('Free Weights & Machines', { exact: false })).toBeVisible();
await page.locator('div[role="dialog"]').getByRole('button', { name: 'Create' }).click();
await page.waitForTimeout(1000);
// Reload and filter
await page.reload();
await page.getByRole('button', { name: 'Profile' }).click();
await page.locator('button:has-text("Manage Exercises")').click();
await page.getByLabel(/Filter by name/i).fill('Archive Me');
await expect(page.getByText('Archive Me')).toBeVisible();
const row = page.locator('div.flex.justify-between').filter({ hasText: 'Archive Me' }).last();
// Archive button (box-archive or similar)
await row.locator('button').filter({ has: page.locator('svg.lucide-archive') }).click();
await row.locator('[aria-label="Archive Exercise"]').click();
// It should disappear or fade. "Show Archived" is false by default.
await expect(page.getByText('Archive Me')).not.toBeVisible();
// Toggle Show Archived
await page.getByLabel('Show Archived').check();
// Label might not be linked, so we filter by text and find the adjacent checkbox
await page.locator('div').filter({ hasText: /Show Archived/i }).last().locator('input[type="checkbox"]').check();
await expect(page.getByText('Archive Me')).toBeVisible();
// Unarchive
const archivedRow = page.locator('div')
.filter({ hasText: 'Archive Me' })
.filter({ has: page.getByLabel('Unarchive Exercise') })
.last();
await archivedRow.getByLabel('Unarchive Exercise').click();
// Verify it persists after unchecking "Show Archived"
await page.locator('div').filter({ hasText: /Show Archived/i }).last().locator('input[type="checkbox"]').uncheck();
await expect(page.getByText('Archive Me')).toBeVisible();
});
@@ -280,8 +369,23 @@ test.describe('II. Workout Management', () => {
await expect(page.getByText('IgnoreThatOne')).not.toBeVisible();
});
test.skip('2.11 B. Exercise Library - Capitalization (Mobile)', async ({ page }) => {
// ...
test('2.11 B. Exercise Library - Capitalization (Mobile)', async ({ page, createUniqueUser }) => {
// Simulate Mobile Viewport
await page.setViewportSize({ width: 390, height: 844 }); // iPhone 12 Pro
await loginAndSetup(page, createUniqueUser);
await page.getByRole('button', { name: 'Profile' }).click();
await page.locator('button:has-text("Manage Exercises")').click();
// Use force as FAB might be different on mobile, but text is same
await page.getByRole('button', { name: /New Exercise/i }).click({ force: true });
await expect(page.locator('div[role="dialog"]')).toBeVisible();
// Verify autocapitalize attribute is set to 'words' or 'sentences'
// In ExerciseModal.tsx it is set to 'words'
const nameInput = page.locator('div[role="dialog"]').getByLabel('Name');
await expect(nameInput).toHaveAttribute('autocapitalize', 'words');
});
test('2.12 B. Exercise Library - Unilateral', async ({ page, createUniqueUser }) => {
@@ -289,12 +393,15 @@ test.describe('II. Workout Management', () => {
await page.getByRole('button', { name: 'Profile' }).click();
await page.getByRole('button', { name: /Manage Exercises/i }).click();
await page.getByRole('button', { name: /New Exercise/i }).click();
await page.getByLabel('Name').fill('Single Leg Squat');
await page.getByRole('button', { name: /New Exercise/i }).click({ force: true });
await page.locator('input[type="checkbox"]').first().check();
await expect(page.locator('div[role="dialog"]')).toBeVisible();
await page.locator('div[role="dialog"]').getByLabel('Name').fill('Single Leg Squat');
await page.getByRole('button', { name: 'Create' }).click();
await page.getByLabel(/Unilateral exercise/).check();
await page.locator('div[role="dialog"]').getByRole('button', { name: 'Create' }).click();
await page.waitForTimeout(1000);
// Reload and filter
await page.reload();
@@ -311,12 +418,15 @@ test.describe('II. Workout Management', () => {
await page.getByRole('button', { name: 'Profile' }).click();
await page.getByRole('button', { name: /Manage Exercises/i }).click();
await page.getByRole('button', { name: /New Exercise/i }).click();
await page.getByLabel('Name').fill('Plank Test');
await page.getByRole('button', { name: /New Exercise/i }).click({ force: true });
await page.locator('button').filter({ hasText: /Static/i }).click();
await expect(page.locator('div[role="dialog"]')).toBeVisible();
await page.locator('div[role="dialog"]').getByLabel('Name').fill('Plank Test');
await page.getByRole('button', { name: 'Create' }).click();
await page.locator('div[role="dialog"]').getByRole('button', { name: /Static/i }).click({ force: true });
await page.locator('div[role="dialog"]').getByRole('button', { name: 'Create' }).click();
await page.waitForTimeout(1000);
// Reload and filter
await page.reload();
@@ -349,4 +459,4 @@ async function loginAndSetup(page: any, createUniqueUser: any) {
// Login might already be done or dashboard loaded fast
}
return user;
}
}