home-path-tilde.expected.e2e.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // @vitest-environment jsdom
  2. // Assembled POSIX home-path display: the fixture Host home is `/home/fixture`
  3. // and a second Workspace lives under it. The sidebar hover card must show
  4. // `~/Documents/project` while copy still writes the full path.
  5. import { mkdirSync, writeFileSync } from 'node:fs'
  6. import { dirname, join } from 'node:path'
  7. import { act, fireEvent, screen, waitFor, within } from '@testing-library/react'
  8. import { describe, expect, it } from 'vitest'
  9. import { installAssembledBootEnv, mountAssembledApp, REFRESHING_GOLDEN } from './assembled-boot.ts'
  10. const EXPECTED = join(process.cwd(), 'apps/web/tests/expected/home-path-tilde/workspace-hover.expected.txt')
  11. installAssembledBootEnv()
  12. describe('assembled POSIX home-path display', () => {
  13. it('shows the home-descendant Workspace path as ~ and copies the full path', async () => {
  14. mountAssembledApp()
  15. const tree = await screen.findByRole('tree', { name: 'Sessions' }, { timeout: 10_000 })
  16. const group = (await within(tree).findAllByText('project'))
  17. .map(el => el.closest<HTMLElement>('[role="treeitem"]'))
  18. .find(el => el?.getAttribute('aria-expanded') !== null)
  19. if (group == null) throw new Error('home-descendant Workspace group missing')
  20. fireEvent.pointerEnter(group.parentElement as HTMLElement)
  21. const hoverPath = await waitFor(() => {
  22. const found = screen.getByText('~/Documents/project')
  23. expect(found).toBeTruthy()
  24. return found
  25. }, { timeout: 2_000 })
  26. expect(screen.queryByText('/home/fixture/Documents/project')).toBeNull()
  27. const copy = screen.getByRole('button', { name: 'Copy: /home/fixture/Documents/project' })
  28. const shape = [
  29. `hover=${hoverPath.textContent}`,
  30. `copy=${copy.getAttribute('aria-label')}`,
  31. ].join('\n') + '\n'
  32. if (REFRESHING_GOLDEN) {
  33. mkdirSync(dirname(EXPECTED), { recursive: true })
  34. writeFileSync(EXPECTED, shape)
  35. }
  36. await expect(shape).toMatchFileSnapshot(EXPECTED)
  37. act(() => { fireEvent.pointerLeave(group.parentElement as HTMLElement) })
  38. })
  39. })