Skip to content

Commit de02a0c

Browse files
fix(tests): Fix tests that causes false negative results
1 parent 2ce9a8d commit de02a0c

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

tests/plenary/ui/mappings/archive_spec.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('Archive', function()
1010
})
1111
assert.are.same(vim.fn.glob(vim.fn.fnamemodify(file.filename, ':p:h') .. '/**/*.org_archive', false, 1, 1), {})
1212

13+
local now = Date.now()
1314
vim.cmd([[exe "norm ,o$"]])
1415
-- Pause to finish the archiving
1516
vim.wait(50)
@@ -25,7 +26,7 @@ describe('Archive', function()
2526
assert.are.same({
2627
'* foobar',
2728
' :PROPERTIES:',
28-
' :ARCHIVE_TIME: ' .. Date.now():to_string(),
29+
' :ARCHIVE_TIME: ' .. now:to_string(),
2930
' :ARCHIVE_FILE: ' .. file.filename,
3031
' :ARCHIVE_CATEGORY: ' .. file:get_category(),
3132
' :ARCHIVE_TODO: ',
@@ -40,6 +41,7 @@ describe('Archive', function()
4041
'* foo',
4142
})
4243

44+
local now = Date.now()
4345
vim.cmd([[exe "norm ,o$"]])
4446
-- Pause to finish the archiving
4547
vim.wait(50)
@@ -51,7 +53,7 @@ describe('Archive', function()
5153
assert.are.same({
5254
'* foobar',
5355
' :PROPERTIES:',
54-
' :ARCHIVE_TIME: ' .. Date.now():to_string(),
56+
' :ARCHIVE_TIME: ' .. now:to_string(),
5557
' :ARCHIVE_FILE: ' .. file.filename,
5658
' :ARCHIVE_CATEGORY: ' .. file:get_category(),
5759
' :ARCHIVE_TODO: ',

tests/plenary/ui/mappings/todo_spec.lua

+28-18
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ describe('Todo mappings', function()
1919
' DEADLINE: <2021-07-21 Wed 22:02>',
2020
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
2121
vim.fn.cursor(3, 1)
22+
local now = Date.now()
2223

2324
-- Changing to DONE and adding closed date
2425
vim.cmd([[norm cit]])
2526
assert.are.same({
2627
'* DONE Test orgmode',
27-
' DEADLINE: <2021-07-21 Wed 22:02> CLOSED: [' .. Date.now():to_string() .. ']',
28+
' DEADLINE: <2021-07-21 Wed 22:02> CLOSED: [' .. now:to_string() .. ']',
2829
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
2930

3031
-- Removing todo keyword and removing closed date
@@ -59,15 +60,16 @@ describe('Todo mappings', function()
5960
'* TODO Another task',
6061
}, vim.api.nvim_buf_get_lines(0, 2, 6, false))
6162
vim.fn.cursor(3, 1)
63+
local now = Date.now()
6264
vim.cmd([[norm cit]])
6365
vim.wait(50)
6466
assert.are.same({
6567
'* TODO Test orgmode',
6668
' DEADLINE: <2021-09-14 Tue 12:00 +1w>',
6769
' :PROPERTIES:',
68-
' :LAST_REPEAT: [' .. Date.now():to_string() .. ']',
70+
' :LAST_REPEAT: [' .. now:to_string() .. ']',
6971
' :END:',
70-
' - State "DONE" from "TODO" [' .. Date.now():to_string() .. ']',
72+
' - State "DONE" from "TODO" [' .. now:to_string() .. ']',
7173
'',
7274
'* TODO Another task',
7375
}, vim.api.nvim_buf_get_lines(0, 2, 10, false))
@@ -125,33 +127,35 @@ describe('Todo mappings', function()
125127
'* TODO Another task',
126128
}, vim.api.nvim_buf_get_lines(0, 2, 6, false))
127129
vim.fn.cursor(3, 1)
130+
local now = Date.now()
128131
vim.cmd([[norm cit]])
129132
vim.wait(50)
130133
assert.are.same({
131134
'* TODO Test orgmode',
132135
' DEADLINE: <2021-09-14 Tue 12:00 +1w>',
133136
' :PROPERTIES:',
134-
' :LAST_REPEAT: [' .. Date.now():to_string() .. ']',
137+
' :LAST_REPEAT: [' .. now:to_string() .. ']',
135138
' :END:',
136139
' :LOGBOOK:',
137-
' - State "DONE" from "TODO" [' .. Date.now():to_string() .. ']',
140+
' - State "DONE" from "TODO" [' .. now:to_string() .. ']',
138141
' :END:',
139142
'',
140143
'* TODO Another task',
141144
}, vim.api.nvim_buf_get_lines(0, 2, 12, false))
142145

143146
vim.fn.cursor(3, 1)
147+
local now = Date.now()
144148
vim.cmd([[norm cit]])
145149
vim.wait(200)
146150
assert.are.same({
147151
'* TODO Test orgmode',
148152
' DEADLINE: <2021-09-21 Tue 12:00 +1w>',
149153
' :PROPERTIES:',
150-
' :LAST_REPEAT: [' .. Date.now():to_string() .. ']',
154+
' :LAST_REPEAT: [' .. now:to_string() .. ']',
151155
' :END:',
152156
' :LOGBOOK:',
153-
' - State "DONE" from "TODO" [' .. Date.now():to_string() .. ']',
154-
' - State "DONE" from "TODO" [' .. Date.now():to_string() .. ']',
157+
' - State "DONE" from "TODO" [' .. now:to_string() .. ']',
158+
' - State "DONE" from "TODO" [' .. now:to_string() .. ']',
155159
' :END:',
156160
'',
157161
'* TODO Another task',
@@ -179,11 +183,12 @@ describe('Todo mappings', function()
179183
' DEADLINE: <2021-07-21 Wed 22:02>',
180184
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
181185

186+
local now = Date.now()
182187
-- Changing to DONE and adding closed date
183188
vim.cmd([[norm ciT]])
184189
assert.are.same({
185190
'* DONE Test orgmode',
186-
' DEADLINE: <2021-07-21 Wed 22:02> CLOSED: [' .. Date.now():to_string() .. ']',
191+
' DEADLINE: <2021-07-21 Wed 22:02> CLOSED: [' .. now:to_string() .. ']',
187192
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
188193

189194
-- Setting TODO keyword, initial state
@@ -211,10 +216,11 @@ describe('Todo mappings', function()
211216
' <2021-07-21 Wed 22:02>',
212217
})
213218
vim.fn.cursor({ 3, 1 })
219+
local now = Date.now()
214220
vim.cmd([[norm cit]])
215221
assert.are.same({
216222
'* DONE Test orgmode',
217-
' CLOSED: [' .. Date.now():to_string() .. ']',
223+
' CLOSED: [' .. now:to_string() .. ']',
218224
' <2021-07-21 Wed 22:02>',
219225
}, vim.api.nvim_buf_get_lines(0, 2, 5, false))
220226
end)
@@ -266,16 +272,17 @@ describe('Todo mappings', function()
266272
}, vim.api.nvim_buf_get_lines(0, 2, 7, false))
267273
vim.fn.cursor(3, 3)
268274
vim.cmd([[norm citd]])
275+
local now = Date.now()
269276
vim.wait(50)
270277
assert.are.same({
271278
'* PHONECALL Call dad',
272279
' SCHEDULED: <2021-09-08 Wed 12:00 +1d>',
273280
' :PROPERTIES:',
274281
' :REPEAT_TO_STATE: PHONECALL',
275-
' :LAST_REPEAT: [' .. Date.now():to_string() .. ']',
282+
' :LAST_REPEAT: [' .. now:to_string() .. ']',
276283
' :END:',
277284
' :LOGBOOK:',
278-
' - State "DONE" from "PHONECALL" [' .. Date.now():to_string() .. ']',
285+
' - State "DONE" from "PHONECALL" [' .. now:to_string() .. ']',
279286
' :END:',
280287
}, vim.api.nvim_buf_get_lines(0, 2, 11, false))
281288
end)
@@ -300,17 +307,18 @@ describe('Todo mappings', function()
300307
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
301308

302309
vim.fn.cursor(3, 3)
310+
local now = Date.now()
303311
vim.cmd([[norm citd]])
304312
vim.wait(50)
305313

306314
assert.are.same({
307315
'* MEET Daily stand-up with the team',
308316
' SCHEDULED: <2021-09-08 Wed 09:00 +1d>',
309317
' :PROPERTIES:',
310-
' :LAST_REPEAT: [' .. Date.now():to_string() .. ']',
318+
' :LAST_REPEAT: [' .. now:to_string() .. ']',
311319
' :END:',
312320
' :LOGBOOK:',
313-
' - State "DONE" from "MEET" [' .. Date.now():to_string() .. ']',
321+
' - State "DONE" from "MEET" [' .. now:to_string() .. ']',
314322
' :END:',
315323
}, vim.api.nvim_buf_get_lines(0, 2, 10, false))
316324
end)
@@ -341,6 +349,7 @@ describe('Todo mappings', function()
341349
}, vim.api.nvim_buf_get_lines(0, 2, 7, false))
342350

343351
vim.fn.cursor(3, 3)
352+
local now = Date.now()
344353
vim.cmd([[norm citd]])
345354
vim.wait(50)
346355

@@ -349,10 +358,10 @@ describe('Todo mappings', function()
349358
' SCHEDULED: <2021-09-08 Wed 09:00 +1d>',
350359
' :PROPERTIES:',
351360
' :REPEAT_TO_STATE: PHONECALL',
352-
' :LAST_REPEAT: [' .. Date.now():to_string() .. ']',
361+
' :LAST_REPEAT: [' .. now:to_string() .. ']',
353362
' :END:',
354363
' :LOGBOOK:',
355-
' - State "DONE" from "MEET" [' .. Date.now():to_string() .. ']',
364+
' - State "DONE" from "MEET" [' .. now:to_string() .. ']',
356365
' :END:',
357366
}, vim.api.nvim_buf_get_lines(0, 2, 11, false))
358367
end)
@@ -383,6 +392,7 @@ describe('Todo mappings', function()
383392
}, vim.api.nvim_buf_get_lines(0, 2, 7, false))
384393

385394
vim.fn.cursor(3, 3)
395+
local now = Date.now()
386396
vim.cmd([[norm citd]])
387397
vim.wait(50)
388398

@@ -391,10 +401,10 @@ describe('Todo mappings', function()
391401
' SCHEDULED: <2021-09-08 Wed 09:00 +1d>',
392402
' :PROPERTIES:',
393403
' :REPEAT_TO_STATE: PHONECALL',
394-
' :LAST_REPEAT: [' .. Date.now():to_string() .. ']',
404+
' :LAST_REPEAT: [' .. now:to_string() .. ']',
395405
' :END:',
396406
' :LOGBOOK:',
397-
' - State "DONE" from "MEET" [' .. Date.now():to_string() .. ']',
407+
' - State "DONE" from "MEET" [' .. now:to_string() .. ']',
398408
' :END:',
399409
}, vim.api.nvim_buf_get_lines(0, 2, 11, false))
400410
end)

0 commit comments

Comments
 (0)