Offerings: mobiele FAB en icon-only categorieënknop onder sm (CMS-U8)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Link } from '@tanstack/react-router';
|
||||
import { Package } from 'lucide-react';
|
||||
import { Package, Plus, Tags } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { OfferingsList } from '../components/OfferingsList';
|
||||
import { DeleteOfferingDialog } from '../components/DeleteOfferingDialog';
|
||||
@@ -20,21 +20,35 @@ export function OfferingsListPage() {
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-4 p-4">
|
||||
<div className="space-y-4 p-4 pb-24 sm:pb-4" data-testid="offerings-page">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-2xl font-semibold" data-testid="offerings-title">
|
||||
{t('offerings.title')}
|
||||
</h1>
|
||||
<div className="flex items-center gap-2">
|
||||
{/* From sm up: text buttons. Below sm: icon-only categories button; the add action is the FAB below. */}
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="size-11 sm:hidden"
|
||||
aria-label={t('offerings.categories.manageButton')}
|
||||
title={t('offerings.categories.manageButton')}
|
||||
data-testid="offerings-categories-icon-button"
|
||||
onClick={() => setCategoriesOpen(true)}
|
||||
>
|
||||
<Tags className="size-5" aria-hidden="true" />
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
className="hidden sm:inline-flex"
|
||||
data-testid="offerings-categories-button"
|
||||
onClick={() => setCategoriesOpen(true)}
|
||||
>
|
||||
{t('offerings.categories.manageButton')}
|
||||
</Button>
|
||||
<Button asChild data-testid="offerings-add-button">
|
||||
<Button asChild className="hidden sm:inline-flex" data-testid="offerings-add-button">
|
||||
<Link to="/offerings/new">{t('offerings.addButton')}</Link>
|
||||
</Button>
|
||||
</div>
|
||||
@@ -62,6 +76,16 @@ export function OfferingsListPage() {
|
||||
<OfferingsList offerings={offerings} onDeleteRequested={setOfferingPendingDelete} />
|
||||
)}
|
||||
|
||||
<Link
|
||||
to="/offerings/new"
|
||||
aria-label={t('offerings.addButton')}
|
||||
title={t('offerings.addButton')}
|
||||
data-testid="offerings-add-fab"
|
||||
className="fixed bottom-[max(1rem,env(safe-area-inset-bottom))] right-[max(1rem,env(safe-area-inset-right))] z-40 flex size-14 items-center justify-center rounded-full bg-primary text-primary-foreground shadow-lg transition-colors hover:bg-primary/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 sm:hidden"
|
||||
>
|
||||
<Plus className="size-6" aria-hidden="true" />
|
||||
</Link>
|
||||
|
||||
<CategoriesDialog open={categoriesOpen} onOpenChange={setCategoriesOpen} />
|
||||
|
||||
<DeleteOfferingDialog
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
||||
import { screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { renderApp, mockAuthenticated } from '@/test/utils';
|
||||
import { resetMockOfferings } from '@/features/offerings/mocks/handlers';
|
||||
import { _resetSetupStatusCache } from '@/router';
|
||||
import i18n from '@/i18n/config';
|
||||
|
||||
const LONG = { timeout: 10000 };
|
||||
|
||||
// jsdom does not evaluate media queries, so the breakpoint behaviour is checked on the Tailwind classes:
|
||||
// `sm:hidden` = only below 640px, `hidden sm:inline-flex` = only from 640px up.
|
||||
beforeEach(() => {
|
||||
_resetSetupStatusCache();
|
||||
resetMockOfferings();
|
||||
mockAuthenticated();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await i18n.changeLanguage('en');
|
||||
});
|
||||
|
||||
describe('Offerings page on small and large screens', () => {
|
||||
it('has a floating add button that is only shown below sm, at least 44px, in the safe area', async () => {
|
||||
renderApp('/offerings');
|
||||
const fab = await screen.findByTestId('offerings-add-fab', {}, LONG);
|
||||
|
||||
expect(fab).toHaveAttribute('href', '/offerings/new');
|
||||
expect(fab).toHaveAccessibleName('Add Offering');
|
||||
expect(fab.className).toContain('sm:hidden');
|
||||
expect(fab.className).toContain('fixed');
|
||||
expect(fab.className).toContain('right-[max(1rem,env(safe-area-inset-right))]');
|
||||
expect(fab.className).toContain('bottom-[max(1rem,env(safe-area-inset-bottom))]');
|
||||
expect(fab.className).toContain('size-14'); // 56px, above the 44px minimum
|
||||
expect(fab.querySelector('svg')).toHaveAttribute('aria-hidden', 'true');
|
||||
});
|
||||
|
||||
it('shows the text add button only from sm up', async () => {
|
||||
renderApp('/offerings');
|
||||
const button = await screen.findByTestId('offerings-add-button', {}, LONG);
|
||||
|
||||
expect(button.className).toContain('hidden');
|
||||
expect(button.className).toContain('sm:inline-flex');
|
||||
expect(button).toHaveTextContent('Add Offering');
|
||||
});
|
||||
|
||||
it('has an icon-only categories button below sm with an accessible name and tooltip, text button from sm up', async () => {
|
||||
renderApp('/offerings');
|
||||
const icon = await screen.findByTestId('offerings-categories-icon-button', {}, LONG);
|
||||
const text = screen.getByTestId('offerings-categories-button');
|
||||
|
||||
expect(icon).toHaveAccessibleName('Manage categories');
|
||||
expect(icon).toHaveAttribute('title', 'Manage categories');
|
||||
expect(icon.className).toContain('sm:hidden');
|
||||
expect(icon.className).toContain('size-11'); // 44px
|
||||
expect(icon).toHaveTextContent('');
|
||||
expect(text.className).toContain('hidden');
|
||||
expect(text.className).toContain('sm:inline-flex');
|
||||
expect(text).toHaveTextContent('Manage categories');
|
||||
});
|
||||
|
||||
it('keeps extra bottom space below sm so the FAB does not cover the last row', async () => {
|
||||
renderApp('/offerings');
|
||||
const page = await screen.findByTestId('offerings-page', {}, LONG);
|
||||
|
||||
expect(page.className).toContain('pb-24');
|
||||
expect(page.className).toContain('sm:pb-4');
|
||||
});
|
||||
|
||||
it('opens the categories dialog from the icon button', async () => {
|
||||
renderApp('/offerings');
|
||||
await userEvent.click(
|
||||
await screen.findByTestId('offerings-categories-icon-button', {}, LONG),
|
||||
);
|
||||
|
||||
expect(await screen.findByRole('dialog')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('uses Dutch names when the language is Dutch', async () => {
|
||||
await i18n.changeLanguage('nl');
|
||||
renderApp('/offerings');
|
||||
|
||||
expect(await screen.findByTestId('offerings-add-fab', {}, LONG)).toHaveAccessibleName(
|
||||
'Aanbieding toevoegen',
|
||||
);
|
||||
expect(screen.getByTestId('offerings-categories-icon-button')).toHaveAccessibleName(
|
||||
'Categorieën beheren',
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user