Files
suixinkan_ios_new/suixinkanTests/ToastCenterTests.swift
汉秋 09922f70fe 重构全局 Toast 为自动消失的顶部横幅
采用全宽主色横幅居中展示文案,2.2 秒后自动隐藏,并补充定时器重置行为的测试。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-23 14:48:31 +08:00

61 lines
2.0 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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))
}
}