test: preserve native focus sequence when discarding note drafts
Cross-platform packages / Validate source (push) Canceled after 0s
GoodBuddy Agent Release / Authorize Agent release (push) Canceled after 0s
Cross-platform packages / Authorize desktop packaging (push) Canceled after 0s
Cross-platform packages / linux arm64 (push) Canceled after 0s
Cross-platform packages / macos arm64 (push) Canceled after 0s
Cross-platform packages / windows arm64 (push) Canceled after 0s
Cross-platform packages / linux x64 (push) Canceled after 0s
Cross-platform packages / macos x64 (push) Canceled after 0s
Cross-platform packages / windows x64 (push) Canceled after 0s
Cross-platform packages / Publish GitHub and OSS release (push) Canceled after 0s
GoodBuddy Agent Release / Build darwin arm64 compound package (push) Canceled after 0s
GoodBuddy Agent Release / Build linux arm64 compound package (push) Canceled after 0s
GoodBuddy Agent Release / Build linux x64 compound package (push) Canceled after 0s
GoodBuddy Agent Release / Sign cumulative Agent catalog (push) Canceled after 0s
GoodBuddy Agent Release / Publish Agent to GitHub and OSS (push) Canceled after 0s

Wait for detail navigation and continued editing focus, and focus the cancel button before synthetic clicks so confirmation restores the actual opener. Keep draft discard and final entry focus assertions unchanged. Validate in CI without touching parallel work.
This commit is contained in:
mesalogo
2026-10-02 12:14:33 +08:00
parent 5368e0ecf4
commit 8280158edc
2 changed files with 14 additions and 2 deletions
@@ -825,14 +825,20 @@ describe('MagicNotesWorkspace overview navigation', () => {
it('cancels a new entry only after confirming that its draft will be discarded', async () => {
render(<MagicNotesWorkspace onNotify={onNotify} />)
await openNote()
await waitFor(() => expect(screen.getByRole('button', { name: '返回总览' })).toHaveFocus())
newEntry()
const composer = document.querySelector('.magic-note-composer')!
fireEvent.click(screen.getByTestId('magic-note-editor'))
fireEvent.click(within(composer as HTMLElement).getByRole('button', { name: '取消' }))
const cancel = within(composer as HTMLElement).getByRole('button', { name: '取消' })
// fireEvent.click does not focus like a native click; the modal must restore its actual opener.
cancel.focus()
fireEvent.click(cancel)
expect(await screen.findByRole('alertdialog')).toBeVisible()
fireEvent.click(screen.getByRole('button', { name: '继续编辑' }))
await waitFor(() => expect(screen.getByTestId('magic-note-editor')).toHaveFocus())
expect(document.querySelector('.magic-note-composer')).toHaveClass('magic-note-composer--active')
fireEvent.click(within(document.querySelector('.magic-note-composer') as HTMLElement).getByRole('button', { name: '取消' }))
cancel.focus()
fireEvent.click(cancel)
fireEvent.click(await screen.findByRole('button', { name: '放弃草稿并切换' }))
await waitFor(() => expect(document.querySelector('.magic-note-composer')).not.toHaveClass('magic-note-composer--active'))
await waitFor(() => expect(document.getElementById(`magic-note-entry-${entryId}`)).toHaveFocus())