-
-
Notifications
You must be signed in to change notification settings - Fork 166
Fix stale clocked header references when making edits to headers #759
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9d8fcca
Add test case for clock-out bug
ReeceStevens 8600c50
Force reload of clocked headline before clock operations
ReeceStevens 4eca40f
Merge branch 'master' into clock-fixes
kristijanhusak a9e8084
Upgrade tests to use new file loading schema
ReeceStevens be8bf14
Merge branch 'master' into clock-fixes
ReeceStevens 722b657
Remove clocking update when refreshing statusline
ReeceStevens 4f1f8e1
Merge branch 'clock-fixes' of github.com:ReeceStevens/orgmode into cl…
ReeceStevens 406ceb0
Move test to clock UI test file
ReeceStevens 1e2365d
Merge branch 'master' into clock-fixes
ReeceStevens bd648ee
Fix lint error
ReeceStevens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| local OrgFiles = require('orgmode.files') | ||
| local OrgFile = require('orgmode.files.file') | ||
| 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() | ||
| 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) | ||
|
|
||
| orgmode.files = OrgFiles:new({ | ||
| paths = { file.filename }, | ||
| }):load_sync(true, 20000) | ||
|
|
||
| -- Establish baseline: Test 1 is clocked in | ||
| local clock = org.clock:new({ files = orgmode.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) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The 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 comment
The 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.
Please move this test into https://github.com/nvim-orgmode/orgmode/blob/master/tests/plenary/ui/clock_spec.lua and adapt the setup around it. For example, you shouldn't do
OrgFiles:newdirectly.