//
//  CooperationOrderRemarkNameTests.swift
//  suixinkanTests
//
//  Created by Codex on 2026/7/2.
//

import XCTest
@testable import suixinkan

/// 合作获客员备注名校验规则测试。
final class CooperationOrderRemarkNameTests: XCTestCase {
    /// 测试超出上限时返回错误提示。
    func testValidationMessageWhenExceedsMaxLength() {
        let input = String(repeating: "名", count: CooperationOrderRemarkName.maxLength + 1)
        XCTAssertEqual(
            CooperationOrderRemarkName.validationMessage(for: input),
            "备注名不能超过\(CooperationOrderRemarkName.maxLength)个字符"
        )
    }

    /// 测试合法长度时不返回错误。
    func testValidationMessageAcceptsValidRemark() {
        XCTAssertNil(CooperationOrderRemarkName.validationMessage(for: "张哥"))
        XCTAssertNil(
            CooperationOrderRemarkName.validationMessage(
                for: String(repeating: "名", count: CooperationOrderRemarkName.maxLength)
            )
        )
    }

    /// 测试保存前会去除首尾空白后再校验。
    func testValidationUsesTrimmedLength() {
        let inner = String(repeating: "张", count: CooperationOrderRemarkName.maxLength)
        XCTAssertNil(CooperationOrderRemarkName.validationMessage(for: " \(inner) "))
        XCTAssertNotNil(CooperationOrderRemarkName.validationMessage(for: " \(inner)多 "))
    }

    /// 测试去除首尾空白。
    func testTrimmedRemovesSurroundingWhitespace() {
        XCTAssertEqual(CooperationOrderRemarkName.trimmed(" 张哥 "), "张哥")
    }
}
