Files
pkurchatov 27a3472171 Enabled blankLinesBetweenImports swiftformat rule
commit_hash:84ea24cbdf21ef89741080f38ec5e583172a2458
2024-12-20 12:41:02 +03:00

78 lines
2.4 KiB
Swift

@testable import LayoutKit
import VGSL
import XCTest
final class LayeredBlockLayoutTests: XCTestCase {
func test_WhenChildIsHorizontallyResizable_FrameWidthIsEqualToBoundsWidth() {
let block = LayeredBlock(children: [horizontallyResizableBlock])
let blockFrames = block.makeChildrenFrames(size: testSize)
XCTAssertEqual(blockFrames.first?.width, testSize.width)
}
func test_WhenChildIsVerticallyResizable_FrameHeightIsEqualToBoundsHeight() {
let block = LayeredBlock(children: [verticallyResizableBlock])
let blockFrames = block.makeChildrenFrames(size: testSize)
XCTAssertEqual(blockFrames.first?.height, testSize.height)
}
func test_WhenHorizontalChildrenAlignmentIsCenter_IntrinsicWidthChildIsCentered() {
let block = LayeredBlock(
horizontalChildrenAlignment: .center,
children: [verticallyResizableBlock]
)
let blockFrames = block.makeChildrenFrames(size: testSize)
XCTAssertEqual(
blockFrames.first?.center.x ?? 0,
testSize.width / 2,
accuracy: 1 / PlatformDescription.screenScale()
)
}
func test_WhenHorizontalChildrenAlignmentIsTrailing_IntrinsicWidthChildIsRightAligned() {
let block = LayeredBlock(
horizontalChildrenAlignment: .trailing,
children: [verticallyResizableBlock]
)
let blockFrames = block.makeChildrenFrames(size: testSize)
XCTAssertEqual(blockFrames.first?.maxX, testSize.width)
}
func test_WhenVerticalChildrenAlignmentIsCenter_IntrinsicWidthChildIsCentered() {
let block = LayeredBlock(
verticalChildrenAlignment: .center,
children: [horizontallyResizableBlock]
)
let blockFrames = block.makeChildrenFrames(size: testSize)
XCTAssertEqual(
blockFrames.first?.center.y ?? 0,
testSize.height / 2,
accuracy: 1 / PlatformDescription.screenScale()
)
}
func test_WhenVerticalChildrenAlignmentIsTrailing_IntrinsicWidthChildIsBottomAligned() {
let block = LayeredBlock(
verticalChildrenAlignment: .trailing,
children: [horizontallyResizableBlock]
)
let blockFrames = block.makeChildrenFrames(size: testSize)
XCTAssertEqual(blockFrames.first?.maxY, testSize.height)
}
}
private let horizontallyResizableBlock = SeparatorBlock(direction: .horizontal)
private let verticallyResizableBlock = SeparatorBlock(direction: .vertical)
private let testSize = CGSize(width: 100, height: 200)