test(front): correct frontend test + end2end tests

This commit is contained in:
Edouard Vanbelle
2026-07-20 12:50:19 +02:00
parent 569b67caac
commit 4f3309e087
9 changed files with 82 additions and 47 deletions
+14 -10
View File
@@ -5,12 +5,13 @@ const { confirmDialog, promptDialog } = vi.hoisted(() => ({
confirmDialog: vi.fn(),
promptDialog: vi.fn()
}));
vi.mock('$lib/api/endpoints/recent', () => ({ clearRecent: vi.fn(), fetchRecentPage: vi.fn() }));
vi.mock('$lib/api/endpoints/recent', () => ({
clearRecent: vi.fn(),
fetchRecentPage: vi.fn(),
removeFromRecent: vi.fn()
}));
vi.mock('$lib/api/endpoints/favorites', () => ({
addFavorite: vi.fn(),
dateBucket: () => 'Today',
fetchFavoritesPage: vi.fn(async () => ({ items: [], next_cursor: null })),
removeFavorite: vi.fn(),
resolveOwnerName: vi.fn(async () => 'me'),
sizeBucket: () => 'Small',
typeLabel: () => 'File'
@@ -23,8 +24,7 @@ vi.mock('$lib/api/endpoints/files', () => ({
vi.mock('$lib/api/endpoints/folders', () => ({ renameFolder: vi.fn(), deleteFolder: vi.fn() }));
vi.mock('$lib/stores/dialogs.svelte', () => ({ confirmDialog, promptDialog }));
import { fetchRecentPage, clearRecent } from '$lib/api/endpoints/recent';
import { addFavorite } from '$lib/api/endpoints/favorites';
import { fetchRecentPage, clearRecent, removeFromRecent } from '$lib/api/endpoints/recent';
import { deleteFile } from '$lib/api/endpoints/files';
import RecentPage from './+page.svelte';
@@ -79,13 +79,17 @@ it('clears recent activity after confirmation', async () => {
await waitFor(() => expect(clearRecent).toHaveBeenCalled());
});
it('favorites a recent row via the star button', async () => {
it('removes a recent row via the broom button', async () => {
// Recent no longer surfaces a favorite star (users go to the item's
// real home for that). The per-row affordance is now a broom that
// calls `DELETE /api/recent/{kind}/{id}` — verified end-to-end via
// the `removeFromRecent` mock.
withOneFile();
m(addFavorite).mockResolvedValue(undefined);
m(removeFromRecent).mockResolvedValue(undefined);
render(RecentPage);
await screen.findByText('notes.txt');
await fireEvent.click(screen.getByTestId('resource-list-favorite-r1-btn'));
await waitFor(() => expect(addFavorite).toHaveBeenCalledWith('file', 'r1'));
await fireEvent.click(screen.getByTestId('recent-remove-btn-r1'));
await waitFor(() => expect(removeFromRecent).toHaveBeenCalledWith('file', 'r1'));
});
it('batch-deletes selected recent items after confirmation', async () => {