初始提交

This commit is contained in:
2026-06-22 11:28:01 +08:00
commit 0a0d4fbd79
84 changed files with 8899 additions and 0 deletions

View File

@ -0,0 +1,76 @@
//
// ScenicSpotContextTests.swift
// suixinkanTests
//
// Created by Codex on 2026/6/22.
//
import XCTest
@testable import suixinkan
@MainActor
///
final class ScenicSpotContextTests: XCTestCase {
/// ID
func testReloadRequestsSpotsForScenicId() async {
let context = ScenicSpotContext()
let api = MockScenicSpotAPI()
api.spotResponse = ListPayload(total: 1, list: [ScenicSpotItem(id: 9, name: "观景台")])
await context.reload(scenicId: 88, api: api)
XCTAssertEqual(api.requestedScenicIds, [88])
XCTAssertEqual(context.scenicId, 88)
XCTAssertEqual(context.spots.map(\.id), [9])
XCTAssertEqual(context.loadState, .loaded)
}
///
func testReloadFailureOnlyAffectsScenicSpotContext() async {
let context = ScenicSpotContext()
let api = MockScenicSpotAPI()
api.error = APIError.networkFailed("景点接口失败")
await context.reload(scenicId: 88, api: api)
XCTAssertEqual(api.requestedScenicIds, [88])
XCTAssertTrue(context.spots.isEmpty)
if case .failed = context.loadState {
XCTAssertTrue(true)
} else {
XCTFail("景点接口失败时应进入 failed 状态")
}
}
}
@MainActor
/// ID
private final class MockScenicSpotAPI: AccountContextServing {
var requestedScenicIds: [Int] = []
var spotResponse = ListPayload(total: 0, list: [ScenicSpotItem]())
var error: Error?
/// 使
func rolePermissions() async throws -> [RolePermissionResponse] {
[]
}
/// 使
func scenicListAll() async throws -> ScenicListAllResponse {
ScenicListAllResponse(total: 0, list: [])
}
/// 使
func storeAll() async throws -> ListPayload<StoreItem> {
ListPayload(total: 0, list: [])
}
/// ID
func scenicSpotListAll(scenicId: Int) async throws -> ListPayload<ScenicSpotItem> {
requestedScenicIds.append(scenicId)
if let error {
throw error
}
return spotResponse
}
}