Files
babaevmm 0c31bbafc1 reconfigure generic view if content is not child
14cdb13eb08f5adfab7a1405ebac9fb6c433c38b
2024-07-23 16:02:21 +03:00

53 lines
1.4 KiB
Swift

import XCTest
import LayoutKit
import VGSL
final class GenericViewBlockTests: XCTestCase {
func test_WhenSameContentViewSetForAnotherBlock_ContentIsUpdatedForLastBlock() throws {
let contentView = UIView()
let block = makeBlock(.view(contentView))
let view1 = GenericViewBlock.makeBlockView()
let view2 = GenericViewBlock.makeBlockView()
block.configure(view1)
block.configure(view2)
block.configure(view1)
XCTAssertIdentical(contentView.superview, view1)
XCTAssertTrue(view2.subviews.isEmpty)
}
func test_WhenSameContentLayerSetForAnotherBlock_ContentIsUpdatedForLastBlock() throws {
let contentLayer = CALayer()
let block = makeBlock(.layer(contentLayer))
let view1 = GenericViewBlock.makeBlockView()
let view2 = GenericViewBlock.makeBlockView()
block.configure(view1)
block.configure(view2)
block.configure(view1)
XCTAssertIdentical(contentLayer.superlayer, view1.layer)
XCTAssertNil(view2.layer.sublayers)
}
}
private func makeBlock(_ content: GenericViewBlock.Content) -> GenericViewBlock {
return GenericViewBlock(content: content, width: .resizable, height: .resizable)
}
extension GenericViewBlock {
fileprivate func configure(_ view: UIView & BlockViewProtocol) {
configureBlockView(
view,
observer: nil,
overscrollDelegate: nil,
renderingDelegate: nil
)
}
}