This lands the clue collection line on top of origin/dev (v0.32.1, DSH 0.2.2-rc.2). The 14 commits that carried it are squashed into this one because every one of them overlapped upstream's own changes (version, 19 dictionaries, CHANGELOG), and each intermediate commit would have failed to compile against rc.2's menu API. The pre-integration head is kept at backup/clues-uiux-refresh-pre-rebase. What the feature is: - a Clues tab that reads local files, Feishu tasks/docs and GitHub issues/pulls through one source registry, with a scope row, shared search, filters, paging and stable [[dsh-clue:...]] references; - one window host for detail, pack management, source configuration, new pack and sharing (preview and edit are separate paths: a read is never saved over); - .cluepack export/import with per-row resolvability previews; - a source runtime that owns dependency installs and connection authorization (gh, lark-cli device code) and only probes on an explicit read; - the public betterSidebarClues service and the windows capability (features gains clues / windowHost). Merged with upstream rather than over it: - the settings section keeps upstream's start-page takeover group and this branch's clue sources group; navigation is now six groups; - the dictionaries keep both sides' new keys (1211 each, verified equal across all 19), the external-plugin guide and CHANGELOG keep both histories, and service features list both capability sets. Adapted to 0.2.2-rc.2: - menu call sites use anchorPoint instead of getAnchorRect; - the shared SelectMenu mounts the host menu only while open, because rc.2's Menu reads the DOM during render and broke server-rendered settings surfaces; - the submenu flip workaround stays deleted (the host positions submenus now), pinned by an updated layout-css assertion. Version 0.33.0 (three synced spots) with a new 未发布 / Unreleased changelog section; package.json regains the ./clues export, lib/clues.js and the uqr dependency that upstream never had. Gates: typecheck, lint, 5410 unit tests, build, check:consumer-types and the full mount lane (35 passed) against dsh 0.2.2-rc.2 in Chromium.
56 lines
3.0 KiB
TypeScript
56 lines
3.0 KiB
TypeScript
/**
|
|
* SourceSwitcher contract:
|
|
* - ONE item list renders the full-width segmented track and the narrow select;
|
|
* - the active value and the source count are exposed on the shared wrapper;
|
|
* - the wide form keeps the tablist/keyboard contract; the narrow form is the
|
|
* host select (a menu trigger, never a native select);
|
|
* - icons stay inside the tab label and each label carries its full title.
|
|
*/
|
|
// @vitest-environment jsdom
|
|
import { afterEach, expect, it, vi } from 'vitest'
|
|
import { createElement } from 'react'
|
|
import { act } from 'react-dom/test-utils'
|
|
import { SourceSwitcher } from '../src/client/ui/SourceSwitcher.tsx'
|
|
import { renderRoot, setupReactAct, type RenderedRoot } from './test-utils.ts'
|
|
|
|
setupReactAct()
|
|
let view: RenderedRoot | undefined
|
|
afterEach(() => { view?.unmount(); document.body.replaceChildren() })
|
|
|
|
const items = [
|
|
{ value: 'files', label: 'Local files', icon: createElement('span', { 'data-glyph': 'files' }) },
|
|
{ value: 'feishu', label: 'Feishu docs', icon: createElement('span', { 'data-glyph': 'feishu' }) },
|
|
{ value: 'github', label: 'GitHub Issues', icon: createElement('span', { 'data-glyph': 'github' }) },
|
|
]
|
|
|
|
it('renders one full-width tablist for the items and marks the active source', () => {
|
|
const onChange = vi.fn()
|
|
view = renderRoot(createElement(SourceSwitcher, { items, value: 'feishu', onChange, ariaLabel: 'Source' }))
|
|
const wrapper = view.container.querySelector<HTMLElement>('[data-clue-source-navigation]')!
|
|
expect(wrapper.getAttribute('data-clue-active-source')).toBe('feishu')
|
|
expect(wrapper.getAttribute('data-source-count')).toBe('3')
|
|
const tabs = [...wrapper.querySelectorAll<HTMLButtonElement>('[role="tab"]')]
|
|
expect(tabs).toHaveLength(3)
|
|
expect(tabs.map(tab => tab.textContent)).toEqual(['Local files', 'Feishu docs', 'GitHub Issues'])
|
|
expect(tabs[1]!.getAttribute('aria-selected')).toBe('true')
|
|
expect(tabs[1]!.title).toBe('Feishu docs')
|
|
expect(wrapper.querySelectorAll('[role="tablist"] [data-glyph]')).toHaveLength(3)
|
|
expect(wrapper.querySelector('[role="tablist"]')!.getAttribute('data-variant')).toBe('segmented')
|
|
act(() => tabs[2]!.click())
|
|
expect(onChange).toHaveBeenCalledExactlyOnceWith('github')
|
|
})
|
|
|
|
it('offers the same values through the host select for the narrow form', () => {
|
|
view = renderRoot(createElement(SourceSwitcher, { items, value: 'files', onChange: () => {}, ariaLabel: 'Source' }))
|
|
const select = view.container.querySelector<HTMLButtonElement>('button[aria-haspopup="menu"]')!
|
|
expect(select.getAttribute('aria-label')).toBe('Source')
|
|
expect(select.textContent).toContain('Local files')
|
|
expect(select.querySelector('[data-glyph="files"]')).not.toBeNull()
|
|
})
|
|
|
|
it('keeps a single enabled source visible (the strip is then one honest segment)', () => {
|
|
view = renderRoot(createElement(SourceSwitcher, { items: [items[0]!], value: 'files', onChange: () => {}, ariaLabel: 'Source' }))
|
|
expect(view.container.querySelectorAll('[role="tab"]')).toHaveLength(1)
|
|
expect(view.container.querySelector('[data-clue-source-navigation]')).not.toBeNull()
|
|
})
|