Admin: Zgloszenie #9 - formularz cwiczenia mowi na zywo, czego brakuje (podpowiedz 'Uzupelnic wymagane pola: Nazwa, Glowny miesien' nad przyciskami, aktualizowana w trakcie wypelniania: dotad 'Dodaj' byl glucho blokowany bez wskazania brakujacego pola; submit dodatkowo odporny na same spacje w nazwie; komunikat = etykiety pol z i18n, nowe klucze fillRequiredFields pl/en; bez zmian w API; + unit i e2e)
This commit is contained in:
@@ -49,6 +49,7 @@
|
||||
"mistakesLabel": "Common mistakes (optional)",
|
||||
"mistakesPh": "What to avoid when performing.",
|
||||
"chooseOption": "— select —",
|
||||
"fillRequiredFields": "Fill in the required fields: {{fields}}.",
|
||||
"muscleNotInCatalog": "{{name}} (not in area catalog)",
|
||||
"typeStrength": "Strength",
|
||||
"typeCardio": "Cardio",
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
"mistakesLabel": "Najczęstsze błędy (opcjonalnie)",
|
||||
"mistakesPh": "Czego unikać przy wykonaniu.",
|
||||
"chooseOption": "— wybierz —",
|
||||
"fillRequiredFields": "Uzupełnij wymagane pola: {{fields}}.",
|
||||
"muscleNotInCatalog": "{{name}} (brak w katalogu obszarów)",
|
||||
"typeStrength": "Siłowe",
|
||||
"typeCardio": "Cardio",
|
||||
|
||||
@@ -248,7 +248,16 @@ export default function Exercises() {
|
||||
onError: (e) => setFormError((e as Error).message),
|
||||
});
|
||||
|
||||
function missingRequired(): string[] {
|
||||
const missing: string[] = [];
|
||||
if (!form.name.trim()) missing.push(t('nameLabel'));
|
||||
if (!form.primaryMuscle) missing.push(t('primaryMuscle'));
|
||||
return missing;
|
||||
}
|
||||
|
||||
function submit() {
|
||||
if (missingRequired().length > 0) return;
|
||||
setFormError(null);
|
||||
// zmiana flag u ćwiczenia używanego w planach zmienia formularz zapisu w aplikacji
|
||||
if (flagsChanged() && (editing?.planExercisesCount ?? 0) > 0) {
|
||||
setConfirmFlagChange(true);
|
||||
@@ -322,6 +331,7 @@ export default function Exercises() {
|
||||
const secondaryOptions = muscleOptions(areas, form.secondaryMuscles, (name) =>
|
||||
t('muscleNotInCatalog', { name }),
|
||||
);
|
||||
const missingFields = missingRequired();
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -556,11 +566,16 @@ export default function Exercises() {
|
||||
/>
|
||||
</Field>
|
||||
{formError && <ErrorText>{formError}</ErrorText>}
|
||||
{missingFields.length > 0 && (
|
||||
<p role="status" className="text-dim text-[0.875rem]">
|
||||
{t('fillRequiredFields', { fields: missingFields.join(', ') })}
|
||||
</p>
|
||||
)}
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="secondary" onClick={() => setFormOpen(false)}>
|
||||
{t('common:cancel')}
|
||||
</Button>
|
||||
<Button onClick={submit} disabled={save.isPending || !form.name || !form.primaryMuscle}>
|
||||
<Button onClick={submit} disabled={save.isPending || missingFields.length > 0}>
|
||||
{editing ? t('common:save') : t('common:add')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -246,6 +246,38 @@ describe('admin Exercises page', () => {
|
||||
expect(within(typeSelect).getByRole('option', { name: 'Cardio' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('formularz ćwiczenia na żywo wskazuje brakujące wymagane pola', async () => {
|
||||
const { requests } = mockApi();
|
||||
const user = userEvent.setup();
|
||||
renderExercises();
|
||||
await screen.findByText('Wyciskanie sztangi leżąc');
|
||||
|
||||
openCreateDialog();
|
||||
const dialog = await screen.findByRole('dialog');
|
||||
// podpowiedź widoczna od razu, bez klikania „Dodaj”
|
||||
expect(within(dialog).getByRole('status')).toHaveTextContent(
|
||||
'Uzupełnij wymagane pola: Nazwa, Główny mięsień.',
|
||||
);
|
||||
const addBtn = within(dialog).getByRole('button', { name: 'Dodaj' });
|
||||
expect(addBtn).toBeDisabled();
|
||||
|
||||
await user.type(
|
||||
within(dialog).getByPlaceholderText('np. Wyciskanie sztangi leżąc'),
|
||||
'Bieganie',
|
||||
);
|
||||
expect(within(dialog).getByRole('status')).toHaveTextContent(
|
||||
'Uzupełnij wymagane pola: Główny mięsień.',
|
||||
);
|
||||
|
||||
const [primarySelect] = within(dialog).getAllByRole('combobox');
|
||||
await user.selectOptions(primarySelect, 'quads');
|
||||
expect(within(dialog).queryByRole('status')).not.toBeInTheDocument();
|
||||
expect(addBtn).toBeEnabled();
|
||||
|
||||
// kliknięcia z brakami nie wysyłały zapytania
|
||||
expect(requests.some((r) => r.method === 'POST')).toBe(false);
|
||||
});
|
||||
|
||||
it('utworzenie ćwiczenia cardio z presetu wysyła odpowiednie flagi', async () => {
|
||||
const { requests } = mockApi();
|
||||
const user = userEvent.setup();
|
||||
|
||||
@@ -37,6 +37,25 @@ test('przycisk „Nowe ćwiczenie” w menu kontekstowym otwiera modal', async (
|
||||
await expect(dialog.locator('option', { hasText: 'Nogi (legs)' })).toBeAttached();
|
||||
});
|
||||
|
||||
test('formularz ćwiczenia na żywo wskazuje brakujące wymagane pola', async ({ page }) => {
|
||||
mockApi(page);
|
||||
await loginAsAdmin(page);
|
||||
await page.getByRole('link', { name: 'Rodzaje ćwiczeń' }).click();
|
||||
await page.getByRole('button', { name: 'Nowe ćwiczenie' }).click();
|
||||
const dialog = page.getByRole('dialog');
|
||||
await expect(dialog.getByRole('status')).toHaveText(
|
||||
'Uzupełnij wymagane pola: Nazwa, Główny mięsień.',
|
||||
);
|
||||
await expect(dialog.getByRole('button', { name: 'Dodaj', exact: true })).toBeDisabled();
|
||||
|
||||
await dialog.getByPlaceholder('np. Wyciskanie sztangi leżąc').fill('Bieganie');
|
||||
await expect(dialog.getByRole('status')).toHaveText('Uzupełnij wymagane pola: Główny mięsień.');
|
||||
|
||||
await dialog.locator('select').first().selectOption('legs');
|
||||
await expect(dialog.getByRole('status')).not.toBeVisible();
|
||||
await expect(dialog.getByRole('button', { name: 'Dodaj', exact: true })).toBeEnabled();
|
||||
});
|
||||
|
||||
test('utworzenie ćwiczenia cardio z presetu wysyła flagi cardio', async ({ page }) => {
|
||||
mockApi(page);
|
||||
await loginAsAdmin(page);
|
||||
|
||||
Reference in New Issue
Block a user