Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion knip.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
// `skills/devframe/templates/*.ts` are the devframe-authoring skill's
// copy-and-run reference snippets (`skills/devframe/SKILL.md`) - each
// one a standalone, runnable example, not imported by anything else.
"entry": ["design/*.ts", "skills/devframe/templates/*.ts", "scripts/smoke-bun.ts"],
// The floating dock fixture is loaded by its HTML script tag.
"entry": ["design/*.ts", "skills/devframe/templates/*.ts", "scripts/smoke-bun.ts", "tests/e2e/_support/floating-dock/main.ts"],
// `@x18n/cli` is run by hand (`pnpm x18n`) and no script calls it yet.
"ignoreDependencies": ["@x18n/cli"]
},
Expand Down
12 changes: 10 additions & 2 deletions packages/hub-ui/src/client/components/dock/Dock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { DocksContext } from '@devframes/hub/client'
import type { CSSProperties } from 'vue'
import type { DockLayout } from './dock-layout'
import { useEventListener, whenever } from '@vueuse/core'
import { useEventListener, useFocusWithin, whenever } from '@vueuse/core'
import { computed, onMounted, reactive, ref, useTemplateRef, watch } from 'vue'
import { BUILTIN_ENTRY_CLIENT_AUTH_NOTICE } from '../../constants'
import { t } from '../../i18n'
Expand Down Expand Up @@ -49,6 +49,7 @@ const safeArea = useSafeArea(anchorEl)
const panelMargins = computed(() => resolveViewportMargins(safeArea.value, layout.value))

const dockEl = useTemplateRef<HTMLDivElement>('dockEl')
const { focused: isFocused } = useFocusWithin(dockEl)

