Skip to content

Commit 3af042b

Browse files
committed
refactor(tests): update output_window scroll tracking tests
Update tests to reflect the new cursor-based scroll tracking logic in output_window. Remove references to the old viewport-based flag and simulate user actions by moving the cursor instead. This ensures tests align with the simplified auto-scroll behavior.
1 parent f78500e commit 3af042b

1 file changed

Lines changed: 14 additions & 31 deletions

File tree

tests/unit/cursor_tracking_spec.lua

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ describe('output_window.is_at_bottom', function()
220220
assert.is_true(output_window.is_at_bottom(win))
221221
end)
222222

223-
it('returns false when _was_at_bottom_by_win flag is explicitly false', function()
224-
-- Simulate user having scrolled away: flag is set to false
225-
output_window._was_at_bottom_by_win[win] = false
223+
it('returns false when cursor is not on last line', function()
224+
-- cursor not at last line
225+
vim.api.nvim_win_set_cursor(win, { 25, 0 })
226226
assert.is_false(output_window.is_at_bottom(win))
227227
end)
228228

@@ -232,16 +232,13 @@ describe('output_window.is_at_bottom', function()
232232
end)
233233

234234
it('returns false when user has scrolled viewport away from bottom', function()
235-
-- Simulate scrolling to bottom then user scrolling away
235+
-- Simulate scrolling to bottom then user pressing k to move cursor up
236236
local scroll = require('opencode.ui.renderer.scroll')
237237
scroll.scroll_win_to_bottom(win, buf)
238238
assert.is_true(output_window.is_at_bottom(win))
239239

240-
-- Simulate WinScrolled: user scrolls viewport up
241-
pcall(vim.api.nvim_win_call, win, function()
242-
vim.fn.winrestview({ topline = 1 })
243-
end)
244-
output_window.sync_cursor_with_viewport(win)
240+
-- User presses k: cursor moves away from the last line
241+
vim.api.nvim_win_set_cursor(win, { 40, 0 })
245242
assert.is_false(output_window.is_at_bottom(win))
246243
end)
247244

@@ -278,20 +275,14 @@ describe('output_window.is_at_bottom', function()
278275
pcall(vim.api.nvim_buf_delete, empty_buf, { force = true })
279276
end)
280277

281-
it('viewport-based: scrolling viewport up stops auto-scroll even when cursor stays at last line', function()
282-
-- Scroll to bottom so _was_at_bottom_by_win is set to true
278+
it('cursor-based: moving cursor up stops auto-scroll', function()
279+
-- Scroll to bottom: cursor is at last line
283280
local scroll = require('opencode.ui.renderer.scroll')
284281
scroll.scroll_win_to_bottom(win, buf)
285282
assert.is_true(output_window.is_at_bottom(win))
286283

287-
-- Scroll the viewport up without touching the cursor.
288-
-- WinScrolled fires → sync_cursor_with_viewport → _was_at_bottom_by_win = false
289-
pcall(vim.api.nvim_win_call, win, function()
290-
vim.fn.winrestview({ topline = 1 })
291-
end)
292-
output_window.sync_cursor_with_viewport(win)
293-
294-
-- Even though cursor is still at line 50, viewport has scrolled away
284+
-- User presses k: cursor moves away from last line → auto-scroll stops
285+
vim.api.nvim_win_set_cursor(win, { 40, 0 })
295286
assert.is_false(output_window.is_at_bottom(win))
296287
end)
297288

@@ -352,20 +343,12 @@ describe('output_window.sync_cursor_with_viewport', function()
352343
state.ui.set_windows(nil)
353344
end)
354345

355-
it('sets _was_at_bottom_by_win to false when viewport scrolls away from bottom', function()
356-
-- Start with viewport and cursor at last line
357-
vim.api.nvim_win_set_cursor(win, { 5, 0 })
358-
local scroll = require('opencode.ui.renderer.scroll')
359-
scroll.scroll_win_to_bottom(win, buf)
360-
assert.is_true(output_window._was_at_bottom_by_win[win])
361-
362-
-- Scroll the viewport up (simulate mouse wheel scroll)
363-
pcall(vim.api.nvim_win_call, win, function()
364-
vim.fn.winrestview({ topline = 1 })
365-
end)
346+
it('does not affect is_at_bottom when cursor is away from bottom', function()
347+
-- cursor not at last line
348+
vim.api.nvim_win_set_cursor(win, { 2, 0 })
366349
output_window.sync_cursor_with_viewport(win)
367350

368-
assert.is_false(output_window._was_at_bottom_by_win[win])
351+
assert.is_false(output_window.is_at_bottom(win))
369352
end)
370353

371354
it('does not move the cursor when the user is already reading earlier content', function()

0 commit comments

Comments
 (0)