-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathtest_status.lua
More file actions
156 lines (131 loc) · 4.18 KB
/
Copy pathtest_status.lua
File metadata and controls
156 lines (131 loc) · 4.18 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
local eq = MiniTest.expect.equality
local child_helper = require("tests.child_helper")
local child = child_helper.new_child_neovim("test_status")
local u = require("tests.utils")
local T = MiniTest.new_set({
hooks = {
pre_once = function() end,
pre_case = function()
child.run_pre_case(true)
end,
post_once = child.stop,
},
})
T["status()"] = MiniTest.new_set()
-- register handler tests
T["status()"]["register handler called immediately with current data"] = function()
child.configure_copilot()
local result = child.lua([[
local status = require("copilot.status")
local received = nil
status.register_status_notification_handler(function(data)
received = data
end)
return received ~= nil
]])
eq(result, true)
end
-- unregister handler tests
T["status()"]["unregister stops callbacks"] = function()
child.configure_copilot()
local result = child.lua([[
local status = require("copilot.status")
local call_count = 0
local handler = function(data)
call_count = call_count + 1
end
-- registering calls handler immediately
status.register_status_notification_handler(handler)
local count_after_register = call_count
-- unregister
status.unregister_status_notification_handler(handler)
-- simulate a notification - should not increment count
status.handlers.statusNotification(nil,
{ status = "Normal", message = "" },
{ client_id = 1, method = "statusNotification" })
return { after_register = count_after_register, final = call_count }
]])
eq(result.after_register, 1)
eq(result.final, 1) -- should not have been called again
end
-- statusNotification tests
T["status()"]["statusNotification broadcasts to all handlers"] = function()
child.configure_copilot()
local result = child.lua([[
local status = require("copilot.status")
local handler1_called = false
local handler2_called = false
status.register_status_notification_handler(function(data)
handler1_called = true
end)
status.register_status_notification_handler(function(data)
handler2_called = true
end)
-- Reset flags after initial registration calls
handler1_called = false
handler2_called = false
-- Fire notification
status.handlers.statusNotification(nil,
{ status = "Normal", message = "test" },
{ client_id = 1, method = "statusNotification" })
return { h1 = handler1_called, h2 = handler2_called }
]])
eq(result.h1, true)
eq(result.h2, true)
end
T["status()"]["statusNotification updates stored data"] = function()
child.configure_copilot()
local result = child.lua([[
local status = require("copilot.status")
status.handlers.statusNotification(nil,
{ status = "InProgress", message = "working" },
{ client_id = 42, method = "statusNotification" })
return { status = status.data.status, message = status.data.message, client_id = status.client_id }
]])
eq(result.status, "InProgress")
eq(result.message, "working")
eq(result.client_id, 42)
end
-- status display tests
T["status()"]["status shows Online when running"] = function()
child.configure_copilot()
child.lua([[
local status = require("copilot.status")
status.status()
]])
local messages = child.lua([[
local messages = ""
vim.wait(500, function()
messages = vim.api.nvim_exec("messages", { output = true }) or ""
return messages:find("Online")
end, 50)
return messages
]])
u.expect_match(messages, "Online")
end
T["status()"]["status shows Offline when disabled"] = function()
-- Override lsp.setup to return false, simulating disabled state
child.lua([[
local lsp = require("copilot.lsp")
lsp.setup = function(_, _)
return false
end
]])
child.lua([[
M.setup({
filetypes = { ["*"] = true },
})
]])
-- Wait for initialization
child.lua("vim.wait(200, function() return false end, 10)")
child.lua([[
local status = require("copilot.status")
status.status()
]])
local messages = child.lua([[
vim.wait(200, function() return false end, 10)
return vim.api.nvim_exec("messages", { output = true }) or ""
]])
u.expect_match(messages, "Offline")
end
return T