Skip to content

Commit 84483dd

Browse files
Tests: More progress on DeskTop basics, and some high level notes
1 parent 6bca5f0 commit 84483dd

File tree

2 files changed

+184
-0
lines changed

2 files changed

+184
-0
lines changed

tests/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,17 @@ Tests for the testing libraries themselves.
9999
## `desk_acc/`, `desktop/`, `disk_copy/`, `selector/`, `launcher/`
100100

101101
Tests specific to various components of the application.
102+
103+
# Tips For Authoring Tests
104+
105+
* Apple IIc and IIc+ models are slow in MAME. @mgcaret points out that on real hardware the processor slows to 1MHZ when accessing 800K drives. Prefer using a `superdrive` card in an Apple IIe instead.
106+
* Drive assignments are a pain, especialy with SCSI cards. See the [MAMEDEV Page](https://wiki.mamedev.org/index.php/Driver:Apple_II#More_configuration) for some notes. Basically, MAME does things bottom-up, whereas the Apple II ("autostart ROM") and SCSI do things top-down.
107+
* Controlling the mouse precisely with MAME is elusive, so MouseKeys mode is used in most tests. Is it most convenient with the `a2d.InMouseKeys()` helper. This works great with some exceptions:
108+
* Since it is quantized (and differently for x/y), errors creep in over time. Add an `m.Home()` if this happens.
109+
* You can't press shortcut keys or <kbd>Esc</kbd> in MouseKeys mode. This makes testing edge cases challenging.
110+
* The API in `a2d` is limited to driving the UI primarily through the keyboard. For example, `a2d.OpenPath()` works bu closing all windows, then using type-down selection on each segment followed by the OA+SA+Down shortcut to open the selection while closing the current window. This is generally sufficient but some things require creativity:
111+
* As noted, methods like `a2d.SelectPath()` and `a2d.OpenPath()` by default close all windows first. If you need multiple windows open for an operation you need get creative()
112+
* Add a shortcut (e.g. via `a2d.AddShortcut()`) for a dependent window, use `a2d.OpenPath()` to open the initial window, then `a2d.OAShortcut("1")` (etc) to open the second window.
113+
* Use the `{keep_windows=true}` option to override the default. But note that this works by setting focus to the desktop and opening windows via typing. If you open "/DISK1" and then try to open "/DISK1/FOLDER1" the second "hijacks" the window of the first. Re-ordering the actions is usually sufficient.
114+
* The `a2d` library implicitly has short waits after each action using `a2d.WaitForRepaint()`. The duration of this delay can (and should) be changed by calling `a2d.ConfigureRepaintTiming()`. While this is convenient, experience has shown that manual delays using `emu.wait(N)` after an action that "takes too long" are more maintainable; adding a single extra wait is better than trying to tweak the global settings.. Even better, of course, are using functions that delay until a milestone has been reached (the desktop is visible, an alert is showing, etc).
115+

tests/desktop/basics.lua

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ test.Step(
8585
end)
8686
a2d.WaitForRepaint()
8787
test.Snap("verify icon name is clipped on left but renders")
88+
89+
-- cleanup
90+
a2d.EraseVolume("RAM1")
8891
end)
8992

