|
1 | 1 | local helpers = require('tests.plenary.helpers') |
2 | 2 | local Date = require('orgmode.objects.date') |
| 3 | +local orgmode = require('orgmode') |
3 | 4 |
|
4 | 5 | describe('Clock', function() |
5 | 6 | local files = {} |
@@ -149,4 +150,39 @@ describe('Clock', function() |
149 | 150 | assert.are.same('', vim.fn.getline(6)) |
150 | 151 | assert.are.same('', vim.fn.getline(7)) |
151 | 152 | end) |
| 153 | + |
| 154 | + it('should properly clock in an entry if unsaved edits were made to the buffer', function() |
| 155 | + local file = helpers.create_agenda_file({ |
| 156 | + '* TODO Test 1', |
| 157 | + ' :LOGBOOK:', |
| 158 | + ' CLOCK: [2024-05-22 Wed 05:15]', |
| 159 | + ' :END:', |
| 160 | + '* TODO Test 2', |
| 161 | + }) |
| 162 | + |
| 163 | + vim.cmd('edit ' .. file.filename) |
| 164 | + |
| 165 | + -- Establish baseline: Test 1 is clocked in |
| 166 | + local clock = orgmode.clock |
| 167 | + assert.are.same('Test 1', clock.clocked_headline:get_title()) |
| 168 | + assert.is_true(clock.clocked_headline:is_clocked_in()) |
| 169 | + |
| 170 | + -- Move the test 2 header above test 1 and then clock test 2 in |
| 171 | + vim.fn.cursor({ 5, 1 }) |
| 172 | + vim.cmd([[norm dd]]) |
| 173 | + vim.fn.cursor({ 1, 1 }) |
| 174 | + vim.cmd([[norm P]]) |
| 175 | + vim.fn.cursor({ 1, 1 }) |
| 176 | + clock:org_clock_in():wait() |
| 177 | + file:reload():wait() |
| 178 | + |
| 179 | + -- Test 2 is properly clocked in |
| 180 | + assert.are.same('Test 2', clock.clocked_headline:get_title()) |
| 181 | + assert.are.same('Test 2', file:get_headlines()[1]:get_title()) |
| 182 | + assert.is_true(file:get_headlines()[1]:is_clocked_in()) |
| 183 | + |
| 184 | + -- Test 1 is properly clocked out |
| 185 | + assert.are.same('Test 1', file:get_headlines()[2]:get_title()) |
| 186 | + assert.is_false(file:get_headlines()[2]:is_clocked_in()) |
| 187 | + end) |
152 | 188 | end) |
0 commit comments