Skip to content

Commit 2269cbe

Browse files
Add edit note gui/notes test
1 parent af1cae2 commit 2269cbe

2 files changed

Lines changed: 48 additions & 4 deletions

File tree

gui/notes.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,11 @@ function NotesScreen:onDismiss()
350350
if self.should_disable_overlay then
351351
overlay.overlay_command({'disable', 'notes.map_notes'})
352352
end
353+
354+
if self.subviews.notes_window.note_manager then
355+
self.subviews.notes_window.note_manager:dismiss()
356+
end
357+
353358
view = nil
354359
end
355360

test/gui/notes.lua

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ local gui = require('gui')
22
local gui_notes = reqscript('gui/notes')
33
local utils = require('utils')
44
local guidm = require('gui.dwarfmode')
5-
6-
7-
-- local guidm = require('gui.dwarfmode')
5+
local overlay = require('plugins.overlay')
86

97
config = {
108
target = 'gui/notes',
@@ -49,7 +47,11 @@ local function arrange_gui_notes(options)
4947
gui_notes:updateLayout()
5048
gui_notes:onRender()
5149

52-
return gui_notes
50+
-- for some reasons running tests remove all overlays,
51+
-- but there are need for gui/notes tests
52+
overlay.rescan()
53+
54+
return gui_notes, gui_notes.subviews.notes_window
5355
end
5456

5557
local function cleanup(gui_notes)
@@ -214,6 +216,43 @@ function test.filter_notes()
214216
cleanup(gui_notes)
215217
end
216218

219+
function test.edit_note()
220+
local notes = {
221+
{name='green note 1', comment='comment 1', pos={x=1, y=1, z=1}},
222+
{name='green note 2', comment='comment 2', pos={x=2, y=2, z=2}},
223+
{name='blue note 3', comment='comment 3', pos={x=3, y=3, z=3}},
224+
}
225+
226+
local gui_notes, gui_notes_window = arrange_gui_notes({ notes=notes })
227+
local screen = dfhack.gui.getCurViewscreen(true)
228+
229+
gui.simulateInput(screen, 'KEYBOARD_CURSOR_DOWN')
230+
gui.simulateInput(screen, 'CUSTOM_CTRL_E')
231+
232+
local note_manager = gui_notes_window.note_manager
233+
expect.ne(note_manager, nil)
234+
235+
expect.eq(note_manager.subviews.name:getText(), 'green note 2')
236+
expect.eq(note_manager.subviews.comment:getText(), 'comment 2')
237+
238+
note_manager.subviews.name:setText('updated green note 2')
239+
note_manager.subviews.comment:setText('updated comment 2')
240+
local screen = dfhack.gui.getCurViewscreen(true)
241+
printall(screen.widgets)
242+
gui.simulateInput(dfhack.gui.getCurViewscreen(true), 'CUSTOM_CTRL_ENTER')
243+
244+
local note_list = gui_notes.subviews.note_list:getChoices()
245+
expect.eq(#note_list, 3)
246+
247+
local updated_note = note_list[2]
248+
249+
expect.eq(updated_note.text, 'updated green note 2')
250+
expect.eq(updated_note.point.name, 'updated green note 2')
251+
expect.eq(updated_note.point.comment, 'updated comment 2')
252+
253+
cleanup(gui_notes)
254+
end
255+
217256
function test.delete_note()
218257
local notes = {
219258
{name='green note 1', comment='comment 1', pos={x=1, y=1, z=1}},

0 commit comments

Comments
 (0)