test(e2e): 覆盖「两次插入之间夹文本」与「多行选区引用」,并补一条多行单测
真机 lane 的这条用例现在跑四种形状:两次文件 @(chip)、一次目录 @(纯文本 token)、
中间夹打字文本后再插一个文件 @、以及从 markdown 预览里框选多行后用选区弹窗插入
(payload 是带围栏的多行串)。每一段之后都要求既有 chip 数量与身份不变、纯文本 token
数量不变、且引文逐字落地(围栏与换行都在)。写成这样是因为旧实现在**任何一次**插入时
都会整份重写草稿,四种形状都会红。
lane 里踩到的两个选择器坑,注释已经写在用例上,避免下次再踩:
- 宿主为每个保留会话渲染隐藏 seat,`[data-sidebar-right-panel]` 会同时匹配隐藏副本,
沿它取 `.first()` 拿到的可能是不可见的那个(boundingBox 为 null / 文本节点没有 rect);
- markdown 预览模式会把 CodeMirror 宿主**保留但隐藏**(未保存草稿),所以定位必须
`filter({ visible: true })`,否则会选中隐藏的那份。
单测侧补一条:多行 payload 逐字交给宿主(围栏与换行不动)、既有 chip 的 occurrence 仍在、
`setDraft` 不被调用。
This commit is contained in:
1 parent
315ad5d5ff
commit
494f5e80d0
2 files changed
+75
No files matched your search
@@ -328,6 +328,23 @@ describe('appendToDraft', () => {
|
||||
expect(composer.setDrafts).toEqual([])
|
||||
})
|
||||
|
||||
it('hands a multi-line payload to the host verbatim and keeps the chip (selection quote)', () => {
|
||||
const composer = fakeComposer({
|
||||
draft: '@notes/ENV.md ',
|
||||
draftRev: 1,
|
||||
occurrences: [{ offset: 0, length: 13 }],
|
||||
})
|
||||
const quote = ['```diagram.md:1-9', '# Diagram', 'tail text', '```'].join('\n')
|
||||
expect(appendToDraft(composer.ctx, 's1', quote)).toBe(true)
|
||||
// The draft already ends with whitespace, so the payload arrives untouched:
|
||||
// no leading separator, every newline intact (the host renders them under
|
||||
// the composer's `white-space: pre-wrap`).
|
||||
expect(composer.events[0]?.payload.text).toBe(quote)
|
||||
expect(composer.read().draft).toBe(`@notes/ENV.md ${quote}`)
|
||||
expect(composer.read().occurrences).toEqual([{ offset: 0, length: 13 }])
|
||||
expect(composer.setDrafts).toEqual([])
|
||||
})
|
||||
|
||||
it('reports false — logs, and leaves the draft alone — when no listener handled the event', () => {
|
||||
const consoleWarn = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
|
||||
const composer = fakeComposer({ draft: 'hi', draftRev: 2 })
|
||||
|
||||
@@ -988,6 +988,64 @@ test('the explorer @-reference button keeps earlier chips (no whole-draft rewrit
|
||||
).toHaveCount(1, { timeout: 15_000 })
|
||||
await expect(chips, 'the folder insert must leave both chips intact').toHaveCount(2)
|
||||
|
||||
// Text typed BETWEEN two references must not change how either insert
|
||||
// behaves: the next reference still lands as its own chip, and the earlier
|
||||
// ones stay chips (the flattened-draft bug used to eat them on any insert).
|
||||
const composer = chips.first().locator('xpath=ancestor::*[@contenteditable="true"][1]')
|
||||
const typeInComposer = async (text: string): Promise<void> => {
|
||||
await composer.click()
|
||||
await page.keyboard.press('End')
|
||||
await page.keyboard.type(text)
|
||||
}
|
||||
|
||||
await typeInComposer('prose between mentions ')
|
||||
await expect(chips, 'typing must not touch the chips').toHaveCount(2)
|
||||
await referenceRow(SEEDED_README_FILE)
|
||||
await expect(
|
||||
chips,
|
||||
'a reference inserted after interleaved prose must add its own chip and keep the rest',
|
||||
).toHaveCount(3, { timeout: 15_000 })
|
||||
await expect(chips.first(), 'the first chip must still carry its own file').toContainText(SEEDED_FILE)
|
||||
await expect(
|
||||
page.locator('[data-composer-text-ref]'),
|
||||
'the folder token stays the only plain-text reference',
|
||||
).toHaveCount(1)
|
||||
|
||||
// The viewer's selection popup: its payload is a fenced MULTI-LINE string
|
||||
// that rides the same plain-text insert. It must arrive verbatim (newlines
|
||||
// included) and leave every chip alone.
|
||||
const mdRow = pane.locator(`[role="button"][title$="${SEEDED_MD_FILE}"]:visible`)
|
||||
await expect(mdRow).toHaveCount(1, { timeout: 30_000 })
|
||||
await mdRow.click({ position: { x: 8, y: 8 } }) // open the file (not the @ action)
|
||||
await expect(pane.getByText('tail text')).toHaveCount(1, { timeout: 30_000 })
|
||||
// A multi-line selection in the code viewer (CodeMirror): the editor path
|
||||
// raises the same popup with a fenced payload carrying the file and its line
|
||||
// range — the multi-line shape this module has to hand over verbatim.
|
||||
// The preview keeps a hidden CodeMirror host mounted (unsaved edits), so
|
||||
// every locator here has to filter for the VISIBLE copy.
|
||||
const heading = pane.getByText('Diagram', { exact: true }).filter({ visible: true }).first()
|
||||
const tail = pane.getByText('tail text', { exact: true }).filter({ visible: true }).first()
|
||||
const headingBox = await heading.boundingBox()
|
||||
const tailBox = await tail.boundingBox()
|
||||
expect(headingBox, 'the visible preview heading must be laid out').not.toBeNull()
|
||||
expect(tailBox, 'the visible preview line must be laid out').not.toBeNull()
|
||||
await page.mouse.move(headingBox!.x + 2, headingBox!.y + headingBox!.height / 2)
|
||||
await page.mouse.down()
|
||||
await page.mouse.move(tailBox!.x + tailBox!.width - 2, tailBox!.y + tailBox!.height / 2, { steps: 8 })
|
||||
await page.mouse.up()
|
||||
|
||||
const quoteButton = page.getByRole('button', { name: /Add to conversation|添加到对话/ })
|
||||
await expect(quoteButton, 'the selection popup must offer the quote').toHaveCount(1, { timeout: 10_000 })
|
||||
await quoteButton.click()
|
||||
await expect(
|
||||
chips,
|
||||
'the multi-line quote must leave every chip intact',
|
||||
).toHaveCount(3, { timeout: 15_000 })
|
||||
const composed = await composer.evaluate((element) => element.textContent ?? '')
|
||||
expect(composed, 'the quote must arrive verbatim, fences and newlines included').toContain('```')
|
||||
expect(composed, 'the quote must keep its line breaks').toContain('\n')
|
||||
expect(composed).toContain('tail text')
|
||||
|
||||
expect(pageErrors, 'no page error while inserting references').toEqual([])
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user