Redesign global toast as auto-dismissing top banner.

Use a full-width primary banner with centered text, auto-hide after 2.2 seconds, and tests for timer reset behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-23 14:48:31 +08:00
parent 31a262fd08
commit b7054145e7
5 changed files with 146 additions and 27 deletions

View File

@ -0,0 +1,60 @@
//
// ToastCenterTests.swift
// suixinkanTests
//
// Created by Codex on 2026/6/23.
//
import XCTest
@testable import suixinkan
@MainActor
/// Toast
final class ToastCenterTests: XCTestCase {
/// show Toast
func testShowStoresMessage() {
let center = ToastCenter(autoDismissNanoseconds: 100_000_000)
center.show("保存成功")
XCTAssertEqual(center.snapshotForTests, ToastSnapshot(message: "保存成功"))
}
/// Toast
func testToastAutoDismissesAfterDelay() async throws {
let center = ToastCenter(autoDismissNanoseconds: 60_000_000)
center.show("保存成功")
try await Task.sleep(nanoseconds: 90_000_000)
XCTAssertEqual(center.snapshotForTests, ToastSnapshot(message: nil))
}
/// show
func testRepeatedShowResetsAutoDismissTimer() async throws {
let center = ToastCenter(autoDismissNanoseconds: 100_000_000)
center.show("第一条")
try await Task.sleep(nanoseconds: 70_000_000)
center.show("第二条")
try await Task.sleep(nanoseconds: 60_000_000)
XCTAssertEqual(center.snapshotForTests, ToastSnapshot(message: "第二条"))
try await Task.sleep(nanoseconds: 70_000_000)
XCTAssertEqual(center.snapshotForTests, ToastSnapshot(message: nil))
}
/// dismiss
func testDismissClearsMessageImmediately() async throws {
let center = ToastCenter(autoDismissNanoseconds: 100_000_000)
center.show("保存成功")
center.dismiss()
XCTAssertEqual(center.snapshotForTests, ToastSnapshot(message: nil))
try await Task.sleep(nanoseconds: 130_000_000)
XCTAssertEqual(center.snapshotForTests, ToastSnapshot(message: nil))
}
}