Files
bot/apps/macos/Tests/BotIPCTests/WindowPlacementTests.swift
zeekay ca704d3e6a chore: rebrand openclaw → hanzo-bot for bridge merge
Comprehensive rename of all openclaw references to hanzo-bot equivalents:
- Package: openclaw → @hanzo/bot
- Binary: openclaw → hanzo-bot
- Types: OpenClaw* → Bot*
- Env vars: OPENCLAW_* → BOT_*
- Android: ai.openclaw.android → ai.hanzo.bot.android
- iOS/macOS: ai.openclaw.* → ai.hanzo.*
- Swift modules: OpenClaw* → Bot*
- Plugins: openclaw.plugin.json → bot.plugin.json
- Paths: .openclaw/ → .hanzo/bot/
- URLs: github.com/openclaw → github.com/hanzoai
2026-02-26 22:36:01 -08:00

86 lines
2.9 KiB
Swift

import AppKit
import Testing
@testable import HanzoBot
@Suite
@MainActor
struct WindowPlacementTests {
@Test
func centeredFrameZeroBoundsFallsBackToOrigin() {
let frame = WindowPlacement.centeredFrame(size: NSSize(width: 120, height: 80), in: NSRect.zero)
#expect(frame.origin == .zero)
#expect(frame.size == NSSize(width: 120, height: 80))
}
@Test
func centeredFrameClampsToBoundsAndCenters() {
let bounds = NSRect(x: 10, y: 20, width: 300, height: 200)
let frame = WindowPlacement.centeredFrame(size: NSSize(width: 600, height: 120), in: bounds)
#expect(frame.size.width == bounds.width)
#expect(frame.size.height == 120)
#expect(frame.minX == bounds.minX)
#expect(frame.midY == bounds.midY)
}
@Test
func topRightFrameZeroBoundsFallsBackToOrigin() {
let frame = WindowPlacement.topRightFrame(
size: NSSize(width: 120, height: 80),
padding: 12,
in: NSRect.zero)
#expect(frame.origin == .zero)
#expect(frame.size == NSSize(width: 120, height: 80))
}
@Test
func topRightFrameClampsToBoundsAndAppliesPadding() {
let bounds = NSRect(x: 10, y: 20, width: 300, height: 200)
let frame = WindowPlacement.topRightFrame(
size: NSSize(width: 400, height: 50),
padding: 8,
in: bounds)
#expect(frame.size.width == bounds.width)
#expect(frame.size.height == 50)
#expect(frame.maxX == bounds.maxX - 8)
#expect(frame.maxY == bounds.maxY - 8)
}
@Test
func ensureOnScreenUsesFallbackWhenWindowOffscreen() {
let window = NSWindow(
contentRect: NSRect(x: 100_000, y: 100_000, width: 200, height: 120),
styleMask: [.borderless],
backing: .buffered,
defer: false)
WindowPlacement.ensureOnScreen(
window: window,
defaultSize: NSSize(width: 200, height: 120),
fallback: { _ in NSRect(x: 11, y: 22, width: 33, height: 44) })
#expect(window.frame == NSRect(x: 11, y: 22, width: 33, height: 44))
}
@Test
func ensureOnScreenDoesNotMoveVisibleWindow() {
let screen = NSScreen.main ?? NSScreen.screens.first
#expect(screen != nil)
guard let screen else { return }
let visible = screen.visibleFrame.insetBy(dx: 40, dy: 40)
let window = NSWindow(
contentRect: NSRect(x: visible.minX, y: visible.minY, width: 200, height: 120),
styleMask: [.titled],
backing: .buffered,
defer: false)
let original = window.frame
WindowPlacement.ensureOnScreen(
window: window,
defaultSize: NSSize(width: 200, height: 120),
fallback: { _ in NSRect(x: 11, y: 22, width: 33, height: 44) })
#expect(window.frame == original)
}
}