Files
bot/apps/macos/Tests/BotIPCTests/WindowPlacementTests.swift
zeekay bb5ae75492 Rebrand OpenClaw → Hanzo Bot across entire codebase
Complete rename of all OpenClaw/OPENCLAW/openclaw references to
Hanzo Bot/BOT/bot naming convention:

- Env vars: OPENCLAW_* → BOT_* (18 patterns)
- Config: ~/.openclaw/ → ~/.bot/, openclaw.json → bot.json
- Packages: @openclaw/* → @hanzo/bot-*
- Domains: openclaw.ai → hanzo.bot
- Mobile: OpenClawKit → BotKit, bundle IDs ai.openclaw → ai.hanzo.bot
- mDNS: _openclaw-gw._tcp → _bot-gw._tcp
- Docker: CMD hanzo-bot.mjs, BOT_PREFER_PNPM, BOT_DOCKER_APT_PACKAGES
- CI: docker-release.yml adds :latest tag on main branch
2026-02-11 11:13:08 -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)
}
}