9093
--[[
@@ -182,6 +185,64 @@ end)
182185
Hold scroll arrow. Verify icon scrolls into view, and eventually the
183186
scrollbar deactivates. Repeat with right edge.
184187
]]
188+
test.Step(
189+
"scrollbar deactivates when not needed",
190+
function()
191+
a2d.CopyPath("/A2.DESKTOP/READ.ME", "/RAM1")
192+
a2d.SelectPath("/RAM1/READ.ME")
193+
194+
-- Left
195+
local icon_x, icon_y = a2dtest.GetSelectedIconCoords()
196+
local x, y, w, h = a2dtest.GetFrontWindowContentRect()
197+
198+
a2d.InMouseKeysMode(function(m)
199+
m.MoveToApproximately(icon_x, icon_y)
200+
m.ButtonDown()
201+
m.MoveToApproximately(x+5, icon_y)
202+
m.ButtonUp()
203+
end)
204+
a2d.WaitForRepaint()
205+
local hscroll, vscroll = a2dtest.GetFrontWindowScrollOptions()
206+
test.ExpectNotEquals(hscroll & mgtk.scroll.option_active, 0, "scrollbar should be active")
207+
208+
a2d.InMouseKeysMode(function(m)
209+
m.MoveToApproximately(x + 5, y + h + 5)
210+
m.ButtonDown()
211+
emu.wait(1)
212+
m.ButtonUp()
213+
end)
214+
a2d.WaitForRepaint()
215+
local hscroll, vscroll = a2dtest.GetFrontWindowScrollOptions()
216+
test.ExpectEquals(hscroll & mgtk.scroll.option_active, 0, "scrollbar should be inactive")
217+
218+
-- Right
219+
local icon_x, icon_y = a2dtest.GetSelectedIconCoords()
220+
local x, y, w, h = a2dtest.GetFrontWindowContentRect()
221+
222+
a2d.InMouseKeysMode(function(m)
223+
m.MoveToApproximately(icon_x, icon_y)
224+
m.ButtonDown()
225+
m.MoveToApproximately(x+w-5, icon_y)
226+
m.ButtonUp()
227+
end)
228+
a2d.WaitForRepaint()
229+
local hscroll, vscroll = a2dtest.GetFrontWindowScrollOptions()
230+
test.ExpectNotEquals(hscroll & mgtk.scroll.option_active, 0, "scrollbar should be active")
231+
232+
a2d.InMouseKeysMode(function(m)
233+
m.MoveToApproximately(x + w - 5, y + h + 5)
234+
m.ButtonDown()
235+
emu.wait(1)
236+
m.ButtonUp()
237+
end)
238+
a2d.WaitForRepaint()
239+
local hscroll, vscroll = a2dtest.GetFrontWindowScrollOptions()
240+
test.ExpectEquals(hscroll & mgtk.scroll.option_active, 0, "scrollbar should be inactive")
241+
242+
-- cleanup
243+
a2d.EraseVolume("RAM1")
244+
end)
245+
185246
--[[
186247
Launch DeskTop. Open a window with 11-15 icons. Verify scrollbars
187248
are not active.
@@ -198,6 +259,14 @@ end)
198259
Launch DeskTop. Open a folder using Apple menu (e.g. Control Panels)
199260
or a shortcut. Verify that the used/free numbers are non-zero.
200261
]]
262+
test.Step(
263+
"Windows opened from Apple Menu have used/free numbers",
264+
function()
265+
a2d.CloseAllWindows()
266+
a2d.InvokeMenuItem(a2d.APPLE_MENU, a2d.CONTROL_PANELS)
267+
emu.wait(1)
268+
test.Snap("verify the window has non-zero used/free numbers")
269+
end)
201270

