Integrate Umeng analytics and APM

This commit is contained in:
2026-07-07 14:20:04 +08:00
parent 9899a2ccb3
commit 6bdabadc3b
9 changed files with 155 additions and 2 deletions

View File

@ -0,0 +1,54 @@
//
// 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.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.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)
}
}