e3823ce470
Add an end-to-end and unit test suite for the SvelteKit frontend:
- Playwright e2e specs (tests/e2e/spa) with a throwaway container stack,
codegen scenarios, and an Istanbul-based coverage report pipeline.
- Vitest unit tests across API endpoints, components, stores and composables.
- `data-testid` hooks on interactive elements (AppShell, FileViewer,
ShareDialog, search, photos, files breadcrumbs, login/Nextcloud flows,
public share pages) so the e2e suite can target them deterministically.
- Serve the SPA app-shell CSP from a <meta> policy (svelte.config.js) plus a
middleware that skips the CSP header on HTML; move the Nextcloud Login Flow
v2 grant page to the SvelteKit /nextcloud/login route.
- `just front-codegen` recipe and start-server-spa.sh harness.
Make the test environment robust and consistent:
- Install a deterministic in-memory localStorage/sessionStorage in the Vitest
setup so storage behaves identically across Node versions (Node 26 ships a
native Web Storage global that otherwise shadows jsdom's).
- Pin devenv to Node 26 + PostgreSQL 18 and pin every CI job to Node 26.3.0
so the dev shell and CI run the same toolchain versions.
Repair the API/WebDAV (hurl) suite, which had drifted from the backend:
- Migrate the removed `/api/folders/{id}/listing` endpoint to `/resources`
(cursor-paginated `{items:[{resource_type,resource}]}` shape) across the
batch-copy, grants, nested-group, and WebDAV NC tests + the dav_helpers
wipe routine.
- Stop photos_etag from uploading the dedup-tracked fixture so the dedup
blob-lifecycle test can own its content-addressed blob exclusively.
- dedup_create now asserts the idempotent same-content re-upload (201 +
existing file id) instead of the stale 409 expectation.
Generated coverage reports, nyc output and the e2e server runtime data dir
are gitignored rather than committed.
105 lines
4.2 KiB
TypeScript
105 lines
4.2 KiB
TypeScript
import { test, expect } from './coverage-helpers';
|
|
import { apiLogin, apiCreateFolder, apiUploadFile, SAMPLE_FILES } from '../scenarios/helpers';
|
|
|
|
/**
|
|
* File-browser CRUD against the SvelteKit `/files` route — the single largest
|
|
* source file. Drives the toolbar, the right-click context menu, and the
|
|
* prompt/confirm dialogs, which also exercises the files/folders/favorites
|
|
* endpoint modules.
|
|
*/
|
|
test.beforeEach(async ({ page }) => {
|
|
await apiLogin(page);
|
|
});
|
|
|
|
function uniq(prefix: string): string {
|
|
return `${prefix}-${Date.now()}-${Math.floor(Math.random() * 1e6)}`;
|
|
}
|
|
|
|
test('create a folder via the toolbar', async ({ page }) => {
|
|
const name = uniq('Created');
|
|
await page.goto('/files');
|
|
await page.getByTestId('files-new-folder-btn').click();
|
|
await page.getByTestId('dialog-host-prompt-input').fill(name);
|
|
await page.getByTestId('dialog-host-submit-btn').click();
|
|
await expect(page.getByTestId(name)).toBeVisible({ timeout: 15_000 });
|
|
});
|
|
|
|
test('rename a folder via the context menu', async ({ page }) => {
|
|
const before = uniq('Rename');
|
|
const after = uniq('Renamed');
|
|
await apiCreateFolder(page, before);
|
|
await page.goto('/files');
|
|
await expect(page.getByTestId(before)).toBeVisible({ timeout: 15_000 });
|
|
|
|
await page.getByTestId(before).click({ button: 'right' });
|
|
await page.getByTestId('files-ctx-rename-item').click();
|
|
const input = page.getByTestId('dialog-host-prompt-input');
|
|
await input.fill(after);
|
|
await page.getByTestId('dialog-host-submit-btn').click();
|
|
|
|
await expect(page.getByTestId(after)).toBeVisible({ timeout: 15_000 });
|
|
await expect(page.getByTestId(before)).toHaveCount(0);
|
|
});
|
|
|
|
test('favorite a folder via the context menu', async ({ page }) => {
|
|
const name = uniq('Fav');
|
|
await apiCreateFolder(page, name);
|
|
await page.goto('/files');
|
|
await expect(page.getByTestId(name)).toBeVisible({ timeout: 15_000 });
|
|
|
|
await page.getByTestId(name).click({ button: 'right' });
|
|
await page.getByTestId('files-ctx-favorite-item').click();
|
|
|
|
// Action completed — the row is still present and the menu has closed.
|
|
await expect(page.getByTestId('files-context-menu')).toHaveCount(0);
|
|
await expect(page.getByTestId(name)).toBeVisible();
|
|
});
|
|
|
|
test('delete a folder via the context menu', async ({ page }) => {
|
|
const name = uniq('Delete');
|
|
await apiCreateFolder(page, name);
|
|
await page.goto('/files');
|
|
await expect(page.getByTestId(name)).toBeVisible({ timeout: 15_000 });
|
|
|
|
await page.getByTestId(name).click({ button: 'right' });
|
|
await page.getByTestId('files-ctx-delete-item').click();
|
|
await page.getByTestId('dialog-host-confirm-btn').click();
|
|
|
|
await expect(page.getByTestId(name)).toHaveCount(0, { timeout: 15_000 });
|
|
});
|
|
|
|
test('upload a file via the hidden file input', async ({ page }) => {
|
|
const folder = uniq('Uploads');
|
|
const created = await apiCreateFolder(page, folder);
|
|
// Navigate straight into the (empty) folder by ID (the route keys on folder
|
|
// id, not name) — avoids the crowded root listing and click ambiguity.
|
|
await page.goto(`/files/${created.id}`);
|
|
await expect(page.getByTestId('files-upload-file-input')).toBeAttached({ timeout: 15_000 });
|
|
// Now inside the folder; upload a text file by setting the hidden input.
|
|
const f = SAMPLE_FILES.text();
|
|
await page.getByTestId('files-upload-file-input').setInputFiles({
|
|
name: f.name,
|
|
mimeType: f.mimeType,
|
|
buffer: f.body,
|
|
});
|
|
await expect(page.getByTestId(f.name)).toBeVisible({ timeout: 15_000 });
|
|
});
|
|
|
|
test('open a text file in the viewer', async ({ page }) => {
|
|
const folderName = uniq('Viewer');
|
|
const folder = await apiCreateFolder(page, folderName);
|
|
const f = SAMPLE_FILES.markdown();
|
|
await apiUploadFile(page, f, folder.id);
|
|
|
|
await page.goto('/files');
|
|
await page.getByTestId(folderName).click();
|
|
await expect(page.getByTestId(f.name)).toBeVisible({ timeout: 15_000 });
|
|
|
|
// Open via the context menu, then assert the inline viewer dialog appears.
|
|
await page.getByTestId(f.name).click({ button: 'right' });
|
|
await page.getByTestId('files-ctx-file-open-item').click();
|
|
await expect(page.getByTestId('file-viewer-dialog')).toBeVisible({ timeout: 15_000 });
|
|
await page.getByTestId('file-viewer-close-btn').click();
|
|
await expect(page.getByTestId('file-viewer-dialog')).toHaveCount(0);
|
|
});
|