feat: API to automatically open preview window after opening oil (#339)
This commit is contained in:
parent
52f1683c76
commit
57528bf9c5
6 changed files with 135 additions and 31 deletions
42
tests/preview_spec.lua
Normal file
42
tests/preview_spec.lua
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
require("plenary.async").tests.add_to_env()
|
||||
local TmpDir = require("tests.tmpdir")
|
||||
local oil = require("oil")
|
||||
local test_util = require("tests.test_util")
|
||||
local util = require("oil.util")
|
||||
|
||||
a.describe("oil preview", function()
|
||||
local tmpdir
|
||||
a.before_each(function()
|
||||
tmpdir = TmpDir.new()
|
||||
end)
|
||||
a.after_each(function()
|
||||
if tmpdir then
|
||||
tmpdir:dispose()
|
||||
end
|
||||
test_util.reset_editor()
|
||||
end)
|
||||
|
||||
a.it("opens preview window", function()
|
||||
tmpdir:create({ "a.txt" })
|
||||
oil.open(tmpdir.path)
|
||||
test_util.wait_oil_ready()
|
||||
a.wrap(oil.open_preview, 2)()
|
||||
local preview_win = util.get_preview_win()
|
||||
assert.not_nil(preview_win)
|
||||
assert(preview_win)
|
||||
local bufnr = vim.api.nvim_win_get_buf(preview_win)
|
||||
local preview_lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
||||
assert.are.same({ "a.txt" }, preview_lines)
|
||||
end)
|
||||
|
||||
a.it("opens preview window when open(preview={})", function()
|
||||
tmpdir:create({ "a.txt" })
|
||||
a.wrap(oil.open, 3)(tmpdir.path, { preview = {} })
|
||||
local preview_win = util.get_preview_win()
|
||||
assert.not_nil(preview_win)
|
||||
assert(preview_win)
|
||||
local bufnr = vim.api.nvim_win_get_buf(preview_win)
|
||||
local preview_lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
||||
assert.are.same({ "a.txt" }, preview_lines)
|
||||
end)
|
||||
end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue