forked from CopilotC-Nvim/CopilotChat.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotify_spec.lua
More file actions
126 lines (94 loc) · 2.88 KB
/
notify_spec.lua
File metadata and controls
126 lines (94 loc) · 2.88 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
local notify = require('CopilotChat.utils.notify')
describe('CopilotChat.notify', function()
before_each(function()
-- Clear all listeners before each test
notify.clear()
end)
describe('publish and listen', function()
it('calls listener when event is published', function()
local called = false
local received_data = nil
notify.listen('test_event', function(data)
called = true
received_data = data
end)
notify.publish('test_event', 'test_data')
assert.is_true(called)
assert.equals('test_data', received_data)
end)
it('supports multiple listeners for same event', function()
local count = 0
notify.listen('test_event', function(data)
count = count + 1
end)
notify.listen('test_event', function(data)
count = count + 10
end)
notify.publish('test_event', 'data')
assert.equals(11, count)
end)
it('does not call listeners for different events', function()
local called = false
notify.listen('event_a', function(data)
called = true
end)
notify.publish('event_b', 'data')
assert.is_false(called)
end)
it('passes correct data to listeners', function()
local received = nil
notify.listen('test_event', function(data)
received = data
end)
notify.publish('test_event', { foo = 'bar', num = 123 })
assert.are.same({ foo = 'bar', num = 123 }, received)
end)
it('handles nil and empty data', function()
local received = 'not_called'
notify.listen('test_event', function(data)
received = data
end)
notify.publish('test_event', nil)
assert.is_nil(received)
notify.publish('test_event', '')
assert.equals('', received)
end)
it('handles publishing to events with no listeners', function()
-- Should not error
assert.has_no.errors(function()
notify.publish('nonexistent_event', 'data')
end)
end)
end)
describe('clear', function()
it('removes all listeners', function()
local called = false
notify.listen('test_event', function(data)
called = true
end)
notify.clear()
notify.publish('test_event', 'data')
assert.is_false(called)
end)
it('allows adding new listeners after clear', function()
local called = false
notify.listen('test_event', function(data)
called = true
end)
notify.clear()
notify.listen('test_event', function(data)
called = true
end)
notify.publish('test_event', 'data')
assert.is_true(called)
end)
end)
describe('constants', function()
it('defines STATUS constant', function()
assert.equals('status', notify.STATUS)
end)
it('defines MESSAGE constant', function()
assert.equals('message', notify.MESSAGE)
end)
end)
end)