Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/mail/fixtures/draft_with_quotes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
From: me@example.com
To: alice@example.com
Subject: Re: Meeting tomorrow
Date: Mon, 7 Jul 2026 10:00:00 +0000

Thanks for the update, sounds good.

> On Mon, 7 Jul 2026, Alice wrote:
> Hi,
> Just confirming the meeting is at 2pm tomorrow.
> Let me know if that still works.
>
> Thanks,
> Alice
28 changes: 25 additions & 3 deletions tests/mail/navigate_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,31 @@ describe('mail.navigate', function()

describe('goto_reply', function()
it('jumps to first quoted line', function()
local buf = load_fixture('draft_reply_with_thread.txt')
-- This fixture has no quotes, so it should not move
-- Let's test with marker fixture which also has no quotes
local buf = load_fixture('draft_with_quotes.txt')
nav.goto_reply()
local pos = vim.api.nvim_win_get_cursor(0)
local line = vim.api.nvim_buf_get_lines(buf, pos[1] - 1, pos[1], false)[1]
assert.is_truthy(line:match('^>'))
-- Assert exact first-quote line (fixture: draft_with_quotes.txt line 8 is `> On Mon, ...`)
assert.are.equal(8, pos[1])
vim.api.nvim_buf_delete(buf, { force = true })
end)

it('does not move cursor when there are no quoted lines', function()
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_lines(buf, 0, -1, false, {
'From: a@b.com',
'To: c@d.com',
'Subject: Hello',
'',
'Just a plain body line.',
'No quotes here.',
})
vim.api.nvim_set_current_buf(buf)
vim.api.nvim_win_set_cursor(0, { 5, 0 })
nav.goto_reply()
local pos = vim.api.nvim_win_get_cursor(0)
assert.are.equal(5, pos[1])
vim.api.nvim_buf_delete(buf, { force = true })
Comment on lines +50 to 75

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To make the test suite more robust and ensure correct behavior, we should:

  1. Assert the exact line number (8) to verify that goto_reply() indeed jumps to the first quoted line, rather than just any line starting with >.
  2. Add a test case to verify that the cursor does not move if there are no quoted lines in the buffer.
      local buf = load_fixture('draft_with_quotes.txt')
      nav.goto_reply()
      local pos = vim.api.nvim_win_get_cursor(0)
      assert.are.equal(8, pos[1])
      local line = vim.api.nvim_buf_get_lines(buf, pos[1] - 1, pos[1], false)[1]
      assert.is_truthy(line:match('^>'))
      vim.api.nvim_buf_delete(buf, { force = true })
    end)

    it('does not move cursor if there are no quotes', function()
      local buf = vim.api.nvim_create_buf(false, true)
      vim.api.nvim_buf_set_lines(buf, 0, -1, false, {
        'From: me@example.com',
        'To: alice@example.com',
        '',
        'Hello Alice,',
        'This is a draft with no quotes.',
      })
      vim.api.nvim_set_current_buf(buf)
      vim.api.nvim_win_set_cursor(0, { 4, 0 })
      nav.goto_reply()
      local pos = vim.api.nvim_win_get_cursor(0)
      assert.are.equal(4, pos[1])
      vim.api.nvim_buf_delete(buf, { force = true })

end)
end)
Expand Down
Loading