增加禁飞期间的设备指令拦截及本地模拟拍摄流程;适配订单素材库和景区空境库,完善素材筛选、预览与下载;订单交付入口改为方式选择弹窗并复用云端上传。补充单元测试、接口记录和模拟器截图。
91 lines
5.1 KiB
Swift
91 lines
5.1 KiB
Swift
import XCTest
|
|
@testable import suixinkan
|
|
|
|
/// 验证两列日期滚轮只有保留期内的日期,跨年与月末不会生成越界值。
|
|
final class ScenicMaterialDatePickerOptionsTests: XCTestCase {
|
|
/// 首尾月只保留允许的日号,所有选项都包含在闭区间内。
|
|
func testPartialBoundaryMonthsContainOnlyRetainedDays() {
|
|
let options = makeOptions(from: date(2026, 7, 29), through: date(2026, 10, 26))
|
|
XCTAssertEqual(options.months.map(\.number), [7, 8, 9, 10])
|
|
XCTAssertEqual(options.months.map { $0.dates.count }, [3, 31, 30, 26])
|
|
XCTAssertEqual(options.months.first?.dates.first, date(2026, 7, 29))
|
|
XCTAssertEqual(options.months.last?.dates.last, date(2026, 10, 26))
|
|
XCTAssertTrue(options.months.flatMap(\.dates).allSatisfy { options.minimumDate <= $0 && $0 <= options.maximumDate })
|
|
XCTAssertEqual(options.date(inMonthAt: 0, preferredDay: 1), date(2026, 7, 29))
|
|
XCTAssertEqual(options.date(inMonthAt: 3, preferredDay: 31), date(2026, 10, 26))
|
|
}
|
|
|
|
/// 12 月与次年 1 月属于不同年月,滚轮日号不会回到上一年。
|
|
func testCrossYearMonthsPreserveYearAndChronologicalOrder() {
|
|
let options = makeOptions(from: date(2026, 11, 30), through: date(2027, 1, 5))
|
|
XCTAssertEqual(options.months.map(\.year), [2026, 2026, 2027])
|
|
XCTAssertEqual(options.months.map(\.number), [11, 12, 1])
|
|
XCTAssertEqual(options.monthIndex(for: date(2027, 1, 1)), 2)
|
|
XCTAssertEqual(options.monthTitle(at: 2), "1月")
|
|
XCTAssertEqual(options.date(inMonthAt: 2, preferredDay: 31), date(2027, 1, 5))
|
|
}
|
|
|
|
/// 从 31 日切换到平年 2 月时落到 28 日,再切换长月可以正常选 31 日。
|
|
func testShortMonthClampsDayWithoutOverflowingIntoMarch() {
|
|
let options = makeOptions(from: date(2026, 1, 1), through: date(2026, 3, 31))
|
|
XCTAssertEqual(options.date(inMonthAt: 1, preferredDay: 31), date(2026, 2, 28))
|
|
XCTAssertEqual(options.date(inMonthAt: 2, preferredDay: 31), date(2026, 3, 31))
|
|
XCTAssertEqual(options.months[1].dates.count, 28)
|
|
}
|
|
|
|
/// 闰年 2 月 29 日保留为有效选项,不硬编码每月天数。
|
|
func testLeapDayIsSelectable() {
|
|
let options = makeOptions(from: date(2028, 1, 31), through: date(2028, 3, 1))
|
|
XCTAssertEqual(options.months[1].dates.count, 29)
|
|
XCTAssertEqual(options.date(inMonthAt: 1, preferredDay: 31), date(2028, 2, 29))
|
|
}
|
|
|
|
/// 保留期外的传入日期收敛到最近边界,同时去除时分秒。
|
|
func testExternalDatesClampToInclusiveDayBoundaries() {
|
|
let options = makeOptions(from: date(2026, 10, 1), through: date(2026, 10, 30))
|
|
XCTAssertEqual(options.clamped(date(2026, 9, 30)), date(2026, 10, 1))
|
|
XCTAssertEqual(options.clamped(date(2026, 10, 31)), date(2026, 10, 30))
|
|
XCTAssertEqual(options.clamped(date(2026, 10, 15).addingTimeInterval(12 * 3600)), date(2026, 10, 15))
|
|
}
|
|
|
|
/// 非法倒置边界收敛成一天,滚轮仍有可选值。
|
|
func testInvertedBoundsProduceOneValidDay() {
|
|
let options = makeOptions(from: date(2026, 10, 30), through: date(2026, 10, 1))
|
|
XCTAssertEqual(options.months.flatMap(\.dates), [date(2026, 10, 30)])
|
|
XCTAssertEqual(options.maximumDate, options.minimumDate)
|
|
}
|
|
|
|
/// 长区间出现同名月份时显示年份,防止两条“1 月”无法区分。
|
|
func testRepeatedMonthNamesIncludeYear() {
|
|
let options = makeOptions(from: date(2026, 1, 31), through: date(2027, 1, 1))
|
|
XCTAssertEqual(options.monthTitle(at: 0), "2026年1月")
|
|
XCTAssertEqual(options.monthTitle(at: 12), "2027年1月")
|
|
XCTAssertEqual(options.monthTitle(at: 1), "2月")
|
|
}
|
|
|
|
/// 夏令时切换不跳过日期,也不会生成非零点的日期选项。
|
|
func testDayEnumerationUsesCalendarAcrossDaylightSavingTransition() throws {
|
|
var localCalendar = Calendar(identifier: .gregorian)
|
|
localCalendar.timeZone = try XCTUnwrap(TimeZone(identifier: "America/Los_Angeles"))
|
|
let start = try XCTUnwrap(localCalendar.date(from: DateComponents(year: 2026, month: 3, day: 7)))
|
|
let end = try XCTUnwrap(localCalendar.date(from: DateComponents(year: 2026, month: 3, day: 10)))
|
|
let options = ScenicMaterialDatePickerOptions(minimumDate: start, maximumDate: end, calendar: localCalendar)
|
|
XCTAssertEqual(options.months[0].dates.map { localCalendar.component(.day, from: $0) }, [7, 8, 9, 10])
|
|
XCTAssertTrue(options.months[0].dates.allSatisfy { localCalendar.component(.hour, from: $0) == 0 })
|
|
}
|
|
|
|
private var calendar: Calendar {
|
|
var calendar = Calendar(identifier: .gregorian)
|
|
calendar.timeZone = TimeZone(secondsFromGMT: 8 * 3600)!
|
|
return calendar
|
|
}
|
|
|
|
private func date(_ year: Int, _ month: Int, _ day: Int) -> Date {
|
|
calendar.date(from: DateComponents(year: year, month: month, day: day))!
|
|
}
|
|
|
|
private func makeOptions(from minimum: Date, through maximum: Date) -> ScenicMaterialDatePickerOptions {
|
|
ScenicMaterialDatePickerOptions(minimumDate: minimum, maximumDate: maximum, calendar: calendar)
|
|
}
|
|
}
|