const recalculateCounter = ref(0)
const isHovering = ref(false)
Expand Down Expand Up @@ -219,6 +220,8 @@ const docksGroupPanel = useDocksGroupPanel()
const isMinimized = computed(() => {
if (context.panel.store.inactiveTimeout < 0)
return false
if (isFocused.value)
return false
if (docksGroupPanel.value)
return false
// Keep an active tool's button in sight while it hides the panel.
Expand Down Expand Up @@ -307,7 +310,8 @@ onMounted(() => {
@pointerdown="onPointerDown"
>
<div
class="w-3 h-3 absolute left-1/2 top-1/2 translate-x--1/2 translate-y--1/2 transition-opacity duration-300"
aria-hidden="true"
class="pointer-events-none w-3 h-3 absolute left-1/2 top-1/2 translate-x--1/2 translate-y--1/2 transition-opacity duration-300"
:class="[
isMinimized ? 'op100' : 'op0',
context.panel.isVertical ? 'rotate-270' : 'rotate-0',
Expand All @@ -318,6 +322,8 @@ onMounted(() => {
</div>
<div
v-if="!isRpcTrusted"
:inert="!!isMinimized"
:aria-hidden="!!isMinimized"
class="transition duration-300 delay-200 ma"
:class="isMinimized ? 'opacity-0 pointer-events-none ws-nowrap text-sm text-orange of-hidden' : 'opacity-100'"
>
Expand All @@ -338,6 +344,8 @@ onMounted(() => {
</div>
<div
v-if="isRpcTrusted"
:inert="!!isMinimized"
:aria-hidden="!!isMinimized"
:class="isMinimized ? 'opacity-0 pointer-events-none' : 'opacity-100'"
class="transition duration-200 flex items-center w-full h-full justify-center px1 overflow-hidden"
>
Expand Down
11 changes: 11 additions & 0 deletions tests/e2e/_support/floating-dock/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Floating dock interaction fixture</title>
</head>
<body>
<button id="before">Before dock</button>
<script type="module" src="./main.ts"></script>
</body>
</html>
37 changes: 37 additions & 0 deletions tests/e2e/_support/floating-dock/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { setDevframeClientContext } from '@devframes/hub/client'
import { watchEffect } from 'vue'
import { DockEmbedded } from '../../../../packages/hub-ui/src/client/components/DockEmbedded'
import { createMockDocksContext } from '../../../../packages/hub-ui/src/client/stories/mock-context'

async function main(): Promise<void> {
const params = new URLSearchParams(location.search)
const context = await createMockDocksContext({
isTrusted: params.has('trusted'),
panel: {
position: params.has('vertical')
? 'left'
: 'bottom',
left: params.has('vertical')
? 0
: 50,
top: params.has('vertical')
? 50
: 100,
inactiveTimeout: 30_000,
},
})
setDevframeClientContext(context)
document.body.appendChild(new DockEmbedded({ context }))

watchEffect(() => {
document.body.dataset.selected = context.docks.selected?.id ?? ''
document.body.dataset.open = String(context.panel.session.open)
})

const after = document.createElement('button')
after.id = 'after'
after.textContent = 'After dock'
document.body.appendChild(after)
}

void main()
117 changes: 117 additions & 0 deletions tests/e2e/floating-dock.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import type { Locator } from '@playwright/test'
import type { ViteDevServer } from 'vite'
import { fileURLToPath } from 'node:url'
import { expect, test } from '@playwright/test'
import { createServer } from 'vite'
import { alias } from '../../alias'

let server: ViteDevServer
let origin: string

test.beforeAll(async ({ browserName }, { workerIndex }) => {
server = await createServer({
configFile: fileURLToPath(new URL('../../packages/hub-ui/vite.embedded.config.ts', import.meta.url)),
root: fileURLToPath(new URL('./_support/floating-dock', import.meta.url)),
cacheDir: fileURLToPath(new URL(`../../node_modules/.vite/floating-dock/${browserName}-${workerIndex}`, import.meta.url)),
resolve: { alias },
server: { host: '127.0.0.1', port: 0 },
})
await server.listen()
origin = server.resolvedUrls!.local[0]
})

test.afterAll(async () => {
await server?.close()
})

async function center(locator: Locator): Promise<{ x: number, y: number }> {
const box = await locator.boundingBox()
expect(box).not.toBeNull()
return { x: box!.x + box!.width / 2, y: box!.y + box!.height / 2 }
}

for (const trusted of [false, true]) {
test.describe(trusted ? 'trusted floating dock' : 'unauthorized floating dock', () => {
const name = trusted ? 'Settings' : 'Unauthorized'

test.beforeEach(async ({ page }) => {
await page.clock.install()
await page.goto(`${origin}?${trusted ? 'trusted' : ''}`)
await expect(page.locator('#devframes-dock')).toBeVisible()
})

for (const vertical of [false, true]) {
test(`center pointer click activates the visible control (${vertical ? 'vertical' : 'horizontal'})`, async ({ page }) => {
if (vertical)
await page.goto(`${origin}?${trusted ? 'trusted&' : ''}vertical`)
const dock = page.locator('#devframes-dock')
await dock.hover()
await expect(page.locator('#devframes-anchor')).not.toHaveClass(/devframes-minimized/)
const button = dock.getByRole('button', { name, exact: true })
// Wait for expansion so the click lands beneath the centered logo.
await expect(button).toBeInViewport()
const logo = dock.locator(':scope > div').first()
await expect(logo).toHaveCSS('opacity', '0')
await expect(dock.locator(':scope > div').last()).toHaveCSS('opacity', '1')
expect(await logo.evaluate((el) => {
const box = el.getBoundingClientRect()
const root = el.getRootNode() as ShadowRoot
return root.elementsFromPoint(box.x + box.width / 2, box.y + box.height / 2)
.some(target => el.contains(target))
})).toBe(false)
const point = await center(button)
await page.mouse.click(point.x, point.y)
await expect(page.locator('body')).toHaveAttribute('data-open', 'true')
await expect(page.locator('body')).toHaveAttribute('data-selected', trusted ? '~settings' : '~client-auth-notice')
})
}

test('minimized controls leave the accessibility tree and tab order', async ({ page }) => {
const dock = page.locator('#devframes-dock')
await dock.hover()
await expect(dock.getByRole('button', { name, exact: true })).toHaveCount(1)
await page.mouse.move(0, 0)
await page.clock.fastForward(31_000)
await expect(page.locator('#devframes-anchor')).toHaveClass(/devframes-minimized/)
await expect(dock.getByRole('button')).toHaveCount(0)
const hidden = dock.locator('button').first()
await hidden.evaluate(el => el.focus())
await expect(hidden).not.toBeFocused()
await page.locator('#before').focus()
await page.keyboard.press('Tab')
await expect(page.locator('#after')).toBeFocused()

await dock.hover()
await expect(dock.getByRole('button', { name, exact: true })).toHaveCount(1)
await dock.getByRole('button', { name, exact: true }).focus()
await expect(dock.getByRole('button', { name, exact: true })).toBeFocused()
})

test('keeps focused controls available past the inactivity timeout', async ({ page }) => {
const dock = page.locator('#devframes-dock')
await dock.hover()
const button = dock.getByRole('button', { name, exact: true })
await button.focus()
await page.mouse.move(0, 0)
await page.clock.fastForward(31_000)
await expect(button).toBeFocused()
await expect(page.locator('#devframes-anchor')).not.toHaveClass(/devframes-minimized/)

await page.locator('#before').focus()
await expect(page.locator('#devframes-anchor')).toHaveClass(/devframes-minimized/)
await expect(dock.getByRole('button')).toHaveCount(0)
})

test('minimized dock remains draggable', async ({ page }) => {
const anchor = page.locator('#devframes-anchor')
await page.clock.fastForward(31_000)
await expect(anchor).toHaveClass(/devframes-minimized/)
const point = await center(page.locator('#devframes-dock'))
await page.mouse.move(point.x, point.y)
await page.mouse.down()
await page.mouse.move(20, 300, { steps: 10 })
await page.mouse.up()
await expect(anchor).toHaveClass(/devframes-vertical/)
})
})
}
Loading