202271
--[[
203272
Launch DeskTop. Open a folder containing subfolders. Select all the
@@ -208,6 +277,31 @@ end)
208277
parent window correctly shows only the previously opened folder as
209278
selected.
210279
]]
280+
test.Step(
281+
"Correct selection when child window is closed",
282+
function()
283+
a2d.OpenPath("/A2.DESKTOP/APPLE.MENU")
284+
a2d.Select("CONTROL.PANELS")
285+
local x, y = a2dtest.GetSelectedIconCoords()
286+
a2d.SelectAll()
287+
local count = #a2d.GetSelectedIcons()
288+
a2d.InMouseKeysMode(function(m)
289+
m.MoveToApproximately(x, y)
290+
m.DoubleClick()
291+
end)
292+
emu.wait(5)
293+
test.ExpectEquals(#a2d.GetSelectedIcons(), count, "selection should not have changed")
294+
while a2dtest.GetFrontWindowTitle():upper() ~= "APPLE.MENU" do
295+
a2d.CycleWindows()
296+
emu.wait(1)
297+
end
298+
test.Snap("verify selected folder icons are dimmed")
299+
a2d.CycleWindows()
300+
local name = a2dtest.GetFrontWindowTitle()
301+
a2d.CloseWindow()
302+
emu.wait(1)
303+
test.ExpectEqualsIgnoreCase(a2dtest.GetSelectedIconName(), name, "only closed window should be selected")
304+
end)
211305

212306
--[[
213307
Launch DeskTop. Open a window containing folders and files. Scroll
@@ -216,6 +310,43 @@ end)
216310
over the obscured part of the folder. Verify the folder doesn't
217311
highlight.
218312
]]
313+
test.Step(
314+
"dragging over obscured part of folder doesn't highlight",
315+
function()
316+
a2d.CreateFolder("/RAM1/FOLDER")
317+
a2d.CopyPath("/A2.DESKTOP/READ.ME", "/RAM1")
318+
a2d.OpenPath("/RAM1")
319+
320+
local x, y, w, h = a2dtest.GetFrontWindowContentRect()
321+
322+
a2d.Select("FOLDER")
323+
local x1, y1 = a2dtest.GetSelectedIconCoords()
324+
a2d.InMouseKeysMode(function(m)
325+
m.MoveToApproximately(x1, y1+5)
326+
m.ButtonDown()
327+
m.MoveByApproximately(0, -10)
328+
m.ButtonUp()
329+
end)
330+
331+
a2d.Select("READ.ME")
332+
local x2, y2 = a2dtest.GetSelectedIconCoords()
333+
a2d.InMouseKeysMode(function(m)
334+
m.MoveToApproximately(x2, y2)
335+
m.ButtonDown()
336+
m.MoveToApproximately(x2, y+5) -- Y only first
337+
m.MoveToApproximately(x1, y+5)
338+
emu.wait(5)
339+
test.Snap("verify folder not highlighted")
340+
m.ButtonUp()
341+
end)
342+
emu.wait(1)
343+
344+
a2d.Select("READ.ME") -- verify not moved
345+
346+
-- cleanup
347+
a2d.EraseVolume("/RAM1")
348+
end)
349+
219350
--[[
220351
Launch DeskTop. Open a window containing folders and files. Scroll
221352
the window so a folder is partially or fully outside the visual area
@@ -224,6 +355,44 @@ end)
224355
but doesn't render past window bounds. Continue dragging over the
225356
obscured part of the folder. Verify that the folder unhighlights.
226357
]]
358+
test.Step(
359+
"dragging over visible part of folder highlights, but highlights if needed",
360+
function()
361+
a2d.CreateFolder("/RAM1/FOLDER")
362+
a2d.CopyPath("/A2.DESKTOP/READ.ME", "/RAM1")
363+
a2d.OpenPath("/RAM1")
364+
365+
local x, y, w, h = a2dtest.GetFrontWindowContentRect()
366+
367+
a2d.Select("FOLDER")
368+
local x1, y1 = a2dtest.GetSelectedIconCoords()
369+
a2d.InMouseKeysMode(function(m)
370+
m.MoveToApproximately(x1, y1+5)
371+
m.ButtonDown()
372+
m.MoveByApproximately(0, -10)
373+
m.ButtonUp()
374+
end)
375+
376+
a2d.Select("READ.ME")
377+
local x2, y2 = a2dtest.GetSelectedIconCoords()
378+
a2d.InMouseKeysMode(function(m)
379+
m.MoveToApproximately(x2, y2)
380+
m.ButtonDown()
381+
m.MoveToApproximately(x1, y+15)
382+
emu.wait(5)
383+
test.Snap("verify folder highlighted")
384+
m.MoveToApproximately(x1, y+5)
385+
emu.wait(5)
386+
test.Snap("verify folder not highlighted")
387+
m.ButtonUp()
388+
end)
389+
emu.wait(1)
390+
391+
a2d.Select("READ.ME") -- verify not moved
392+
393+
-- cleanup
394+
a2d.EraseVolume("/RAM1")
395+
end)
227396

228397
--[[
229398
Launch DeskTop. Open two windows containing folders and files. Drag
@@ -893,6 +1062,7 @@ test.Step(
8931062
a2d.MoveWindowBy(20, 0)
8941063
test.Snap("verify icon B rendered correctly")
8951064

1065+
-- cleanup
8961066
a2d.EraseVolume("RAM1")
8971067
end)
8981068

0 commit comments

Comments
 (0)