//
//  HomeCollectionModelsTests.swift
//  suixinkanTests
//

import XCTest
@testable import suixinkan

/// 首页 Collection snapshot 测试。
final class HomeCollectionModelsTests: XCTestCase {

    func testMakeSnapshotIncludesDistinctWorkBlockItems() {
        let snapshot = HomeCollectionLayoutBuilder.makeSnapshot(
            showWorkBlock: true,
            showStore: false,
            storeItem: nil,
            commonMenus: []
        )

        XCTAssertEqual(snapshot.numberOfSections, 4)
        XCTAssertEqual(snapshot.numberOfItems(inSection: .workStatus), 1)
        XCTAssertEqual(snapshot.numberOfItems(inSection: .locationReport), 1)
        XCTAssertEqual(snapshot.numberOfItems(inSection: .quickActions), 1)
        XCTAssertEqual(snapshot.itemIdentifiers(inSection: .workStatus), [.workStatus])
        XCTAssertEqual(snapshot.itemIdentifiers(inSection: .locationReport), [.locationReport])
        XCTAssertEqual(snapshot.itemIdentifiers(inSection: .quickActions), [.quickActions])
    }

    func testMakeSnapshotOmitsWorkBlockForMinimalTopRole() {
        let snapshot = HomeCollectionLayoutBuilder.makeSnapshot(
            showWorkBlock: false,
            showStore: false,
            storeItem: nil,
            commonMenus: []
        )

        XCTAssertEqual(snapshot.sectionIdentifiers, [.commonApps])
        XCTAssertEqual(snapshot.itemIdentifiers(inSection: .commonApps).count, 1)
    }

    func testMakeSnapshotIncludesStoreSectionWhenAvailable() {
        let store = StoreItem(id: 1, name: "测试门店", address: "测试地址")
        let snapshot = HomeCollectionLayoutBuilder.makeSnapshot(
            showWorkBlock: true,
            showStore: true,
            storeItem: store,
            commonMenus: []
        )

        XCTAssertTrue(snapshot.sectionIdentifiers.contains(.store))
        XCTAssertEqual(snapshot.itemIdentifiers(inSection: .store), [.store])
    }
}
