|
| 1 | +---@diagnostic disable: undefined-field, undefined-global |
| 2 | +-- Define helper aliases |
| 3 | +local new_set = MiniTest.new_set |
| 4 | +local expect, eq = MiniTest.expect, MiniTest.expect.equality |
| 5 | + |
| 6 | +-- Create (but not start) child Neovim object |
| 7 | +local child = MiniTest.new_child_neovim() |
| 8 | + |
| 9 | +local TL = require "tests/test_lib" |
| 10 | + |
| 11 | +-- Define main test set of this file |
| 12 | +local T = new_set { |
| 13 | + -- Register hooks |
| 14 | + hooks = { |
| 15 | + pre_once = function() |
| 16 | + TL.clearSessionFilesAndBuffers() |
| 17 | + end, |
| 18 | + -- This will be executed before every (even nested) case |
| 19 | + pre_case = function() |
| 20 | + -- Restart child process with custom 'init.lua' script |
| 21 | + child.restart { "-u", "scripts/minimal_init_mini.lua" } |
| 22 | + -- Load tested plugin |
| 23 | + child.lua [[M = require('auto-session').setup({ |
| 24 | + auto_save_enabled = false, |
| 25 | + auto_restore_enabled = false, |
| 26 | + })]] |
| 27 | + end, |
| 28 | + -- This will be executed one after all tests from this set are finished |
| 29 | + post_once = child.stop, |
| 30 | + }, |
| 31 | +} |
| 32 | + |
| 33 | +T["session lens"] = new_set {} |
| 34 | + |
| 35 | +T["session lens"]["save a default session"] = function() |
| 36 | + child.cmd("e " .. TL.test_file) |
| 37 | + expect.equality(1, child.fn.bufexists(TL.test_file)) |
| 38 | + child.cmd "SessionSave" |
| 39 | + |
| 40 | + expect.equality(1, child.fn.bufexists(TL.test_file)) |
| 41 | + expect.equality(1, vim.fn.filereadable(TL.default_session_path)) |
| 42 | +end |
| 43 | + |
| 44 | +T["session lens"]["save a named session"] = function() |
| 45 | + child.cmd("e " .. TL.test_file) |
| 46 | + expect.equality(1, child.fn.bufexists(TL.test_file)) |
| 47 | + child.cmd("SessionSave " .. TL.named_session_name) |
| 48 | + expect.equality(1, vim.fn.filereadable(TL.named_session_path)) |
| 49 | + |
| 50 | + child.cmd("e " .. TL.other_file) |
| 51 | + child.cmd "SessionSave project_x" |
| 52 | +end |
| 53 | + |
| 54 | +T["session lens"]["can load a session"] = function() |
| 55 | + expect.equality(0, child.fn.bufexists(TL.test_file)) |
| 56 | + child.cmd "SessionSearch" |
| 57 | + -- give the UI time to come up |
| 58 | + vim.loop.sleep(100) |
| 59 | + child.type_keys "project_x" |
| 60 | + child.type_keys "<cr>" |
| 61 | + -- give the session time to load |
| 62 | + vim.loop.sleep(500) |
| 63 | + expect.equality(1, child.fn.bufexists(TL.other_file)) |
| 64 | +end |
| 65 | + |
| 66 | +T["session lens"]["can delete a session"] = function() |
| 67 | + expect.equality(1, vim.fn.filereadable(TL.named_session_path)) |
| 68 | + child.cmd "SessionSearch" |
| 69 | + -- give the UI time to come up |
| 70 | + vim.loop.sleep(100) |
| 71 | + child.type_keys "mysession" |
| 72 | + child.type_keys "<c-d>" |
| 73 | + vim.loop.sleep(100) |
| 74 | + expect.equality(0, vim.fn.filereadable(TL.named_session_path)) |
| 75 | +end |
| 76 | + |
| 77 | +-- Return test set which will be collected and execute inside `MiniTest.run()` |
| 78 | +return T |
0 commit comments