Skip to content

Commit ffd9596

Browse files
committed
chore: fix tests
1 parent 6ced56d commit ffd9596

16 files changed

Lines changed: 170 additions & 107 deletions

lua/vgit/core/Buffer_spec.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ describe('Buffer:', function()
296296
buffer:set_lines({ 'test line' })
297297

298298
buffer:place_extmark_sign({
299-
col = 0,
299+
row = 0,
300300
name = 'GitSignsAdd',
301301
})
302302

@@ -310,7 +310,7 @@ describe('Buffer:', function()
310310
it('should clear all extmarks from the buffer', function()
311311
buffer:set_lines({ 'test line' })
312312

313-
buffer:place_extmark_sign({ col = 0, name = 'GitSignsAdd' })
313+
buffer:place_extmark_sign({ row = 0, name = 'GitSignsAdd' })
314314
local ns_id = buffer._sign_extmark.ns_id
315315
local before = vim.api.nvim_buf_get_extmarks(buffer.bufnr, ns_id, 0, -1, {})
316316
assert.is_true(#before > 0)
@@ -326,7 +326,7 @@ describe('Buffer:', function()
326326
it('should clear sign extmarks from the buffer', function()
327327
buffer:set_lines({ 'test line' })
328328

329-
buffer:place_extmark_sign({ col = 0, name = 'GitSignsAdd' })
329+
buffer:place_extmark_sign({ row = 0, name = 'GitSignsAdd' })
330330
local ns_id = buffer._sign_extmark.ns_id
331331
local before = vim.api.nvim_buf_get_extmarks(buffer.bufnr, ns_id, 0, -1, {})
332332
assert.is_true(#before > 0)

lua/vgit/features/buffer/Conflicts_spec.lua

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,26 @@ local eq = assert.are.same
66
local navigation_up_calls = {}
77
local navigation_down_calls = {}
88

9+
local window_get_cursor_return = { 1, 0 }
10+
local window_instance = {
11+
get_cursor = function()
12+
return window_get_cursor_return
13+
end,
14+
}
15+
916
local navigation_stub = {
1017
up = function(window, marks)
1118
navigation_up_calls[#navigation_up_calls + 1] = { window = window, marks = marks }
1219
end,
1320
down = function(window, marks)
1421
navigation_down_calls[#navigation_down_calls + 1] = { window = window, marks = marks }
1522
end,
23+
current_window = function()
24+
return window_instance
25+
end,
26+
get_current_cursor = function()
27+
return window_get_cursor_return
28+
end,
1629
}
1730

1831
local git_buffer_store_stub = {
@@ -21,12 +34,6 @@ local git_buffer_store_stub = {
2134
end,
2235
}
2336

24-
local window_get_cursor_return = { 1, 0 }
25-
local window_instance = {
26-
get_cursor = function()
27-
return window_get_cursor_return
28-
end,
29-
}
3037
local Window_stub = setmetatable({}, {
3138
__index = require('vgit.core.Object'),
3239
__call = function(_, ...)

lua/vgit/features/buffer/Hunks_spec.lua

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,30 @@ local git_buffer_store_stub = {
3333
for_each = function() end,
3434
}
3535

36+
local event_stub = require('tests.helpers.mock_event').create()
37+
38+
local window_lnum = 1
39+
local window_set_lnum_called = false
40+
local window_set_lnum_value = nil
41+
local window_instance = {
42+
get_cursor = function()
43+
return { window_lnum, 0 }
44+
end,
45+
get_lnum = function()
46+
return window_lnum
47+
end,
48+
set_lnum = function(self, lnum)
49+
window_set_lnum_called = true
50+
window_set_lnum_value = lnum
51+
end,
52+
}
53+
local Window_stub = setmetatable({}, {
54+
__index = {},
55+
__call = function(_, ...)
56+
return window_instance
57+
end,
58+
})
59+
3660
local navigation_up_called = false
3761
local navigation_up_args = {}
3862
local navigation_down_called = false
@@ -46,6 +70,20 @@ local navigation_stub = {
4670
navigation_down_called = true
4771
navigation_down_args = { window = window, hunks = hunks }
4872
end,
73+
current_window = function()
74+
return window_instance
75+
end,
76+
get_current_lnum = function()
77+
return window_lnum
78+
end,
79+
get_current_cursor = function()
80+
return { window_lnum, 0 }
81+
end,
82+
set_current_lnum = function(lnum)
83+
window_lnum = lnum
84+
window_set_lnum_called = true
85+
window_set_lnum_value = lnum
86+
end,
4987
}
5088

5189
local console_error_called = false
@@ -61,30 +99,6 @@ local console_stub = {
6199
info = function() end,
62100
}
63101

64-
local event_stub = require('tests.helpers.mock_event').create()
65-
66-
local window_lnum = 1
67-
local window_set_lnum_called = false
68-
local window_set_lnum_value = nil
69-
local window_instance = {
70-
get_cursor = function()
71-
return { window_lnum, 0 }
72-
end,
73-
get_lnum = function()
74-
return window_lnum
75-
end,
76-
set_lnum = function(self, lnum)
77-
window_set_lnum_called = true
78-
window_set_lnum_value = lnum
79-
end,
80-
}
81-
local Window_stub = setmetatable({}, {
82-
__index = {},
83-
__call = function(_, ...)
84-
return window_instance
85-
end,
86-
})
87-
88102
-- Install stubs BEFORE requiring Hunks
89103
package.loaded['vgit.core.event'] = event_stub
90104
package.loaded['vgit.core.Window'] = Window_stub
@@ -145,6 +159,7 @@ local function make_mock_buffer(opts)
145159
function buffer:is_valid()
146160
return opts.is_valid ~= false
147161
end
162+
function buffer:save() end
148163
return buffer
149164
end
150165

lua/vgit/features/screens/BranchView.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ local lazy = require('vgit.core.lazy')
33
local View = lazy('vgit.ui.View')
44
local console = lazy('vgit.core.console')
55
local repository = lazy('vgit.git.repository')
6-
local LayoutSpec = lazy('vgit.ui.layout.LayoutSpec')
76
local SearchComponent = lazy('vgit.ui.components.SearchComponent')
87

98
local BranchView = View:extend()
@@ -64,6 +63,11 @@ function BranchView:create(data)
6463
return true
6564
end
6665

66+
function BranchView:destroy()
67+
self._search_component = nil
68+
View.destroy(self)
69+
end
70+
6771
function BranchView:_on_select(value)
6872
self:destroy()
6973

lua/vgit/features/screens/CommitPickerView.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ local event = lazy('vgit.core.event')
55
local console = lazy('vgit.core.console')
66
local repository = lazy('vgit.git.repository')
77
local scene_setting = lazy('vgit.settings.scene')
8-
local LayoutSpec = lazy('vgit.ui.layout.LayoutSpec')
98
local display_service = lazy('vgit.ui.display_service')
109
local SearchComponent = lazy('vgit.ui.components.SearchComponent')
1110

lua/vgit/features/screens/FileDiffView_spec.lua

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,18 @@ describe('FileDiffView:', function()
158158
setup_view_mocks()
159159
end)
160160

161-
describe('_reconcile', function()
161+
describe('_refresh_diff', function()
162162
it('should return false when diff_component is nil', function()
163163
view._diff_component = nil
164-
local result = view:_reconcile()
164+
local result = view:_refresh_diff()
165165
assert.is_false(result)
166166
end)
167167

168168
it('should return false when diff_component is invalid', function()
169169
mock_diff.is_valid = function()
170170
return false
171171
end
172-
local result = view:_reconcile()
172+
local result = view:_refresh_diff()
173173
assert.is_false(result)
174174
end)
175175

@@ -189,7 +189,7 @@ describe('FileDiffView:', function()
189189
props_set = props
190190
end
191191

192-
view:_reconcile()
192+
view:_refresh_diff()
193193

194194
assert.is_true(refresh_called)
195195
assert.is_not_nil(props_set)
@@ -201,7 +201,7 @@ describe('FileDiffView:', function()
201201
view._refresh_diff_data = function()
202202
return nil
203203
end
204-
local result = view:_reconcile()
204+
local result = view:_refresh_diff()
205205
assert.is_false(result)
206206
end)
207207

@@ -218,7 +218,7 @@ describe('FileDiffView:', function()
218218
moved_to = idx
219219
end
220220

221-
view:_reconcile({ hunk_index = 3 })
221+
view:_refresh_diff({ hunk_index = 3 })
222222

223223
eq(3, moved_to)
224224
end)
@@ -236,7 +236,7 @@ describe('FileDiffView:', function()
236236
move_called = true
237237
end
238238

239-
view:_reconcile()
239+
view:_refresh_diff()
240240

241241
assert.is_false(move_called)
242242
end)
@@ -250,15 +250,15 @@ describe('FileDiffView:', function()
250250
}
251251
end
252252

253-
local result = view:_reconcile()
253+
local result = view:_refresh_diff()
254254
assert.is_true(result)
255255
end)
256256
end)
257257

258258
describe('toggle_view', function()
259-
it('should call _reconcile with hunk_index 1', function()
259+
it('should call _refresh_diff with hunk_index 1', function()
260260
local reconcile_opts = nil
261-
view._reconcile = function(_, opts)
261+
view._refresh_diff = function(_, opts)
262262
reconcile_opts = opts
263263
return true
264264
end
@@ -271,7 +271,7 @@ describe('FileDiffView:', function()
271271
end)
272272

273273
it('should revert is_staged on failure', function()
274-
view._reconcile = function()
274+
view._refresh_diff = function()
275275
return false
276276
end
277277
view._opts.is_staged = false
@@ -282,7 +282,7 @@ describe('FileDiffView:', function()
282282
end)
283283

284284
it('should keep is_staged flipped on success', function()
285-
view._reconcile = function()
285+
view._refresh_diff = function()
286286
return true
287287
end
288288
view._opts.is_staged = false
@@ -292,9 +292,9 @@ describe('FileDiffView:', function()
292292
assert.is_true(view._opts.is_staged)
293293
end)
294294

295-
it('should not call _reconcile when filename is nil', function()
295+
it('should not call _refresh_diff when filename is nil', function()
296296
local reconcile_called = false
297-
view._reconcile = function()
297+
view._refresh_diff = function()
298298
reconcile_called = true
299299
return true
300300
end
@@ -307,14 +307,14 @@ describe('FileDiffView:', function()
307307
end)
308308

309309
describe('reset_current', function()
310-
it('should call _reconcile after repo:reset', function()
310+
it('should call _refresh_diff after repo:reset', function()
311311
local reset_called = false
312312
local reconcile_called = false
313313

314314
mock_repo.reset = function()
315315
reset_called = true
316316
end
317-
view._reconcile = function()
317+
view._refresh_diff = function()
318318
reconcile_called = true
319319
return true
320320
end
@@ -337,7 +337,7 @@ describe('FileDiffView:', function()
337337
mock_repo.reset = function()
338338
reset_called = true
339339
end
340-
view._reconcile = function()
340+
view._refresh_diff = function()
341341
reconcile_called = true
342342
return true
343343
end
@@ -348,9 +348,9 @@ describe('FileDiffView:', function()
348348
assert.is_true(reconcile_called)
349349
end)
350350

351-
it('should not call _reconcile when is_staged', function()
351+
it('should not call _refresh_diff when is_staged', function()
352352
local reconcile_called = false
353-
view._reconcile = function()
353+
view._refresh_diff = function()
354354
reconcile_called = true
355355
return true
356356
end

lua/vgit/features/screens/ProjectDiffView.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local utils = lazy('vgit.core.utils')
55
local event = lazy('vgit.core.event')
66
local keymap = lazy('vgit.core.keymap')
77
local console = lazy('vgit.core.console')
8+
local navigation = lazy('vgit.core.navigation')
89
local repository = lazy('vgit.git.repository')
910
local scene_setting = lazy('vgit.settings.scene')
1011
local LayoutSpec = lazy('vgit.ui.layout.LayoutSpec')

lua/vgit/features/screens/StashView.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ local console = lazy('vgit.core.console')
77
local git_stash = lazy('vgit.git.git_stash')
88
local scene_setting = lazy('vgit.settings.scene')
99
local LayoutSpec = lazy('vgit.ui.layout.LayoutSpec')
10-
local statusline = lazy('vgit.core.statusline_state')
1110
local stash_view_setting = lazy('vgit.settings.stash_view')
1211
local SearchComponent = lazy('vgit.ui.components.SearchComponent')
1312
local PatchPreviewComponent = lazy('vgit.ui.components.PatchPreviewComponent')

lua/vgit/features/screens/WorktreeView.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ local console = lazy('vgit.core.console')
77
local git_repo = lazy('vgit.git.git_repo')
88
local repository = lazy('vgit.git.repository')
99
local git_worktree = lazy('vgit.git.git_worktree')
10-
local LayoutSpec = lazy('vgit.ui.layout.LayoutSpec')
1110
local SearchComponent = lazy('vgit.ui.components.SearchComponent')
1211

1312
local WorktreeView = View:extend()

0 commit comments

Comments
 (0)