11local gui = require (' gui' )
22local gui_notes = reqscript (' gui/notes' )
33local utils = require (' utils' )
4+ local guidm = require (' gui.dwarfmode' )
5+
46
57-- local guidm = require('gui.dwarfmode')
68
@@ -22,14 +24,16 @@ local function arrange_notes(notes)
2224 map_points :insert (" #" , {
2325 new = true ,
2426
25- id = waypoints .next_point_id ,
27+ id = waypoints .next_point_id ,
2628 tile = 88 ,
2729 fg_color = 7 ,
2830 bg_color = 0 ,
2931 name = note .name ,
3032 comment = note .comment ,
3133 pos = note .pos
3234 })
35+
36+ waypoints .next_point_id = waypoints .next_point_id + 1
3337 end
3438end
3539
@@ -81,6 +85,160 @@ function test.provide_notes_list()
8185 expect .table_eq (gui_note .point .pos , note .pos )
8286 end
8387
84- expect .eq (gui_notes .visible , true )
88+ cleanup (gui_notes )
89+ end
90+
91+ function test .auto_select_first_note ()
92+ local notes = {
93+ {name = ' green note 1' , comment = ' comment 1' , pos = {x = 1 , y = 1 , z = 1 }},
94+ {name = ' green note 2' , comment = ' comment 2' , pos = {x = 2 , y = 2 , z = 2 }},
95+ {name = ' blue note 3' , comment = ' comment 3' , pos = {x = 3 , y = 3 , z = 3 }},
96+ }
97+
98+ local gui_notes = arrange_gui_notes ({ notes = notes })
99+ expect .eq (gui_notes .subviews .name .text_to_wrap , ' green note 1' )
100+ expect .eq (gui_notes .subviews .comment .text_to_wrap , ' comment 1' )
101+
102+ cleanup (gui_notes )
103+ end
104+
105+ function test .select_on_arrow_up_down ()
106+ local notes = {
107+ {name = ' green note 1' , comment = ' comment 1' , pos = {x = 1 , y = 1 , z = 1 }},
108+ {name = ' green note 2' , comment = ' comment 2' , pos = {x = 2 , y = 2 , z = 2 }},
109+ {name = ' blue note 3' , comment = ' comment 3' , pos = {x = 3 , y = 3 , z = 3 }},
110+ }
111+
112+ local gui_notes = arrange_gui_notes ({ notes = notes })
113+ local screen = dfhack .gui .getCurViewscreen (true )
114+
115+ gui .simulateInput (screen , ' KEYBOARD_CURSOR_DOWN' )
116+ expect .eq (gui_notes .subviews .name .text_to_wrap , ' green note 2' )
117+ expect .eq (gui_notes .subviews .comment .text_to_wrap , ' comment 2' )
118+
119+ gui .simulateInput (screen , ' KEYBOARD_CURSOR_DOWN' )
120+ expect .eq (gui_notes .subviews .name .text_to_wrap , ' blue note 3' )
121+ expect .eq (gui_notes .subviews .comment .text_to_wrap , ' comment 3' )
122+
123+ gui .simulateInput (screen , ' KEYBOARD_CURSOR_DOWN' )
124+ expect .eq (gui_notes .subviews .name .text_to_wrap , ' green note 1' )
125+ expect .eq (gui_notes .subviews .comment .text_to_wrap , ' comment 1' )
126+
127+ gui .simulateInput (screen , ' KEYBOARD_CURSOR_UP' )
128+ expect .eq (gui_notes .subviews .name .text_to_wrap , ' blue note 3' )
129+ expect .eq (gui_notes .subviews .comment .text_to_wrap , ' comment 3' )
130+
131+ gui .simulateInput (screen , ' KEYBOARD_CURSOR_UP' )
132+ expect .eq (gui_notes .subviews .name .text_to_wrap , ' green note 2' )
133+ expect .eq (gui_notes .subviews .comment .text_to_wrap , ' comment 2' )
134+
135+ cleanup (gui_notes )
136+ end
137+
138+ function test .center_at_submit_note ()
139+ local notes = {
140+ {name = ' green note 1' , comment = ' comment 1' , pos = {x = 1 , y = 1 , z = 1 }},
141+ {name = ' green note 2' , comment = ' comment 2' , pos = {x = 2 , y = 2 , z = 2 }},
142+ {name = ' blue note 3' , comment = ' comment 3' , pos = {x = 3 , y = 3 , z = 3 }},
143+ }
144+
145+ local gui_notes = arrange_gui_notes ({ notes = notes })
146+ local screen = dfhack .gui .getCurViewscreen (true )
147+
148+ -- it would be best to check viewport, but it's not updated instantly
149+ -- and I do not know way how to force it
150+ -- local viewport = guidm.Viewport.get()
151+
152+ local last_recenter_pos = nil
153+ mock .patch (dfhack .gui , ' pauseRecenter' , function (pos )
154+ last_recenter_pos = pos
155+ end , function ()
156+ gui .simulateInput (screen , ' KEYBOARD_CURSOR_DOWN' )
157+ gui .simulateInput (screen , ' SELECT' )
158+
159+ expect .eq (last_recenter_pos .x , 2 )
160+ expect .eq (last_recenter_pos .y , 2 )
161+ expect .eq (last_recenter_pos .z , 2 )
162+
163+ gui .simulateInput (screen , ' KEYBOARD_CURSOR_DOWN' )
164+ gui .simulateInput (screen , ' SELECT' )
165+
166+ expect .eq (last_recenter_pos .x , 3 )
167+ expect .eq (last_recenter_pos .y , 3 )
168+ expect .eq (last_recenter_pos .z , 3 )
169+ end )
170+
171+ cleanup (gui_notes )
172+ end
173+
174+ function test .filter_notes ()
175+ local notes = {
176+ {name = ' green note 1' , comment = ' comment 1' , pos = {x = 1 , y = 1 , z = 1 }},
177+ {name = ' green note 2' , comment = ' comment 2' , pos = {x = 2 , y = 2 , z = 2 }},
178+ {name = ' blue note 3' , comment = ' comment 3' , pos = {x = 3 , y = 3 , z = 3 }},
179+ }
180+
181+ local gui_notes = arrange_gui_notes ({ notes = notes })
182+ gui_notes .subviews .search :setText (' green' )
183+
184+ local note_list = gui_notes .subviews .note_list :getChoices ()
185+ expect .eq (# note_list , 2 )
186+
187+ for ind , note in ipairs ({table.unpack (notes , 1 , 2 )}) do
188+ local gui_note = note_list [ind ]
189+ expect .eq (gui_note .text , note .name )
190+ expect .eq (gui_note .point .comment , note .comment )
191+ expect .table_eq (gui_note .point .pos , note .pos )
192+ end
193+
194+ expect .eq (gui_notes .subviews .name .text_to_wrap , ' green note 1' )
195+ expect .eq (gui_notes .subviews .comment .text_to_wrap , ' comment 1' )
196+
197+ gui_notes .subviews .search :setText (' blue' )
198+
199+ local note_list = gui_notes .subviews .note_list :getChoices ()
200+ expect .eq (# note_list , 1 )
201+
202+ expect .eq (note_list [1 ].text , notes [3 ].name )
203+ expect .eq (note_list [1 ].point .comment , notes [3 ].comment )
204+ expect .table_eq (note_list [1 ].point .pos , notes [3 ].pos )
205+
206+ expect .eq (gui_notes .subviews .name .text_to_wrap , ' blue note 3' )
207+ expect .eq (gui_notes .subviews .comment .text_to_wrap , ' comment 3' )
208+
209+ gui_notes .subviews .search :setText (' red' )
210+
211+ local note_list = gui_notes .subviews .note_list :getChoices ()
212+ expect .eq (# note_list , 0 )
213+
214+ cleanup (gui_notes )
215+ end
216+
217+ function test .delete_note ()
218+ local notes = {
219+ {name = ' green note 1' , comment = ' comment 1' , pos = {x = 1 , y = 1 , z = 1 }},
220+ {name = ' green note 2' , comment = ' comment 2' , pos = {x = 2 , y = 2 , z = 2 }},
221+ {name = ' blue note 3' , comment = ' comment 3' , pos = {x = 3 , y = 3 , z = 3 }},
222+ }
223+
224+ local gui_notes = arrange_gui_notes ({ notes = notes })
225+ local screen = dfhack .gui .getCurViewscreen (true )
226+
227+ gui .simulateInput (screen , ' KEYBOARD_CURSOR_DOWN' )
228+ gui .simulateInput (screen , ' CUSTOM_CTRL_D' )
229+
230+ local note_list = gui_notes .subviews .note_list :getChoices ()
231+ expect .eq (# note_list , 2 )
232+
233+ for ind , note in ipairs ({notes [1 ], notes [3 ]}) do
234+ local gui_note = note_list [ind ]
235+ expect .eq (gui_note .text , note .name )
236+ expect .eq (gui_note .point .comment , note .comment )
237+ expect .table_eq (gui_note .point .pos , note .pos )
238+ end
239+
240+ expect .eq (gui_notes .subviews .name .text_to_wrap , ' blue note 3' )
241+ expect .eq (gui_notes .subviews .comment .text_to_wrap , ' comment 3' )
242+
85243 cleanup (gui_notes )
86244end
0 commit comments