-
-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix stale clocked header references when making edits to headers #759
Changes from 3 commits
9d8fcca
8600c50
4eca40f
a9e8084
be8bf14
722b657
4f1f8e1
406ceb0
1e2365d
bd648ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
local OrgFiles = require('orgmode.files') | ||
local OrgFile = require('orgmode.files.file') | ||
local Files = require('orgmode.parser.files') | ||
local org = require('orgmode') | ||
|
||
describe('Clock', function() | ||
---@return OrgFile | ||
local load_file_sync = function(content, filename) | ||
content = content or {} | ||
filename = filename or vim.fn.tempname() .. '.org' | ||
vim.fn.writefile(content, filename) | ||
return OrgFile.load(filename):wait() | ||
end | ||
|
||
it('should properly close out an existing clock when clocking in a new headline', function() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this test is not needed. We already have a similar one. If you want to test some scenario that is not tested you can add a test to that linked file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kristijanhusak could you please point me to the existing test that is similar? I am not familiar with all the test files so some guidance would be appreciated. This test fails without the patch proposed here, so it does seem to be testing something the other tests are not covering-- keeping the currently clocked header up-to-date as the buffer changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok, it's not the same. I didn't notice that you are editing file before clocking in/out. |
||
local file = load_file_sync({ | ||
'* TODO Test 1', | ||
' :LOGBOOK:', | ||
' CLOCK: [2024-05-22 Wed 05:15]', | ||
' :END:', | ||
'* TODO Test 2', | ||
}) | ||
|
||
vim.cmd('edit ' .. file.filename) | ||
|
||
Files.file_loader = OrgFiles:new({ | ||
paths = { file.filename }, | ||
}) | ||
local files = Files.loader() | ||
files:add_to_paths(file.filename):wait() | ||
|
||
-- Establish baseline: Test 1 is clocked in | ||
local clock = org.clock:new({ files = files }) | ||
assert.are.same('Test 1', clock.clocked_headline:get_title()) | ||
assert.is_true(clock.clocked_headline:is_clocked_in()) | ||
|
||
-- Move the test 2 header above test 1 and then clock test 2 in | ||
vim.fn.cursor({ 5, 1 }) | ||
vim.cmd('normal! dd') | ||
vim.fn.cursor({ 1, 1 }) | ||
vim.cmd('normal! P') | ||
vim.fn.cursor({ 1, 1 }) | ||
clock:org_clock_in():wait() | ||
file:reload():wait() | ||
|
||
-- Test 2 is properly clocked in | ||
assert.are.same('Test 2', clock.clocked_headline:get_title()) | ||
assert.are.same('Test 2', file:get_headlines()[1]:get_title()) | ||
assert.is_true(file:get_headlines()[1]:is_clocked_in()) | ||
|
||
-- Test 1 is properly clocked out | ||
assert.are.same('Test 1', file:get_headlines()[2]:get_title()) | ||
assert.is_false(file:get_headlines()[2]:is_clocked_in()) | ||
end) | ||
end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file no longer exists, it was refactored to a different structure. You can check other tests how to set up your tests.