mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-13 15:51:00 +00:00
31859651d7
Every help screen checked against the v5 redesign. Tours is documented for the first time, as a screen of its own with twelve screens under it, and notifications get help of their own. All pictures are taken again on a realistic demo trip, with short loops where a still cannot show the motion. The English is plain and every language is written naturally rather than word for word. The switcher shows two levels at most, a screen's overview lists its sub-screens as cards above its guides, each wiki page is linked once, and the help sidebar is wider. Fixes found along the way: Save to Collection keeps a tour's route, a track dropped on the places column opens the Tours import, tour Share on desktop, the unsaved tour draft lives on the account, a route click no longer adds an end point, Trip places leaves the trip's tours out, Escape closes a stage's day menu, confirms before destructive deletes, DWD warnings sharing one id kept apart, a booking's date moves with it, and smaller fixes across notifications, bookings, the day plan, stays, Atlas, Collections, Vacay and the admin screens.
106 lines
4.9 KiB
TypeScript
106 lines
4.9 KiB
TypeScript
// FE-FILES-ROW-001 to FE-FILES-ROW-006
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { render, screen } from '../../../tests/helpers/render';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { buildPlace, buildReservation, buildTrip, buildTripFile } from '../../../tests/helpers/factories';
|
|
import { downloadFile } from '../../utils/fileDownload';
|
|
import type { TripFile } from '../../types';
|
|
import type { FileManagerState } from './useFileManager';
|
|
import { FileRow } from './FileManagerRow';
|
|
|
|
vi.mock('../../utils/fileDownload', () => ({ downloadFile: vi.fn(async () => {}) }));
|
|
|
|
const handlers = {
|
|
handleStar: vi.fn(),
|
|
handleRestore: vi.fn(),
|
|
handlePermanentDelete: vi.fn(),
|
|
handleDelete: vi.fn(),
|
|
openFile: vi.fn(),
|
|
setAssignFileId: vi.fn(),
|
|
};
|
|
|
|
const labels: Record<string, string> = {
|
|
'common.open': 'Open', 'common.delete': 'Delete', 'files.download': 'Download', 'files.star': 'Star', 'files.unstar': 'Unstar',
|
|
'files.assign': 'Assign', 'files.restore': 'Restore', 'files.sourcePlan': 'Day Plan', 'files.sourceBooking': 'Booking',
|
|
'files.sourceTransport': 'Transport', 'files.sourceCollab': 'From Collab Notes',
|
|
};
|
|
|
|
function renderRow(file: TripFile, { isTrash = false, allowed = true } = {}) {
|
|
const state = {
|
|
...handlers,
|
|
places: [buildPlace({ id: 71, name: 'Louvre' })],
|
|
reservations: [buildReservation({ id: 81, title: 'Shinkansen', type: 'train' }), buildReservation({ id: 82, title: '', type: 'restaurant' })],
|
|
t: (k: string) => labels[k] ?? k,
|
|
locale: 'en-US',
|
|
can: () => allowed,
|
|
trip: buildTrip({ id: 1 }),
|
|
} as unknown as FileManagerState;
|
|
return render(<FileRow {...state} file={file} isTrash={isTrash} />);
|
|
}
|
|
|
|
beforeEach(() => {
|
|
Object.values(handlers).forEach(fn => fn.mockClear());
|
|
vi.mocked(downloadFile).mockClear();
|
|
});
|
|
|
|
describe('FileRow', () => {
|
|
it('FE-FILES-ROW-001: opens the file from its tile, its name and the Open action', async () => {
|
|
const user = userEvent.setup();
|
|
const file = buildTripFile({ original_name: 'ticket.pdf' });
|
|
renderRow(file);
|
|
await user.click(screen.getByRole('button', { name: 'Open' }));
|
|
await user.click(screen.getAllByRole('button', { name: 'ticket.pdf' })[0]);
|
|
expect(handlers.openFile).toHaveBeenCalledTimes(2);
|
|
expect(handlers.openFile).toHaveBeenCalledWith(file);
|
|
});
|
|
|
|
it('FE-FILES-ROW-002: Download fetches the file under its own name', async () => {
|
|
const user = userEvent.setup();
|
|
const file = buildTripFile({ original_name: 'ticket.pdf', url: '/api/trips/1/files/9/download' });
|
|
renderRow(file);
|
|
await user.click(screen.getByRole('button', { name: 'Download' }));
|
|
expect(downloadFile).toHaveBeenCalledWith('/api/trips/1/files/9/download', 'ticket.pdf');
|
|
});
|
|
|
|
it('FE-FILES-ROW-003: star, assign and delete reach their handlers', async () => {
|
|
const user = userEvent.setup();
|
|
const file = buildTripFile({ id: 555, starred: 1 } as never);
|
|
renderRow(file);
|
|
await user.click(screen.getByRole('button', { name: 'Unstar' }));
|
|
await user.click(screen.getByRole('button', { name: 'Assign' }));
|
|
await user.click(screen.getByRole('button', { name: 'Delete' }));
|
|
expect(handlers.handleStar).toHaveBeenCalledWith(555);
|
|
expect(handlers.setAssignFileId).toHaveBeenCalledWith(555);
|
|
expect(handlers.handleDelete).toHaveBeenCalledWith(555);
|
|
});
|
|
|
|
it('FE-FILES-ROW-004: without the rights there is nothing to assign or delete', () => {
|
|
renderRow(buildTripFile({}), { allowed: false });
|
|
expect(screen.queryByRole('button', { name: 'Star' })).toBeNull();
|
|
expect(screen.queryByRole('button', { name: 'Assign' })).toBeNull();
|
|
expect(screen.queryByRole('button', { name: 'Delete' })).toBeNull();
|
|
});
|
|
|
|
it('FE-FILES-ROW-005: a file in the trash restores or goes for good, and does not open', async () => {
|
|
const user = userEvent.setup();
|
|
const file = buildTripFile({ id: 556, original_name: 'old.pdf' });
|
|
renderRow(file, { isTrash: true });
|
|
expect(screen.getAllByRole('button', { name: 'old.pdf' })[0]).toBeDisabled();
|
|
await user.click(screen.getByRole('button', { name: 'Restore' }));
|
|
await user.click(screen.getByRole('button', { name: 'Delete' }));
|
|
expect(handlers.handleRestore).toHaveBeenCalledWith(556);
|
|
expect(handlers.handlePermanentDelete).toHaveBeenCalledWith(556);
|
|
expect(screen.queryByRole('button', { name: 'Open' })).toBeNull();
|
|
});
|
|
|
|
it('FE-FILES-ROW-006: says where the file came from: a place, a transport, a booking, a note', () => {
|
|
const file = buildTripFile({ place_id: 71, reservation_id: 81, linked_reservation_ids: [82], note_id: 3, description: 'Seat map', file_size: 2048 } as never);
|
|
renderRow(file);
|
|
expect(screen.getByText('Louvre')).toBeInTheDocument();
|
|
expect(screen.getByText('Shinkansen')).toBeInTheDocument();
|
|
expect(screen.getByText('Booking')).toBeInTheDocument();
|
|
expect(screen.getByText('From Collab Notes')).toBeInTheDocument();
|
|
expect(screen.getByText('Seat map')).toBeInTheDocument();
|
|
});
|
|
});
|