Files
chandra/lib/dock/dock_wbtest.mbt
T
Claude 9a25d70f77
CI / test (push) Failing after 18s
Task manager: show an app icon on each window's pill
Each pill now starts with the app's icon: the same coloured tile with a
letter that the dock draws for that app id, so an app looks the same in
both. The app id comes from windows.all (the task-bar rows carry only
titles); windows without one fall back to a title-keyed tile. Pills
narrower than 72px show just the centred icon.

The tile drawing moves into lib/dock (app_icon, app_glyph) and the dock
uses it too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hm1XqzhrA4N8FyhuRa
2026-11-25 18:31:41 +00:00

80 lines
2.6 KiB
MoonBit

///|
fn apps() -> Array[@types.AppEntry] {
["a", "b", "c"].map(id => { id, name: id + "!", comment: "", category: "", glyph: id.to_upper() })
}
///|
test "tiles hit-test by slot and grow around the hovered one" {
let h = 34
assert_eq(tile_at(3, h, 0, 10), -1)
assert_eq(tile_at(3, h, 12, 10), 0)
assert_eq(tile_at(3, h, 12 + pitch(h), 10), 1)
assert_eq(tile_at(3, h, 12 + 5 * pitch(h), 10), -1)
assert_true(tile_size(1, 1, h) > tile_size(0, 1, h))
assert_eq(tile_size(2, 0, h), base_size(h))
}
///|
test "click launches the app under the pointer; move sets hover" {
let a = apps()
let (hv, redraw, launch) = handle(a, -1, 34, PointerMove({ x: 12, y: 10 }))
assert_eq(hv, 0)
assert_true(redraw)
assert_true(launch is None)
let (_, _, launch) = handle(a, hv, 34, PointerDown({ x: 12 + pitch(34), y: 10 }))
assert_eq(launch, Some("b"))
let (hv, redraw, _) = handle(a, 0, 34, PointerLeave)
assert_eq(hv, -1)
assert_true(redraw)
}
///|
test "render draws one tile and glyph per app, capped at max_tiles" {
let t : @theme.Tokens = {
name: "t",
palette: {
desktop_top: @ui.color(0, 0, 0, 255),
desktop_bottom: @ui.color(0, 0, 0, 255),
surface: @ui.color(30, 30, 30, 255),
surface_hover: @ui.color(40, 40, 40, 255),
surface_popup: @ui.color(30, 30, 30, 255),
foreground: @ui.color(255, 255, 255, 255),
foreground_muted: @ui.color(150, 150, 150, 255),
accent: @ui.color(60, 120, 220, 255),
accent_foreground: @ui.color(255, 255, 255, 255),
border: @ui.color(60, 60, 60, 255),
},
font_size: 14U,
radius: 6U,
spacing: 6U,
panel_height: 44U,
}
assert_eq(render(@ui.size(preferred_width(3), 34), t, apps(), -1).length(), 1 + 3 * 2)
let many = Array::makei(20, i => ({ id: i.to_string(), name: "n", comment: "", category: "", glyph: "x" } : @types.AppEntry))
assert_eq(render(@ui.size(300, 34), t, many, 2).length(), 1 + max_tiles * 2)
assert_eq(tile_name(apps(), 1), "b!")
assert_eq(tile_name(apps(), 9), "")
}
///|
test "app glyph comes from the app id's last part, else the title" {
assert_eq(app_glyph("org.gnome.Nautilus", "Files"), "N")
assert_eq(app_glyph("foot", ""), "F")
assert_eq(app_glyph("org.chandra.", "x"), "C")
assert_eq(app_glyph("", " terminal"), "T")
assert_eq(app_glyph("", ""), "?")
}
///|
test "an app's icon is its coloured tile plus glyph" {
let ops = app_icon(20, 17, 22, "foot", "F")
assert_eq(ops.length(), 2)
match ops[0] {
FillRect(f) => {
assert_eq(f.rect.x, 9)
assert_eq(f.color.r, tile_color("foot").r)
}
_ => fail("expected a tile")
}
}