|
| 1 | +---@module 'luassert' |
| 2 | + |
| 3 | +require("spec.minimum_init") |
| 4 | + |
| 5 | +local paneui = require("rest-nvim.ui.panes") |
| 6 | +local utils = require("rest-nvim.utils") |
| 7 | + |
| 8 | +---@type rest.ui.panes.PaneOpts[] |
| 9 | +local panes = { |
| 10 | + { |
| 11 | + name = "First", |
| 12 | + render = function (self) |
| 13 | + vim.b[self.bufnr].name = "first" |
| 14 | + return true |
| 15 | + end, |
| 16 | + }, |
| 17 | + { |
| 18 | + name = "Second", |
| 19 | + render = function (self) |
| 20 | + vim.b[self.bufnr].name = "second" |
| 21 | + end, |
| 22 | + }, |
| 23 | +} |
| 24 | + |
| 25 | +local group = paneui.create_pane_group("test_panes_1", panes, { |
| 26 | + on_init = function (self) |
| 27 | + utils.nvim_lazy_set_wo(self.bufnr, "winbar", "this-is-a-winbar") |
| 28 | + end, |
| 29 | +}) |
| 30 | + |
| 31 | +describe("ui.panes", function () |
| 32 | + it("all panes are rendered", function () |
| 33 | + -- nothing happens before entering the pane |
| 34 | + assert.not_same("first", vim.b.name) |
| 35 | + assert.not_same("second", vim.b.name) |
| 36 | + assert.not_same("this-is-a-winbar", vim.api.nvim_get_option_value("winbar", { scope = "local" })) |
| 37 | + |
| 38 | + -- enter the pane |
| 39 | + group:enter(0) |
| 40 | + assert.same("first", vim.b.name) |
| 41 | + assert.same("this-is-a-winbar", vim.api.nvim_get_option_value("winbar", { scope = "local" })) |
| 42 | + |
| 43 | + -- cycle to second pane |
| 44 | + group:cycle(1) |
| 45 | + assert.same("second", vim.b.name) |
| 46 | + assert.same("this-is-a-winbar", vim.api.nvim_get_option_value("winbar", { scope = "local" })) |
| 47 | + |
| 48 | + -- cycle back to first pane |
| 49 | + group:cycle(3) |
| 50 | + assert.same("first", vim.b.name) |
| 51 | + assert.same("this-is-a-winbar", vim.api.nvim_get_option_value("winbar", { scope = "local" })) |
| 52 | + |
| 53 | + -- go back to original non-pane buffer |
| 54 | + vim.cmd.buffer(1) |
| 55 | + assert.not_same("first", vim.b.name) |
| 56 | + assert.not_same("second", vim.b.name) |
| 57 | + assert.not_same("this-is-a-winbar", vim.api.nvim_get_option_value("winbar", { scope = "local" })) |
| 58 | + end) |
| 59 | + it("initialize the buffer back after unloaded", function () |
| 60 | + assert.same(1, vim.api.nvim_get_current_buf()) |
| 61 | + group:enter(0) |
| 62 | + local pane_buf = vim.api.nvim_get_current_buf() |
| 63 | + assert.not_same(1, pane_buf) |
| 64 | + vim.cmd.bdelete() |
| 65 | + assert.same(1, vim.api.nvim_get_current_buf()) |
| 66 | + group:enter(0) |
| 67 | + assert.same(pane_buf, vim.api.nvim_get_current_buf()) |
| 68 | + assert.same("first", vim.b.name) |
| 69 | + assert.same("this-is-a-winbar", vim.api.nvim_get_option_value("winbar", { scope = "local" })) |
| 70 | + end) |
| 71 | +end) |
0 commit comments