Files
suixinkan_uikit/suixinkanTests/UmengBootstrapTests.swift
汉秋 005349f8e6 模块化 AppStore 并完善素材管理与个人空间设置。
将会话、权限、位置、收款与排队存储拆分为独立模块,同步更新各 ViewModel 与单元测试,并补充素材管理 UI 与个人空间设置交互。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-13 11:01:08 +08:00

55 lines
1.7 KiB
Swift

//
// UmengBootstrapTests.swift
// suixinkanTests
//
import XCTest
@testable import suixinkan
/// SDK gate
final class UmengBootstrapTests: XCTestCase {
private var defaults: UserDefaults!
private var appStore: AppStore!
override func setUp() {
super.setUp()
UmengBootstrap.resetForTesting()
defaults = UserDefaults(suiteName: "UmengBootstrapTests")!
defaults.removePersistentDomain(forName: "UmengBootstrapTests")
appStore = AppStore(defaults: defaults)
}
override func tearDown() {
UmengBootstrap.resetForTesting()
super.tearDown()
}
func testConfigureReturnsFalseWhenPrivacyNotAccepted() {
var callCount = 0
UmengBootstrap.setConfigureHandlerForTesting { _, _ in
callCount += 1
}
appStore.session.privacyAgreementAccepted = false
XCTAssertFalse(UmengBootstrap.configureIfNeeded(appStore: appStore))
XCTAssertFalse(UmengBootstrap.isConfigured)
XCTAssertEqual(callCount, 0)
}
func testConfigureIsIdempotentWhenPrivacyAccepted() {
var calls: [(appKey: String, channel: String)] = []
UmengBootstrap.setConfigureHandlerForTesting { appKey, channel in
calls.append((appKey, channel))
}
appStore.session.privacyAgreementAccepted = true
XCTAssertTrue(UmengBootstrap.configureIfNeeded(appStore: appStore))
XCTAssertTrue(UmengBootstrap.isConfigured)
XCTAssertTrue(UmengBootstrap.configureIfNeeded(appStore: appStore))
XCTAssertEqual(calls.count, 1)
XCTAssertEqual(calls.first?.appKey, UmengConfig.appKey)
XCTAssertEqual(calls.first?.channel, UmengConfig.channel)
}
}