chadtmiller.com/hud
A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts
place.hud.hudkit 0.5.0 Latest 5 packages
0
0
import Testing
@testable import HUDKit
/// What a pinned feed's buttons draw and do: Pin, Unpin and a row's Move
/// up and Move down are procedures' calls that read the tree again.
struct PinnedFeedsTests {
/// A call that reloads is not kept as done, so the same call drawn again
/// (a feed pinned, unpinned and pinned) can be sent again; one that
/// doesn't reload is done once, as before.
@MainActor @Test func aCallThatReloadsIsNotKeptAsDone() async throws {
let input: JSON = ["preference": ["$type": "social.grain.actor.defs#pinnedFeedsPref", "items": []]]
let call: JSON = ["method": "social.grain.actor.setPreference", "service": "did:web:grain.social#grain_appview", "input": input]
let pin = try #require(ActionSpec(["label": "Pin feed", "icon": "pin", "key": "k1", "reload": true, "call": call]))
let once = try #require(ActionSpec(["label": "Mark read", "key": "k2", "call": call]))
let view = ViewContext()
var reads = 0
view.onReload = { reads += 1 }
view.onAction = { _ in nil }
func send(_ spec: ActionSpec) async -> ActionRun {
let run = ActionRun()
let write = ActionCall.call(method: "social.grain.actor.setPreference", service: "did:web:grain.social#grain_appview", input: input)
run.send(.write(write), spec, view)
var turns = 0
while run.busy, turns < 1000 {
await Task.yield()
turns += 1
}
return run
}
let pinned = await send(pin)
#expect(reads == 1 && !pinned.ran.done && !pinned.finished)
#expect(ActionRun.remembered(pin, view) == Ran(done: false, made: nil))
let read = await send(once)
#expect(reads == 1 && read.ran.done && read.finished)
#expect(ActionRun.remembered(once, view) == Ran(done: true, made: nil))
}
/// A row's Move up and Move down draw arrows; Pin a pin, and Unpin a pin filled.
@Test func movesAndPinsHaveTheirIcons() {
#expect(Icons.symbol("up") == .system("arrow.up"))
#expect(Icons.symbol("down") == .system("arrow.down"))
#expect(Icons.symbol("pin") == .system("pin"))
#expect(Icons.symbol("pinned") == .system("pin.fill"))
}
}