From 80b60fb6a1b179533892216550becdee422a4f09 Mon Sep 17 00:00:00 2001 From: Johannes Fleck Date: Mon, 23 Nov 2026 16:45:58 +0100 Subject: [PATCH 1/5] refactor(ui): Move popover-position into the ui layer ui/ components may only import from ui/, and the upcoming DropdownMenu needs the anchor positioning fallback. --- src/lib/components/DateTimePicker.svelte | 2 +- src/lib/components/storage/BucketSelect.svelte | 2 +- src/lib/components/{ => ui}/popover-position.ts | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/lib/components/{ => ui}/popover-position.ts (100%) diff --git a/src/lib/components/DateTimePicker.svelte b/src/lib/components/DateTimePicker.svelte index a3b47531..e6efcbe6 100644 --- a/src/lib/components/DateTimePicker.svelte +++ b/src/lib/components/DateTimePicker.svelte @@ -9,7 +9,7 @@ positionPopoverRelativeToTrigger, supportsAnchorPositioning, trackPopover - } from '$lib/components/popover-position.js'; + } from '$lib/components/ui/popover-position.js'; import IconCalendar from 'virtual:icons/material-symbols/calendar-today'; import IconChevronLeft from 'virtual:icons/material-symbols/chevron-left'; import IconChevronRight from 'virtual:icons/material-symbols/chevron-right'; diff --git a/src/lib/components/storage/BucketSelect.svelte b/src/lib/components/storage/BucketSelect.svelte index 75ca4bab..ab684d9a 100644 --- a/src/lib/components/storage/BucketSelect.svelte +++ b/src/lib/components/storage/BucketSelect.svelte @@ -1,6 +1,6 @@ + + + + + + + diff --git a/src/lib/components/ui/DropdownMenu.svelte.spec.ts b/src/lib/components/ui/DropdownMenu.svelte.spec.ts new file mode 100644 index 00000000..693543b7 --- /dev/null +++ b/src/lib/components/ui/DropdownMenu.svelte.spec.ts @@ -0,0 +1,137 @@ +import { page, userEvent } from 'vitest/browser'; +import { describe, expect, it, vi } from 'vitest'; +import { render } from 'vitest-browser-svelte'; +import IconMore from 'virtual:icons/material-symbols/more-horiz'; +import IconEdit from 'virtual:icons/material-symbols/edit'; +import IconDelete from 'virtual:icons/material-symbols/delete'; +import DropdownMenu from './DropdownMenu.svelte'; +import type { ContextMenuAction } from './ContextMenu.svelte'; + +const actions: ContextMenuAction[] = [ + { key: 'edit', icon: IconEdit, label: 'Edit', href: '#edit' }, + { key: 'delete', icon: IconDelete, label: 'Delete', class: 'text-error' }, + { key: 'secret', icon: IconDelete, label: 'Secret', hidden: true }, + { key: 'locked', icon: IconDelete, label: 'Locked', disabled: true } +]; + +function renderMenu() { + const onaction = vi.fn(); + // Away from the left edge, so the end-aligned menu has room. + render(DropdownMenu, { + label: 'Options', + icon: IconMore, + actions, + onaction, + triggerClass: 'ml-96' + }); + return { onaction, trigger: page.getByRole('button', { name: 'Options' }) }; +} + +describe('DropdownMenu', () => { + it('opens below its trigger, aligned to its end, and focuses the first item', async () => { + const { trigger } = renderMenu(); + await expect.element(page.getByRole('menu', { includeHidden: true })).not.toBeVisible(); + + await trigger.click(); + + await expect.element(page.getByRole('menu', { name: 'Options' })).toBeVisible(); + await expect.element(trigger).toHaveAttribute('aria-expanded', 'true'); + await expect.element(page.getByRole('menuitem', { name: 'Edit' })).toHaveFocus(); + const triggerRect = trigger.element().getBoundingClientRect(); + // The popover around the menu; measured once DaisyUI's scale-in animation has finished. + const popover = document.querySelector('[popover]')!; + await Promise.all(popover.getAnimations().map((a) => a.finished)); + const menuRect = popover.getBoundingClientRect(); + expect(menuRect.top).toBeGreaterThanOrEqual(triggerRect.bottom - 1); + expect(Math.abs(menuRect.right - triggerRect.right)).toBeLessThan(2); + }); + + it('renders visible actions only and keeps disabled ones inert', async () => { + const { trigger } = renderMenu(); + await trigger.click(); + + const items = page.getByRole('menuitem'); + await expect.element(items.nth(0)).toHaveTextContent('Edit'); + expect(items.elements()).toHaveLength(3); + await expect.element(page.getByRole('menuitem', { name: 'Locked' })).toBeDisabled(); + }); + + it('runs an action, closes and returns focus to the trigger', async () => { + const { trigger, onaction } = renderMenu(); + await trigger.click(); + + await page.getByRole('menuitem', { name: 'Delete' }).click(); + + expect(onaction).toHaveBeenCalledExactlyOnceWith('delete'); + await expect.element(page.getByRole('menu', { includeHidden: true })).not.toBeVisible(); + await expect.element(trigger).toHaveAttribute('aria-expanded', 'false'); + await expect.element(trigger).toHaveFocus(); + }); + + it('opens from the keyboard and closes on Escape', async () => { + const { trigger } = renderMenu(); + trigger.element().focus(); + + await userEvent.keyboard('{Enter}'); + await expect.element(page.getByRole('menu')).toBeVisible(); + + await userEvent.keyboard('{Escape}'); + await expect.element(page.getByRole('menu', { includeHidden: true })).not.toBeVisible(); + await expect.element(trigger).toHaveFocus(); + }); + + it('moves between enabled items with the arrow keys and closes on Tab', async () => { + const { trigger } = renderMenu(); + await trigger.click(); + const edit = page.getByRole('menuitem', { name: 'Edit' }); + const del = page.getByRole('menuitem', { name: 'Delete' }); + + await userEvent.keyboard('{ArrowDown}'); + await expect.element(del).toHaveFocus(); + // Wraps around and skips the disabled item. + await userEvent.keyboard('{ArrowDown}'); + await expect.element(edit).toHaveFocus(); + await userEvent.keyboard('{ArrowUp}'); + await expect.element(del).toHaveFocus(); + await userEvent.keyboard('{Home}'); + await expect.element(edit).toHaveFocus(); + await userEvent.keyboard('{End}'); + await expect.element(del).toHaveFocus(); + + await userEvent.keyboard('{Tab}'); + await expect.element(page.getByRole('menu', { includeHidden: true })).not.toBeVisible(); + }); + + it('flips above its trigger when there is no room below', async () => { + render(DropdownMenu, { + label: 'Options', + icon: IconMore, + actions, + onaction: vi.fn(), + triggerClass: 'fixed bottom-1 left-96' + }); + const trigger = page.getByRole('button', { name: 'Options' }); + await trigger.click(); + + const popover = document.querySelector('[popover]')!; + await Promise.all(popover.getAnimations().map((a) => a.finished)); + expect(popover.getBoundingClientRect().bottom).toBeLessThanOrEqual( + trigger.element().getBoundingClientRect().top + 1 + ); + }); + + it('positions itself by script where the browser lacks anchor positioning', async () => { + const supports = vi.spyOn(CSS, 'supports').mockReturnValue(false); + try { + const { trigger } = renderMenu(); + await trigger.click(); + + const popover = document.querySelector('[popover]')!; + await expect.poll(() => popover.style.top).not.toBe(''); + const triggerRect = trigger.element().getBoundingClientRect(); + expect(parseFloat(popover.style.top)).toBeCloseTo(triggerRect.bottom + 8, 0); + } finally { + supports.mockRestore(); + } + }); +}); From 0a1e576b3caafe3b6624feaf88009775ca04a37f Mon Sep 17 00:00:00 2001 From: Johannes Fleck Date: Mon, 23 Nov 2026 16:46:19 +0100 Subject: [PATCH 3/5] feat(storage): Unpin sidebar locations with a direct button MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The pinned location's "⋯" opened a context menu with a single Unpin action. A direct button saves the extra step and names the location. Focus moves on to the next unpin button, as the clicked one disappears with its row. Part of #488 --- e2e/storage/context-menu.spec.ts | 31 ------- e2e/storage/pinning.spec.ts | 48 ++++++++++ messages/de.json | 1 + messages/en.json | 1 + .../storage/sidebar/BucketList.svelte | 52 +++++------ .../storage/sidebar/BucketList.svelte.spec.ts | 87 +++---------------- 6 files changed, 83 insertions(+), 137 deletions(-) create mode 100644 e2e/storage/pinning.spec.ts diff --git a/e2e/storage/context-menu.spec.ts b/e2e/storage/context-menu.spec.ts index 979e05d5..6533c56f 100644 --- a/e2e/storage/context-menu.spec.ts +++ b/e2e/storage/context-menu.spec.ts @@ -99,37 +99,6 @@ test.describe('Storage S3 — Context Menu', () => { } }); - test('unpins a pinned location from its sidebar menu', async ({ page }, testInfo) => { - const credentials = requireGarageCredentials(); - const client = createS3Client(credentials); - const prefix = uniquePrefix(testInfo, 'ctx-unpin'); - const cleanupKeys = [`${prefix}file.txt`]; - - try { - await putTextObject(client, credentials.bucket, cleanupKeys[0], 'x'); - await connectAndOpenPrefix(page, credentials, prefix); - - const breadcrumb = page.getByRole('navigation', { name: 'Breadcrumb' }); - await breadcrumb.getByText(credentials.bucket).hover(); - await page - .getByRole('button', { name: 'Pin this location' }) - .filter({ visible: true }) - .first() - .click(); - const sidebar = page.getByRole('navigation', { name: 'Buckets' }); - await expect(sidebar.getByText('Pinned Access')).toBeVisible(); - - await sidebar.getByRole('button', { name: 'More options' }).click({ force: true }); - const menu = page.getByRole('menu', { name: 'Actions' }); - await menu.getByRole('menuitem', { name: 'Unpin' }).click(); - - await expect(menu).toHaveCount(0); - await expect(sidebar.getByText('Pinned Access')).toHaveCount(0); - } finally { - await deleteKnownKeys(client, credentials.bucket, cleanupKeys); - } - }); - test('deletes a single file via context menu', async ({ page }, testInfo) => { const credentials = requireGarageCredentials(); const client = createS3Client(credentials); diff --git a/e2e/storage/pinning.spec.ts b/e2e/storage/pinning.spec.ts new file mode 100644 index 00000000..4c402de6 --- /dev/null +++ b/e2e/storage/pinning.spec.ts @@ -0,0 +1,48 @@ +import { test, expect } from '../support/fixtures.js'; +import { + createS3Client, + hasGarageCredentials, + requireGarageCredentials +} from '../support/garage.js'; +import { connectAndOpenPrefix, deleteKnownKeys, putTextObject, uniquePrefix } from './helpers.js'; + +test.describe('Storage S3 — Pinned locations', () => { + test.use({ locale: 'en-US' }); + + test.beforeEach(() => { + test.skip( + !hasGarageCredentials(), + 'Skipped: no s3-config.json found (requires a running Garage instance)' + ); + }); + + test('unpins a pinned location with its sidebar button', async ({ page }, testInfo) => { + const credentials = requireGarageCredentials(); + const client = createS3Client(credentials); + const prefix = uniquePrefix(testInfo, 'unpin'); + const cleanupKeys = [`${prefix}file.txt`]; + + try { + await putTextObject(client, credentials.bucket, cleanupKeys[0], 'x'); + await connectAndOpenPrefix(page, credentials, prefix); + + const breadcrumb = page.getByRole('navigation', { name: 'Breadcrumb' }); + await breadcrumb.getByText(credentials.bucket).hover(); + await page + .getByRole('button', { name: 'Pin this location' }) + .filter({ visible: true }) + .first() + .click(); + const sidebar = page.getByRole('navigation', { name: 'Buckets' }); + await expect(sidebar.getByText('Pinned Access')).toBeVisible(); + + await sidebar.getByRole('button', { name: `Unpin ${credentials.bucket}` }).click({ + force: true + }); + + await expect(sidebar.getByText('Pinned Access')).toHaveCount(0); + } finally { + await deleteKnownKeys(client, credentials.bucket, cleanupKeys); + } + }); +}); diff --git a/messages/de.json b/messages/de.json index 33059d9f..101b3378 100644 --- a/messages/de.json +++ b/messages/de.json @@ -323,6 +323,7 @@ "storage_action_pin": "Ort anheften", "storage_action_details": "Details", "storage_action_unpin": "Loslösen", + "storage_unpin_location": "{label} lösen", "storage_action_copy_filename": "Dateiname kopieren", "storage_action_copy_filename_success": "Dateiname in die Zwischenablage kopiert.", "storage_action_copy_filename_error": "Dateiname konnte nicht in die Zwischenablage kopiert werden.", diff --git a/messages/en.json b/messages/en.json index 647dbc5e..4cb99e1d 100644 --- a/messages/en.json +++ b/messages/en.json @@ -323,6 +323,7 @@ "storage_action_pin": "Pin this location", "storage_action_details": "Details", "storage_action_unpin": "Unpin", + "storage_unpin_location": "Unpin {label}", "storage_action_copy_filename": "Copy filename", "storage_action_copy_filename_success": "Filename copied to clipboard.", "storage_action_copy_filename_error": "Could not copy filename to clipboard.", diff --git a/src/lib/components/storage/sidebar/BucketList.svelte b/src/lib/components/storage/sidebar/BucketList.svelte index 9bd90d9e..1cdabfb1 100644 --- a/src/lib/components/storage/sidebar/BucketList.svelte +++ b/src/lib/components/storage/sidebar/BucketList.svelte @@ -1,7 +1,6 @@ - -