portico/Tests/PorticoTests/MountTests.swift

42 lines
1.3 KiB
Swift

import Testing
import Gtk
@_spi(Portico) import Portico
@MainActor @Suite(.serialized) struct MountTests {
private func childCount(_ w: Gtk.Widget) -> Int {
var n = 0
var cur = w.getFirstChild()
while let c = cur { n += 1; cur = c.getNextSibling() }
return n
}
@Test func vstackAppendsChildrenInOrder() {
guard Gtk.initCheck() else { return }
let widget = AnyView(VStack(spacing: 0) {
Label("a")
Button("b") {}
}).makeWidget(MountContext())
#expect(childCount(widget) == 2)
}
@Test func hstackMountsLabelAndText() {
guard Gtk.initCheck() else { return }
let widget = AnyView(HStack(spacing: 0) {
Label("a")
Text("b")
}).makeWidget(MountContext())
#expect(childCount(widget) == 2)
}
@Test func buttonStoresAction() {
// Validates Portico-level contract: Button stores its action
// closure, and it is callable synchronously. The connectClicked
// signal wiring cannot be tested synchronously in P0 GTK's
// activateclicked chain requires a realized widget and main-loop
// iteration (~250ms timer), out of scope for unit tests.
var fired = false
let button = Button("x") { fired = true }
button.action()
#expect(fired)
}
}