Skip to content

Commit 7365937

Browse files
committed
Add test case for clock-out bug
1 parent cc51c19 commit 7365937

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/plenary/clock/init_spec.lua

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
local OrgFiles = require('orgmode.files')
2+
local OrgFile = require('orgmode.files.file')
3+
local Files = require('orgmode.parser.files')
4+
local org = require('orgmode')
5+
6+
describe('Clock', function()
7+
---@return OrgFile
8+
local load_file_sync = function(content, filename)
9+
content = content or {}
10+
filename = filename or vim.fn.tempname() .. '.org'
11+
vim.fn.writefile(content, filename)
12+
return OrgFile.load(filename):wait()
13+
end
14+
15+
it('should properly close out an existing clock when clocking in a new headline', function()
16+
local file = load_file_sync({
17+
'* TODO Test 1',
18+
' :LOGBOOK:',
19+
' CLOCK: [2024-05-22 Wed 05:15]',
20+
' :END:',
21+
'* TODO Test 2',
22+
})
23+
24+
vim.cmd('edit ' .. file.filename)
25+
26+
Files.file_loader = OrgFiles:new({
27+
paths = { file.filename },
28+
})
29+
local files = Files.loader()
30+
files:add_to_paths(file.filename):wait()
31+
32+
-- Establish baseline: Test 1 is clocked in
33+
local clock = org.clock:new({ files = files })
34+
assert.are.same('Test 1', clock.clocked_headline:get_title())
35+
assert.is_true(clock.clocked_headline:is_clocked_in())
36+
37+
-- Move the test 2 header above test 1 and then clock test 2 in
38+
vim.fn.cursor({ 5, 1 })
39+
vim.cmd('normal! dd')
40+
vim.fn.cursor({ 1, 1 })
41+
vim.cmd('normal! P')
42+
vim.fn.cursor({ 1, 1 })
43+
clock:org_clock_in():wait()
44+
file:reload():wait()
45+
46+
-- Test 2 is properly clocked in
47+
assert.are.same('Test 2', clock.clocked_headline:get_title())
48+
assert.are.same('Test 2', file:get_headlines()[1]:get_title())
49+
assert.is_true(file:get_headlines()[1]:is_clocked_in())
50+
51+
-- Test 1 is properly clocked out
52+
assert.are.same('Test 1', file:get_headlines()[2]:get_title())
53+
assert.is_false(file:get_headlines()[2]:is_clocked_in())
54+
end)
55+
end)

0 commit comments

Comments
 (0)