mirror of
https://github.com/phranck/TUIkit.git
synced 2026-06-20 09:54:37 +00:00
Add @MainActor to View, ViewModifier, Renderable, App, Scene protocols and all builders (ViewBuilder, SceneBuilder, ChildInfoProvider). Update renderToBuffer(), makeChildInfo(), resolveChildInfos() for main-actor isolation. Mark generic Equatable conformances with @preconcurrency. Update all 45 test suites with @MainActor annotation.
109 lines
3.2 KiB
Swift
109 lines
3.2 KiB
Swift
// 🖥️ TUIKit — Terminal UI Kit for Swift
|
|
// ContainerViewTests.swift
|
|
//
|
|
// Created by LAYERED.work
|
|
// License: MIT
|
|
|
|
import Testing
|
|
|
|
@testable import TUIkit
|
|
|
|
@MainActor
|
|
@Suite("Alert Tests")
|
|
struct AlertTests {
|
|
|
|
@Test("Alert renders with border")
|
|
func alertRendering() {
|
|
let alert = Alert(title: "Warning", message: "Something happened")
|
|
let context = RenderContext(availableWidth: 80, availableHeight: 24)
|
|
let buffer = renderToBuffer(alert, context: context)
|
|
#expect(buffer.height > 2)
|
|
// Should have border characters
|
|
let allContent = buffer.lines.joined()
|
|
#expect(allContent.contains("Warning"))
|
|
#expect(allContent.contains("Something happened"))
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
@Suite("Dialog Tests")
|
|
struct DialogTests {
|
|
|
|
@Test("Dialog renders with panel styling")
|
|
func dialogRendering() {
|
|
let dialog = Dialog(title: "Test Dialog") {
|
|
Text("Content here")
|
|
}
|
|
let context = RenderContext(availableWidth: 80, availableHeight: 24)
|
|
let buffer = renderToBuffer(dialog, context: context)
|
|
#expect(buffer.height > 1)
|
|
// Should contain title and content
|
|
let allContent = buffer.lines.joined()
|
|
#expect(allContent.contains("Test Dialog"))
|
|
#expect(allContent.contains("Content here"))
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
@Suite("Menu Tests")
|
|
struct MenuTests {
|
|
|
|
@Test("MenuItem can be created with label")
|
|
func menuItemCreation() {
|
|
let item = MenuItem(label: "Option 1")
|
|
#expect(item.label == "Option 1")
|
|
#expect(item.id == "Option 1")
|
|
#expect(item.shortcut == nil)
|
|
}
|
|
|
|
@Test("MenuItem can have shortcut")
|
|
func menuItemWithShortcut() {
|
|
let item = MenuItem(label: "Quit", shortcut: "q")
|
|
#expect(item.label == "Quit")
|
|
#expect(item.shortcut == "q")
|
|
}
|
|
|
|
@Test("Menu can be created with items")
|
|
func menuCreation() {
|
|
let menu = Menu(
|
|
title: "Test Menu",
|
|
items: [
|
|
MenuItem(label: "Option 1", shortcut: "1"),
|
|
MenuItem(label: "Option 2", shortcut: "2"),
|
|
],
|
|
selectedIndex: 0
|
|
)
|
|
#expect(menu.title == "Test Menu")
|
|
#expect(menu.items.count == 2)
|
|
#expect(menu.selectedIndex == 0)
|
|
}
|
|
|
|
@Test("Menu renders with title and border")
|
|
func menuRendering() {
|
|
let menu = Menu(
|
|
title: "My Menu",
|
|
items: [
|
|
MenuItem(label: "First"),
|
|
MenuItem(label: "Second"),
|
|
]
|
|
)
|
|
let context = RenderContext(availableWidth: 80, availableHeight: 24)
|
|
let buffer = renderToBuffer(menu, context: context)
|
|
#expect(buffer.height >= 3) // border + items + border
|
|
let allContent = buffer.lines.joined()
|
|
// Title should be present
|
|
#expect(allContent.contains("My Menu"))
|
|
// Border characters should be present (rounded style)
|
|
#expect(allContent.contains("╭") || allContent.contains("│"))
|
|
}
|
|
|
|
@Test("Menu clamps selectedIndex to valid range")
|
|
func menuClampsIndex() {
|
|
let menu = Menu(
|
|
items: [MenuItem(label: "Only")],
|
|
selectedIndex: 99
|
|
)
|
|
#expect(menu.selectedIndex == 0)
|
|
}
|
|
}
|