summaryrefslogtreecommitdiff
path: root/lua/99/test/in_flight_spec.lua
blob: c9ebc6bbc4d1a8166701a98a1aef7de3e97821ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
-- luacheck: globals describe it assert after_each
local _99 = require("99")
local Prompt = require("99.prompt")
local Window = require("99.window")
local test_utils = require("99.test.test_utils")
local eq = assert.are.same

local content = {
  "local function foo()",
  "  return 1",
  "end",
}

--- You have to override this or else things will crash since the ui itself
--- does not exist.  this is a headless test so i fake it by returning a very
--- simple ui of 120x40
local original_nvim_list_uis = vim.api.nvim_list_uis
local function nvim_list_uis()
  return {
    { width = 120, height = 40 },
  }
end

describe("in_flight window", function()
  local WAIT_TIME = 10
  before_each(function()
    vim.api.nvim_list_uis = nvim_list_uis
  end)
  after_each(function()
    vim.api.nvim_list_uis = original_nvim_list_uis
  end)
  it("shows active requests and clears when request completes", function()
    local provider = test_utils.test_setup(content, 2, 4)
    local state = _99.__get_state()
    local context = Prompt.search(state)

    context:start_request()
    vim.wait(WAIT_TIME * 2, function() end)

    eq(1, #Window.active_windows)

    local win = Window.active_windows[1]
    vim.api.nvim_win_close(win.win_id, true)

    vim.wait(WAIT_TIME * 2, function() end)
    local next_win = Window.active_windows[1]

    eq(true, win.win_id ~= next_win.win_id)

    provider:resolve("success", "results are in")

    vim.wait(WAIT_TIME * 2, function() end)
    eq(0, #Window.active_windows)
  end)

  it("enable false == do not show in flight", function()
    local provider = test_utils.test_setup(content, 2, 4, "lua", {
      in_flight_options = { enable = false },
    })
    local state = _99.__get_state()
    local context = Prompt.search(state)

    context:start_request()
    vim.wait(WAIT_TIME * 2, function() end)

    eq(0, #Window.active_windows)
    provider:resolve("success", "results are in")
    vim.wait(WAIT_TIME * 2, function() end)
    eq(0, #Window.active_windows)
  end)
end)