feat: add task multi-select on long-press
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import React from 'react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { act, fireEvent, render, screen } from '@testing-library/react';
|
||||
import * as api from '../../api';
|
||||
|
||||
const fixtures = vi.hoisted(() => ({
|
||||
event: {
|
||||
@@ -9,7 +10,16 @@ const fixtures = vi.hoisted(() => ({
|
||||
slug: 'demo-event',
|
||||
event_date: '2026-02-19',
|
||||
event_type_id: null,
|
||||
event_type: null,
|
||||
event_type: {
|
||||
id: 1,
|
||||
slug: 'wedding',
|
||||
name: 'Wedding',
|
||||
name_translations: { de: 'Hochzeit', en: 'Wedding' },
|
||||
icon: null,
|
||||
settings: {},
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
status: 'published',
|
||||
settings: {},
|
||||
},
|
||||
@@ -32,17 +42,19 @@ vi.mock('react-router-dom', () => ({
|
||||
useParams: () => ({ slug: fixtures.event.slug }),
|
||||
}));
|
||||
|
||||
const tMock = (key: string, fallback?: string | Record<string, unknown>) => {
|
||||
if (typeof fallback === 'string') {
|
||||
return fallback;
|
||||
}
|
||||
if (fallback && typeof fallback === 'object' && typeof fallback.defaultValue === 'string') {
|
||||
return fallback.defaultValue;
|
||||
}
|
||||
return key;
|
||||
};
|
||||
|
||||
vi.mock('react-i18next', () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key: string, fallback?: string | Record<string, unknown>) => {
|
||||
if (typeof fallback === 'string') {
|
||||
return fallback;
|
||||
}
|
||||
if (fallback && typeof fallback === 'object' && typeof fallback.defaultValue === 'string') {
|
||||
return fallback.defaultValue;
|
||||
}
|
||||
return key;
|
||||
},
|
||||
t: tMock,
|
||||
}),
|
||||
}));
|
||||
|
||||
@@ -50,10 +62,12 @@ vi.mock('../hooks/useBackNavigation', () => ({
|
||||
useBackNavigation: () => backMock,
|
||||
}));
|
||||
|
||||
const selectEventMock = vi.fn();
|
||||
|
||||
vi.mock('../../context/EventContext', () => ({
|
||||
useEventContext: () => ({
|
||||
activeEvent: fixtures.event,
|
||||
selectEvent: vi.fn(),
|
||||
selectEvent: selectEventMock,
|
||||
}),
|
||||
}));
|
||||
|
||||
@@ -123,8 +137,17 @@ vi.mock('@tamagui/switch', () => ({
|
||||
}));
|
||||
|
||||
vi.mock('@tamagui/list-item', () => ({
|
||||
ListItem: ({ title, subTitle, iconAfter }: { title?: React.ReactNode; subTitle?: React.ReactNode; iconAfter?: React.ReactNode }) => (
|
||||
<div>
|
||||
ListItem: ({
|
||||
title,
|
||||
subTitle,
|
||||
iconAfter,
|
||||
...rest
|
||||
}: {
|
||||
title?: React.ReactNode;
|
||||
subTitle?: React.ReactNode;
|
||||
iconAfter?: React.ReactNode;
|
||||
}) => (
|
||||
<div {...rest}>
|
||||
{title}
|
||||
{subTitle}
|
||||
{iconAfter}
|
||||
@@ -148,6 +171,22 @@ vi.mock('@tamagui/button', () => ({
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('@tamagui/checkbox', () => ({
|
||||
Checkbox: Object.assign(
|
||||
({ children, checked, onCheckedChange, 'aria-label': ariaLabel }: any) => (
|
||||
<button
|
||||
type="button"
|
||||
aria-label={ariaLabel}
|
||||
aria-pressed={checked}
|
||||
onClick={() => onCheckedChange?.(!checked)}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
),
|
||||
{ Indicator: ({ children }: { children: React.ReactNode }) => <span>{children}</span> },
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('@tamagui/radio-group', () => ({
|
||||
RadioGroup: Object.assign(({ children }: { children: React.ReactNode }) => <div>{children}</div>, {
|
||||
Item: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
@@ -233,5 +272,22 @@ describe('MobileEventTasksPage', () => {
|
||||
expect(screen.getByText('Tasks total')).toBeInTheDocument();
|
||||
expect(screen.getByText('Quick jump')).toBeInTheDocument();
|
||||
expect(screen.getByText('Assigned')).toBeInTheDocument();
|
||||
|
||||
expect(api.getTaskCollections).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ event_type: 'wedding' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('enters selection mode on long press', async () => {
|
||||
render(<MobileEventTasksPage />);
|
||||
|
||||
const task = await screen.findByText('Task A');
|
||||
await act(async () => {
|
||||
fireEvent.pointerDown(task);
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
fireEvent.pointerUp(task);
|
||||
});
|
||||
|
||||
expect((await screen.findAllByText('Auswahl löschen')).length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user