Skip to content

Commit 5fb75bb

Browse files
Add basic tests for gui/notes widget
1 parent 4c98e7e commit 5fb75bb

3 files changed

Lines changed: 87 additions & 3 deletions

File tree

gui/notes.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ function NotesScreen:onDismiss()
348348
view = nil
349349
end
350350

351-
function main(options)
351+
function main()
352352
if not dfhack.isMapLoaded() or not dfhack.world.isFortressMode() then
353353
qerror('notes requires a fortress map to be loaded')
354354
end

test/gui/notes.lua

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
local gui = require('gui')
2+
local gui_notes = reqscript('gui/notes')
3+
local utils = require('utils')
4+
5+
-- local guidm = require('gui.dwarfmode')
6+
7+
config = {
8+
target = 'gui/notes',
9+
mode = 'fortress'
10+
}
11+
12+
local waypoints = df.global.plotinfo.waypoints
13+
local map_points = df.global.plotinfo.waypoints.points
14+
15+
local map_points_backup = nil
16+
17+
local function arrange_notes(notes)
18+
map_points_backup = utils.clone(map_points)
19+
map_points:resize(0)
20+
21+
for _, note in ipairs(notes or {}) do
22+
map_points:insert("#", {
23+
new=true,
24+
25+
id = waypoints.next_point_id,
26+
tile=88,
27+
fg_color=7,
28+
bg_color=0,
29+
name=note.name,
30+
comment=note.comment,
31+
pos=note.pos
32+
})
33+
end
34+
end
35+
36+
local function arrange_gui_notes(options)
37+
options = options or {}
38+
39+
arrange_notes(options.notes)
40+
41+
gui_notes.main()
42+
43+
local gui_notes = gui_notes.view
44+
45+
gui_notes:updateLayout()
46+
gui_notes:onRender()
47+
48+
return gui_notes
49+
end
50+
51+
local function cleanup(gui_notes)
52+
gui_notes:dismiss()
53+
54+
df.global.plotinfo.waypoints.points:resize(#map_points_backup)
55+
for ind, map_point in ipairs(map_points_backup) do
56+
df.global.plotinfo.waypoints.points[ind - 1] = map_point
57+
end
58+
map_points_backup = nil
59+
end
60+
61+
function test.load_gui_notes()
62+
local gui_notes = arrange_gui_notes()
63+
expect.eq(gui_notes.visible, true)
64+
cleanup(gui_notes)
65+
end
66+
67+
function test.provide_notes_list()
68+
local notes = {
69+
{name='note 1', comment='comment 1', pos={x=1, y=1, z=1}},
70+
{name='note 2', comment='comment 2', pos={x=2, y=2, z=2}},
71+
{name='note 3', comment='comment 3', pos={x=3, y=3, z=3}},
72+
}
73+
74+
local gui_notes = arrange_gui_notes({ notes=notes })
75+
local note_list = gui_notes.subviews.note_list:getChoices()
76+
77+
for ind, note in ipairs(notes) do
78+
local gui_note = note_list[ind]
79+
expect.eq(gui_note.text, note.name)
80+
expect.eq(gui_note.point.comment, note.comment)
81+
expect.table_eq(gui_note.point.pos, note.pos)
82+
end
83+
84+
expect.eq(gui_notes.visible, true)
85+
cleanup(gui_notes)
86+
end

test/overlay/notes.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ local function add_note(notes_overlay, pos, name, comment)
6262
gui.simulateInput(dfhack.gui.getCurViewscreen(true), 'CUSTOM_CTRL_ENTER')
6363
end
6464

65-
6665
function test.load_notes_overlay()
6766
local notes_overlay = install_notes_overlay()
6867
expect.ne(notes_overlay, nil)
@@ -167,7 +166,6 @@ end
167166
function test.delete_clicked_note()
168167
local notes_overlay = install_notes_overlay()
169168

170-
171169
local viewport = guidm.Viewport.get()
172170

173171
local half_x = math.floor((viewport.x1 + viewport.x2) / 2)

0 commit comments

Comments
 (0)