Files
divkit/client/ios/LayoutKit/LayoutKitTests/Blocks/PagerBlockTests.swift
T
babaevmm 3056a937d3 revert isScrolling logic for GalleryViewState
commit_hash:04c3c93d0d934db316803a9d7efb8423482b52bb
2025-05-05 12:53:39 +03:00

78 lines
2.2 KiB
Swift

import LayoutKit
import VGSL
import XCTest
final class PagerBlockTests: XCTestCase {
func test_WhenFixedHeight_IntrinsicContentHeightReturnsFixedHeight() {
let block = makePagerBlock(heightTrait: .fixed(111))
XCTAssertEqual(block.intrinsicContentHeight(forWidth: .infinity), 111)
}
func test_WhenFixedWidth_IntrinsicContentWidthReturnsFixedWidth() throws {
let block = makePagerBlock(widthTrait: .fixed(111))
XCTAssertEqual(block.intrinsicContentWidth, 111)
}
func test_WhenIntrinsictHeight_IntrinsicContentHeightReturnsMaxPageHeight() throws {
let block = makePagerBlock(currentPage: 0)
XCTAssertEqual(block.intrinsicContentHeight(forWidth: .infinity), 1000)
}
func test_WhenNextPageLarger_IntrinsicContentHeightReturnsNextPageHeight() throws {
let block = makePagerBlock(currentPage: 1)
XCTAssertEqual(block.intrinsicContentHeight(forWidth: .infinity), 1000)
}
func test_WhenPreviousPageLarger_IntrinsicContentHeightReturnsPreviousPageHeight() throws {
let block = makePagerBlock(currentPage: 4)
XCTAssertEqual(block.intrinsicContentHeight(forWidth: .infinity), 1000)
}
}
private func makePagerBlock(
currentPage: Int = 0,
widthTrait: LayoutTrait = .intrinsic,
heightTrait: LayoutTrait = .intrinsic
) -> PagerBlock {
try! PagerBlock(
pagerPath: nil,
alignment: .center,
layoutMode: .neighbourPageSize(10),
gallery: GalleryViewModel(
items: [
makeGalleryItem(size: 100),
makeGalleryItem(size: 100),
makeGalleryItem(size: 1000),
makeGalleryItem(size: 1000),
makeGalleryItem(size: 10),
],
metrics: GalleryViewMetrics(gaps: [0, 10, 10, 10, 10, 0]),
path: UIElementPath("gallery")
),
selectedActions: [[]],
state: PagerViewState(
numberOfPages: 5,
currentPage: currentPage,
animated: false
),
widthTrait: widthTrait,
heightTrait: heightTrait
)
}
private func makeGalleryItem(size: CGFloat) -> GalleryViewModel.Item {
GalleryViewModel.Item(
crossAlignment: .leading,
content: TextBlock(
widthTrait: .fixed(size),
heightTrait: .fixed(size),
text: NSAttributedString(string: "")
)
)
}