feat(git): a labeled repository picker for multi-repo workspaces
A container workspace that discovers several repositories rendered one chip per root above the Changes section; with location labels the row does not scale, and same-named checkouts were indistinguishable. The row is now a compact labeled select: the current root stays on screen, the full list is one click away, and options carry disambiguation labels (deeper roots show their relative parent) shared with the More -> Repository submenu. The picker shows the resolved status root — a server fallback renders as a disabled stand-in with its own short label instead of silently selecting the first option. Single-repo workspaces render no row; switching still goes through chooseRepo.
This commit is contained in:
1 parent
7c374293c7
commit
ea770cc2e1
7 files changed
+577
-85
No files matched your search
@@ -0,0 +1,247 @@
|
||||
/** Repository labels are display-only: preserve input roots/order, and identify context without IO. */
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { buildRepositoryLabels } from '../src/client/changes/repo-labels.ts'
|
||||
|
||||
const labels = (roots: readonly string[], cwd?: string) => buildRepositoryLabels(roots, cwd).map(row => row.label)
|
||||
|
||||
describe('buildRepositoryLabels', () => {
|
||||
it('keeps the display base and immediate child names short', () => {
|
||||
const roots = ['/workspace', '/workspace/dsh-m', '/workspace/ob-harness']
|
||||
expect(buildRepositoryLabels(roots, '/workspace')).toEqual([
|
||||
{ root: '/workspace', label: 'workspace' },
|
||||
{ root: '/workspace/dsh-m', label: 'dsh-m' },
|
||||
{ root: '/workspace/ob-harness', label: 'ob-harness' },
|
||||
])
|
||||
})
|
||||
|
||||
it('always shows the full relative parent for deeper roots, even without name conflicts', () => {
|
||||
expect(labels(['/workspace/ob-harness/contexts/baseline', '/workspace/one/two/repo'], '/workspace'))
|
||||
.toEqual(['baseline (ob-harness/contexts)', 'repo (one/two)'])
|
||||
})
|
||||
|
||||
it('preserves directory names with spaces, Unicode and punctuation', () => {
|
||||
expect(labels(['/workspace/proj a/子目录/a[b]'], '/workspace')).toEqual(['a[b] (proj a/子目录)'])
|
||||
})
|
||||
|
||||
it('treats a POSIX root as base without losing the root or direct child', () => {
|
||||
expect(labels(['/', '/workspace', '/workspace/a'], '/')).toEqual(['/', 'workspace', 'a (workspace)'])
|
||||
})
|
||||
|
||||
it('treats double-leading slashes as POSIX when the known base is POSIX', () => {
|
||||
const roots = ['//work/project/repo']
|
||||
expect(buildRepositoryLabels(roots, '/work')).toEqual([{ root: roots[0], label: 'repo (project)' }])
|
||||
})
|
||||
|
||||
it('treats a Windows-looking namespace as POSIX on a POSIX host', () => {
|
||||
const roots = ['//?/C:/work/repo', '//?/UNC/work/repo']
|
||||
expect(buildRepositoryLabels(roots, '/', '/home/example').map(row => row.label))
|
||||
.toEqual(['repo (?/C:/work)', 'repo (?/UNC/work)'])
|
||||
})
|
||||
|
||||
it('uses the existing host home to disambiguate double-slash POSIX and UNC bases', () => {
|
||||
const posixRoots = ['//work/project/a/b/repo', '/work/project/a/b/other']
|
||||
expect(buildRepositoryLabels(posixRoots, '//work/project', '/home/example').map(row => row.label))
|
||||
.toEqual(['repo (a/b)', 'other (a/b)'])
|
||||
const windowsRoots = ['//server/share/work/a/b/repo']
|
||||
expect(buildRepositoryLabels(windowsRoots, '//server/share/work', 'C:\\Users\\example').map(row => row.label))
|
||||
.toEqual(['repo (a\\b)'])
|
||||
// With no host hint, the two spellings are indistinguishable; preserve
|
||||
// forward-slash spelling rather than pretending the host is Windows.
|
||||
expect(buildRepositoryLabels(windowsRoots, '//server/share/work').map(row => row.label))
|
||||
.toEqual(['repo (a/b)'])
|
||||
expect(buildRepositoryLabels(posixRoots, '//work/project').map(row => row.label))
|
||||
.toEqual(['repo (a/b)', 'other (a/b)'])
|
||||
// Unknown host semantics must not infer case-insensitive containment.
|
||||
expect(buildRepositoryLabels(['//SERVER/share/work/a/b/repo'], '//server/share/work').map(row => row.label))
|
||||
.toEqual(['repo (b)'])
|
||||
})
|
||||
|
||||
it('preserves slash spelling when host and display base are unknown', () => {
|
||||
const roots = ['//srv/share/A/same/repo', '//srv/share/B/same/repo']
|
||||
const expected = ['repo (A/same)', 'repo (B/same)']
|
||||
expect(labels(roots, undefined)).toEqual(expected)
|
||||
expect(labels(roots, 'relative')).toEqual(expected)
|
||||
})
|
||||
|
||||
it('uses segment boundaries rather than a textual prefix', () => {
|
||||
expect(labels(['/work/repo', '/workspace/other', '/work-other/third'], '/work'))
|
||||
.toEqual(['repo', 'other (workspace)', 'third (work-other)'])
|
||||
})
|
||||
|
||||
it('does not infer containment through unresolved parent segments', () => {
|
||||
expect(labels(['/workspace/link/../parent/repo'], '/workspace')).toEqual(['repo'])
|
||||
expect(labels(['/workspace/parent/repo'], '/workspace/link/..')).toEqual(['repo'])
|
||||
})
|
||||
|
||||
it('does not case-fold POSIX containment or POSIX distinct names', () => {
|
||||
expect(labels(['/work/Team/repo', '/Work/Team/other', '/work/foo', '/work/Foo'], '/work'))
|
||||
.toEqual(['repo (Team)', 'other (Team)', 'foo', 'Foo'])
|
||||
})
|
||||
|
||||
it('shows short parent context outside a known base, but short names when the base is unavailable', () => {
|
||||
const roots = ['/a/pkg', '/b/pkg', '/outside/unique']
|
||||
expect(labels(roots, undefined)).toEqual(['pkg (a)', 'pkg (b)', 'unique'])
|
||||
expect(labels(roots, '/workspace')).toEqual(['pkg (a)', 'pkg (b)', 'unique (outside)'])
|
||||
expect(labels(roots, 'relative')).toEqual(['pkg (a)', 'pkg (b)', 'unique'])
|
||||
})
|
||||
|
||||
it('expands parent context sufficiently when immediate parents match', () => {
|
||||
const roots = ['/one/common/repo', '/two/common/repo']
|
||||
expect(labels(roots)).toEqual(['repo (one/common)', 'repo (two/common)'])
|
||||
})
|
||||
|
||||
it('resolves a base item and direct child with the same basename without numeric suffixes', () => {
|
||||
const roots = ['/workspace', '/workspace/workspace']
|
||||
const result = labels(roots, '/workspace')
|
||||
expect(new Set(result).size).toBe(2)
|
||||
expect(result.every(label => !/\[\d+\]$/.test(label))).toBe(true)
|
||||
expect(result).toEqual(labels(roots, '/workspace'))
|
||||
})
|
||||
|
||||
it('resolves collision between a generated label and a real directory name globally', () => {
|
||||
const roots = ['/x/a', '/y/a', '/z/a (x)']
|
||||
const result = labels(roots)
|
||||
expect(new Set(result).size).toBe(3)
|
||||
expect(result).toEqual(labels(roots))
|
||||
expect(result.every(label => !/\[\d+\]$/.test(label))).toBe(true)
|
||||
})
|
||||
|
||||
it('falls back to complete paths when names and ancestor suffixes collide', () => {
|
||||
const roots = ['/x/shared/repo', '/y/shared/repo']
|
||||
const result = labels(roots, undefined)
|
||||
expect(result).toEqual(['repo (x/shared)', 'repo (y/shared)'])
|
||||
expect(new Set(result).size).toBe(2)
|
||||
})
|
||||
|
||||
it('uses absolute paths as a final fallback without losing distinct raw spellings', () => {
|
||||
const roots = ['/a/repo', '/a/repo/']
|
||||
const result = labels(roots)
|
||||
expect(new Set(result).size).toBe(2)
|
||||
expect(result.join('\n')).toContain('/a/repo')
|
||||
expect(result).toEqual(labels(roots))
|
||||
})
|
||||
|
||||
it('supports case-insensitive Windows drive containment using Windows separators', () => {
|
||||
const roots = ['C:\\Work', 'c:\\work\\app', 'C:\\work\\project\\nested\\repo']
|
||||
expect(labels(roots, 'C:\\WORK\\')).toEqual(['Work', 'app', 'repo (project\\nested)'])
|
||||
})
|
||||
|
||||
it('recognises Windows paths written with forward slashes and uses the host dialect', () => {
|
||||
expect(labels(['C:/Work/project/nested/repo'], 'c:/work')).toEqual(['repo (project\\nested)'])
|
||||
})
|
||||
|
||||
it('matches Windows extended-length drive and UNC paths to ordinary bases', () => {
|
||||
expect(labels(['\\\\?\\C:\\work\\project\\nested\\repo'], 'C:\\work'))
|
||||
.toEqual(['repo (project\\nested)'])
|
||||
expect(labels(['\\\\?\\UNC\\srv\\share\\work\\project\\nested\\repo'], '\\\\srv\\share\\work'))
|
||||
.toEqual(['repo (project\\nested)'])
|
||||
expect(labels(['//?/C:/work/project/nested/repo'], 'C:\\work'))
|
||||
.toEqual(['repo (project\\nested)'])
|
||||
expect(labels(['//?/UNC/srv/share/work/project/nested/repo'], '\\\\srv\\share\\work'))
|
||||
.toEqual(['repo (project\\nested)'])
|
||||
})
|
||||
|
||||
it('recognises mixed UNC separators on a Windows host without misreading POSIX names', () => {
|
||||
const roots = ['\\/server/share/work/a/repo', '/\\server/share/work/b/nested/other']
|
||||
const rows = buildRepositoryLabels(roots, '\\\\server\\share\\work', 'C:\\Users\\example')
|
||||
expect(rows.map(row => row.root)).toEqual(roots)
|
||||
expect(rows.map(row => row.label)).toEqual(['repo (a)', 'other (b\\nested)'])
|
||||
expect(buildRepositoryLabels(['/\\server/share/work/a/repo'], '/', '/home/example').map(row => row.label))
|
||||
.toEqual(['repo (\\server/share/work/a)'])
|
||||
const ambiguous = ['/\\server/share/work/a/b/repo']
|
||||
expect(buildRepositoryLabels(ambiguous, '/\\server/share/work').map(row => row.label))
|
||||
.toEqual(['repo (a/b)'])
|
||||
expect(buildRepositoryLabels(ambiguous, '/\\server/share/work', 'C:\\Users\\example').map(row => row.label))
|
||||
.toEqual(['repo (a\\b)'])
|
||||
const duplicates = ['//server/share/A/same/repo', '//server/share/B/same/repo']
|
||||
expect(buildRepositoryLabels(duplicates, undefined, '\\/server/share/user').map(row => row.label))
|
||||
.toEqual(['repo (A\\same)', 'repo (B\\same)'])
|
||||
})
|
||||
|
||||
it('does not treat a different Windows drive as inside the base', () => {
|
||||
expect(labels(['D:\\work\\project\\repo'], 'C:\\work')).toEqual(['repo (project)'])
|
||||
})
|
||||
|
||||
it('shows a root-level parent for an outside repository', () => {
|
||||
expect(labels(['/repo'], '/workspace')).toEqual(['repo (/)'])
|
||||
expect(labels(['D:\\repo'], 'C:\\work')).toEqual(['repo (D:\\)'])
|
||||
expect(labels(['\\\\server\\other'], '\\\\server\\share')).toEqual(['other (\\\\server)'])
|
||||
})
|
||||
|
||||
it('uses drive-qualified absolute paths when parent contexts cannot distinguish drives', () => {
|
||||
expect(labels(['C:\\repo', 'D:\\repo'])).toEqual(['repo (C:\\repo)', 'repo (D:\\repo)'])
|
||||
expect(labels(['C:\\', 'C:\\work', 'C:\\work\\repo'], 'C:\\'))
|
||||
.toEqual(['C:\\', 'work', 'repo (work)'])
|
||||
})
|
||||
|
||||
it('distinguishes raw Windows path spellings when their normalized identity is equal', () => {
|
||||
const roots = ['C:\\work\\repo', 'c:/work/repo/']
|
||||
const rows = buildRepositoryLabels(roots, 'C:\\work')
|
||||
expect(rows.map(row => row.root)).toEqual(roots)
|
||||
expect(new Set(rows.map(row => row.label)).size).toBe(2)
|
||||
expect(rows.map(row => row.label)).toEqual(labels(roots, 'C:\\work'))
|
||||
})
|
||||
|
||||
it('supports UNC shares and case-insensitive Windows containment', () => {
|
||||
const roots = ['\\\\server\\Share', '\\\\SERVER\\share\\org\\repo', '\\\\server\\other\\org\\other']
|
||||
expect(labels(roots, '\\\\SERVER\\SHARE\\')).toEqual(['Share', 'repo (org)', 'other (org)'])
|
||||
})
|
||||
|
||||
it('treats backslashes inside POSIX path components literally', () => {
|
||||
expect(labels(['/workspace/project\\name/sub/repo'], '/workspace')).toEqual(['repo (project\\name/sub)'])
|
||||
})
|
||||
|
||||
it('handles trailing separators while leaving each selected root untouched', () => {
|
||||
const roots = ['/workspace/', '/workspace/nested/repo/', 'C:\\work\\project\\']
|
||||
const rows = buildRepositoryLabels(roots, '/workspace/')
|
||||
expect(rows.map(row => row.root)).toEqual(roots)
|
||||
expect(rows.map(row => row.label)).toEqual(['workspace', 'repo (nested)', 'project (work)'])
|
||||
})
|
||||
|
||||
it('does not invent distinct identities for duplicate identical input roots', () => {
|
||||
const root = '/workspace/app'
|
||||
expect(buildRepositoryLabels([root, root], '/workspace')).toEqual([
|
||||
{ root, label: 'app' }, { root, label: 'app' },
|
||||
])
|
||||
})
|
||||
|
||||
it('distinguishes 200 colliding basenames with an unknown base', () => {
|
||||
const roots = Object.freeze(Array.from({ length: 200 }, (_, i) => `/outside/project-${i}/shared/repo`))
|
||||
const result = buildRepositoryLabels(roots, undefined)
|
||||
expect(result.map(row => row.root)).toEqual([...roots])
|
||||
expect(new Set(result.map(row => row.label)).size).toBe(200)
|
||||
expect(result[0]?.label).toBe('repo (project-0/shared)')
|
||||
expect(result[199]?.label).toBe('repo (project-199/shared)')
|
||||
})
|
||||
|
||||
it('does not build ancestor suffixes for unique names', () => {
|
||||
const base = '/' + Array.from({ length: 200 }, (_, i) => `d${i}`).join('/')
|
||||
const roots = Array.from({ length: 100 }, (_, i) => `${base}/repo-${i}`)
|
||||
const originalJoin = Array.prototype.join
|
||||
let calls = 0
|
||||
Array.prototype.join = function (separator?: string) {
|
||||
calls++
|
||||
return originalJoin.call(this, separator)
|
||||
}
|
||||
let rows: ReturnType<typeof buildRepositoryLabels>
|
||||
try {
|
||||
rows = buildRepositoryLabels(roots, base)
|
||||
} finally {
|
||||
Array.prototype.join = originalJoin
|
||||
}
|
||||
expect(rows).toHaveLength(100)
|
||||
expect(calls).toBeLessThan(500)
|
||||
})
|
||||
|
||||
it('constructs 200 labels in input order without mutating frozen input', () => {
|
||||
const roots = Object.freeze(Array.from({ length: 200 }, (_, i) => `/workspace/project-${i}/contexts/repo`))
|
||||
const before = [...roots]
|
||||
const result = buildRepositoryLabels(roots, '/workspace')
|
||||
expect(result).toHaveLength(200)
|
||||
expect(result.map(row => row.root)).toEqual(before)
|
||||
expect(new Set(result.map(row => row.label)).size).toBe(200)
|
||||
expect(result[0]?.label).toBe('repo (project-0/contexts)')
|
||||
expect(result[199]?.label).toBe('repo (project-199/contexts)')
|
||||
expect(roots).toEqual(before)
|
||||
})
|
||||
})
|
||||
@@ -1,20 +1,26 @@
|
||||
/**
|
||||
* Multi-repository switcher in the Git lens (a workspace CONTAINER, i.e. a
|
||||
* Multi-repository picker in the Git lens (a workspace CONTAINER, i.e. a
|
||||
* project directory that is not itself a repository but holds several).
|
||||
*
|
||||
* Contract:
|
||||
* - `git.status` reports `repositories` (every discovered root). When it holds
|
||||
* more than one, the lens renders one chip per root above the Changes
|
||||
* section: label = `baseName(root)`, `[data-scm-repo]` = the absolute root.
|
||||
* - Exactly one chip is marked `[data-active="true"]`: the root the panel is
|
||||
* currently pinned to (`repoRoot`, or the resolved `status.root` before the
|
||||
* user picks one). Both spellings of one checkout are the same root —
|
||||
* forward/back slashes, a trailing separator and Windows case all fold.
|
||||
* - Clicking another chip re-pins the scope through the same `chooseRepo` the
|
||||
* ⋯ → 仓库 submenu uses, so the next status read carries that root and the
|
||||
* switcher survives the following read (a selected child still reports the
|
||||
* full `repositories` list).
|
||||
* - A single-repository workspace renders NO switcher: the row must not steal
|
||||
* more than one, the lens renders a labeled <select> ("Repository") above
|
||||
* the Changes section: each option pairs the display-only disambiguation
|
||||
* label (`buildRepositoryLabels(roots, scope.cwd, hostHome)` — deeper roots
|
||||
* carry their relative parent, so same-named checkouts stay tellable apart)
|
||||
* with its absolute root as the value. The ⋯ → Repository submenu shares the
|
||||
* same label list.
|
||||
* - The picker's value is the RESOLVED status root, and both spellings of one
|
||||
* checkout fold (forward/back slashes, trailing separator, Windows case).
|
||||
* When that root is no longer among the retained choices (the server fell
|
||||
* back), it renders as a DISABLED stand-in option with its own short label —
|
||||
* the stale request or the first option is never silently presented as the
|
||||
* selection.
|
||||
* - Changing the picker re-pins the scope through the same `chooseRepo` the
|
||||
* submenu uses, so the next status read carries that root and the picker
|
||||
* survives the following read (a selected child still reports the full
|
||||
* `repositories` list).
|
||||
* - A single-repository workspace renders NO picker: the row must not steal
|
||||
* vertical space from the ordinary case.
|
||||
*/
|
||||
// @vitest-environment jsdom
|
||||
@@ -22,6 +28,7 @@ import { act } from 'react-dom/test-utils'
|
||||
import { afterEach, expect, it, vi } from 'vitest'
|
||||
import { api, type GitStatusResult, type SessionScope } from '../src/client/api.ts'
|
||||
import { GitLens } from '../src/client/changes/GitLens.tsx'
|
||||
import { t } from '../src/client/locales.ts'
|
||||
import { renderRoot, setupReactAct } from './test-utils.ts'
|
||||
|
||||
setupReactAct()
|
||||
@@ -30,22 +37,28 @@ afterEach(() => { vi.restoreAllMocks() })
|
||||
const CWD = 'C:/work'
|
||||
const ADMIN = 'C:/work-admin'
|
||||
const DOCS = 'C:/work-docs'
|
||||
const DEEP_A = 'C:/work/pack/alpha'
|
||||
const DEEP_B = 'C:/work/pack/beta'
|
||||
const flush = async (): Promise<void> => { await act(async () => { await Promise.resolve() }) }
|
||||
const click = async (button: HTMLButtonElement): Promise<void> => { await act(async () => { button.click() }) }
|
||||
const chips = (container: HTMLElement): HTMLButtonElement[] =>
|
||||
[...container.querySelectorAll<HTMLButtonElement>('[data-scm-repo]')]
|
||||
const picker = (container: HTMLElement): HTMLSelectElement => {
|
||||
const node = container.querySelector<HTMLSelectElement>(`[data-scm-repos] select[aria-label="${t('gitRepository')}"]`)
|
||||
if (node === null) throw new Error('repository picker missing')
|
||||
return node
|
||||
}
|
||||
const options = (node: HTMLSelectElement): HTMLOptionElement[] => [...node.options].filter(option => !option.disabled)
|
||||
|
||||
/** One container-workspace snapshot: the resolved root plus every discovered root. */
|
||||
const snapshot = (root: string, repositories: string[]): GitStatusResult =>
|
||||
({ isRepo: true, branch: 'main', root, entries: [], repositories })
|
||||
|
||||
/** Mount the lens over a mocked host; `scopes` records every status request. */
|
||||
async function mount(options: { sessionId: string; repositories?: string[] }) {
|
||||
async function mount(options: { sessionId: string; repositories?: string[]; resolvedRoot?: (scope: SessionScope) => string }) {
|
||||
const scopes: SessionScope[] = []
|
||||
const repositories = options.repositories ?? [CWD, ADMIN, DOCS]
|
||||
const resolvedRoot = options.resolvedRoot ?? (scope => scope.repoRoot ?? CWD)
|
||||
vi.spyOn(api, 'gitStatus').mockImplementation(async scope => {
|
||||
scopes.push(scope)
|
||||
return snapshot(scope.repoRoot ?? CWD, repositories)
|
||||
return snapshot(resolvedRoot(scope), repositories)
|
||||
})
|
||||
vi.spyOn(api, 'gitWorktrees').mockResolvedValue([{ path: CWD, branch: 'main', current: true, changes: 0 }])
|
||||
vi.spyOn(api, 'gitBranch').mockResolvedValue({ current: 'main', names: ['main'] })
|
||||
@@ -62,44 +75,76 @@ async function mount(options: { sessionId: string; repositories?: string[] }) {
|
||||
return { ...view, scopes }
|
||||
}
|
||||
|
||||
it('lists every discovered repository and re-pins the scope to the clicked chip', async () => {
|
||||
it('lists every discovered repository and re-pins the scope through the picker', async () => {
|
||||
const view = await mount({ sessionId: 'scm-repos-multi' })
|
||||
const { container } = view
|
||||
const row = container.querySelector('[data-scm-repos]')!
|
||||
expect(row).not.toBeNull()
|
||||
const node = picker(view.container)
|
||||
expect(options(node).map(option => option.value)).toEqual([CWD, ADMIN, DOCS])
|
||||
// Siblings outside the session cwd's directory carry their parent context;
|
||||
// the base itself stays short.
|
||||
expect(options(node).map(option => option.textContent)).toEqual(['work', 'work-admin (C:\\)', 'work-docs (C:\\)'])
|
||||
expect(node.value).toBe(CWD)
|
||||
|
||||
const buttons = chips(container)
|
||||
expect(buttons.map(button => button.dataset.scmRepo)).toEqual([CWD, ADMIN, DOCS])
|
||||
expect(buttons.map(button => button.textContent)).toEqual(['work', 'work-admin', 'work-docs'])
|
||||
expect(buttons.map(button => button.getAttribute('data-active'))).toEqual(['true', null, null])
|
||||
expect(buttons[0]!.getAttribute('aria-pressed')).toBe('true')
|
||||
|
||||
await click(buttons[1]!)
|
||||
await act(async () => { node.value = ADMIN; node.dispatchEvent(new Event('change', { bubbles: true })) })
|
||||
await flush()
|
||||
await flush()
|
||||
|
||||
// The click went through `chooseRepo`: the next status read targets that root...
|
||||
// The change went through `chooseRepo`: the next status read targets that root...
|
||||
expect(view.scopes.at(-1)?.repoRoot).toBe(ADMIN)
|
||||
// ...and the switcher survived the following snapshot, still listing all roots.
|
||||
const after = chips(container)
|
||||
expect(after.map(button => button.dataset.scmRepo)).toEqual([CWD, ADMIN, DOCS])
|
||||
expect(after.map(button => button.getAttribute('data-active'))).toEqual([null, 'true', null])
|
||||
// ...and the picker survives the following snapshot, still listing all roots.
|
||||
expect(picker(view.container).value).toBe(ADMIN)
|
||||
expect(options(picker(view.container)).map(option => option.value)).toEqual([CWD, ADMIN, DOCS])
|
||||
})
|
||||
|
||||
it('folds separator, trailing slash and case when marking the current checkout', async () => {
|
||||
// The status snapshot reports the git spelling (`C:/work`); the root rendered
|
||||
// into a chip may arrive as `C:\WORK\`. Both name the same checkout, so
|
||||
// exactly one chip is active — a naive string compare would mark none.
|
||||
it('folds separator, trailing slash and case when naming the current checkout', async () => {
|
||||
// The status snapshot reports the git spelling (`C:/work`); the retained
|
||||
// option may be `C:\WORK\`. Both name the same checkout, so the picker
|
||||
// selects the original spelling instead of falling to the first option.
|
||||
const view = await mount({ sessionId: 'scm-repos-spelling', repositories: ['C:\\WORK\\', ADMIN] })
|
||||
const buttons = chips(view.container)
|
||||
expect(buttons.map(button => button.dataset.scmRepo)).toEqual(['C:\\WORK\\', ADMIN])
|
||||
expect(buttons.map(button => button.getAttribute('data-active'))).toEqual(['true', null])
|
||||
expect(picker(view.container).value).toBe('C:\\WORK\\')
|
||||
})
|
||||
|
||||
it('renders no switcher for a single-repository workspace', async () => {
|
||||
it('renders no picker for a single-repository workspace', async () => {
|
||||
const view = await mount({ sessionId: 'scm-repos-single', repositories: [CWD] })
|
||||
expect(view.container.querySelector('[data-scm-repos]')).toBeNull()
|
||||
expect(chips(view.container)).toEqual([])
|
||||
// The ordinary panel is intact: the Changes section is still there.
|
||||
expect(view.container.querySelector('[data-scm-section="changes"]')).not.toBeNull()
|
||||
})
|
||||
|
||||
it('labels deeper repositories with their relative parent and shares the list with the menu', async () => {
|
||||
const view = await mount({ sessionId: 'scm-repos-labels', repositories: [CWD, DEEP_A, DEEP_B] })
|
||||
expect(options(picker(view.container)).map(option => option.textContent))
|
||||
.toEqual(['work', 'alpha (pack)', 'beta (pack)'])
|
||||
// The ⋯ → Repository submenu reads the same label list.
|
||||
act(() => { view.container.querySelector<HTMLButtonElement>(`button[aria-label="${t('gitMoreActions')}"]`)!.click() })
|
||||
const parent = [...document.querySelectorAll<HTMLButtonElement>('button[role="menuitem"]')]
|
||||
.find(button => button.textContent?.trim() === t('gitRepository'))
|
||||
expect(parent).not.toBeUndefined()
|
||||
act(() => { parent!.click() })
|
||||
const items = [...document.querySelectorAll<HTMLButtonElement>('[role="menu"] [role="menu"] button[role="menuitem"]')]
|
||||
expect(items.map(item => item.textContent)).toEqual(['work', 'alpha (pack)', 'beta (pack)'])
|
||||
})
|
||||
|
||||
it('shows the server-fallback root as a disabled stand-in, never as a silent first option', async () => {
|
||||
// Picking ADMIN while the server resolves it to a checkout outside the
|
||||
// retained list: the picker must name THAT root (short label, disabled), not
|
||||
// quietly select the first option or keep the stale request.
|
||||
const FALLBACK = '/elsewhere/checkout'
|
||||
const view = await mount({
|
||||
sessionId: 'scm-repos-fallback',
|
||||
resolvedRoot: scope => scope.repoRoot === ADMIN ? FALLBACK : (scope.repoRoot ?? CWD),
|
||||
})
|
||||
await act(async () => {
|
||||
const node = picker(view.container)
|
||||
node.value = ADMIN
|
||||
node.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
})
|
||||
await flush()
|
||||
await flush()
|
||||
// A scope change resets the status slot, so the picker remounts; re-query.
|
||||
const node = picker(view.container)
|
||||
expect(node.value).toBe(FALLBACK)
|
||||
const standIn = node.selectedOptions[0]!
|
||||
expect(standIn.disabled).toBe(true)
|
||||
expect(standIn.textContent).toBe('checkout (elsewhere)')
|
||||
expect(options(node).map(option => option.value)).toEqual([CWD, ADMIN, DOCS])
|
||||
})
|
||||
Reference in new issue
Block a user