diff --git a/Tests/LayoutTests/LayoutItemTests.swift b/Tests/LayoutTests/LayoutItemTests.swift index 3f6409c1..452c31f8 100644 --- a/Tests/LayoutTests/LayoutItemTests.swift +++ b/Tests/LayoutTests/LayoutItemTests.swift @@ -714,6 +714,27 @@ final class LayoutItemTests: XCTestCase { // MARK: - Margins + func testToMargins_throwsAssertion() { + + // GIVEN + + let superview: UIView = .init() + let view: UIView = .init() + let item: LayoutItem = view.toMargins() + + // THEN + + expect(item.superviewConstraints(view)).to(throwAssertion()) + + // WHEN + + superview.addSubview(view) + + // THEN + + expect(item.superviewConstraints(view)).toNot(beEmpty()) + } + func testToMarginsInsetsPriorityDirectional() { assertLayout(devices: Device.portraitTestDevices + Device.modernLandscapeTestDevices) { view in view.layout { @@ -845,6 +866,27 @@ final class LayoutItemTests: XCTestCase { // MARK: - Safe Area + func testToSafeArea_throwsAssertion() { + + // GIVEN + + let superview: UIView = .init() + let view: UIView = .init() + let item: LayoutItem = view.toSafeArea() + + // THEN + + expect(item.superviewConstraints(view)).to(throwAssertion()) + + // WHEN + + superview.addSubview(view) + + // THEN + + expect(item.superviewConstraints(view)).toNot(beEmpty()) + } + func testToSafeAreaInsetsPriorityDirectional() { assertLayout(devices: Device.allTestDevices) { view in view.layout { diff --git a/Tests/LayoutTests/LayoutTests.swift b/Tests/LayoutTests/LayoutTests.swift index 0f8b72b8..057aa8ca 100644 --- a/Tests/LayoutTests/LayoutTests.swift +++ b/Tests/LayoutTests/LayoutTests.swift @@ -663,6 +663,40 @@ final class LayoutTests: XCTestCase { } } + func testEqualAttributesWithViews_givenEmptyArray() { + + // GIVEN + + let superview: UIView = .init() + let view1: UIView = .init() + let view2: UIView = .init() + let layout: Layout = superview.layout().addItems(view1, view2) + + // WHEN + + layout.equal(.top, []) + + // THEN + + expect(layout.constraints).to(beEmpty()) + + // WHEN + + layout.equal(.top, [view1]) + + // THEN + + expect(layout.constraints).to(beEmpty()) + + // WHEN + + layout.equal(.top, [view1, view2]) + + // THEN + + expect(layout.constraints.count) == 1 + } + func testEqualSizeWithViews() { // GIVEN @@ -721,6 +755,32 @@ final class LayoutTests: XCTestCase { } } + func testCenterViewBetweenLeadingAndTrailingPriority_givenNilSuperview() { + + // GIVEN + + var superview: UIView? = .init() + let view: UIView = .init() + let siblingView: UIView = .init() + let layout: Layout = superview!.layout().addItems(view, siblingView) + let leadingAnchor: NSLayoutXAxisAnchor = siblingView.trailing + let trailingAcnhor: NSLayoutXAxisAnchor = superview!.trailing + + // THEN + + expect(layout.center(view, between: leadingAnchor, and: trailingAcnhor)) === layout + expect(layout.constraints.count) == 3 + + // WHEN + + superview = nil + + // THEN + + expect(layout.center(view, between: leadingAnchor, and: trailingAcnhor)) === layout + expect(layout.constraints.count) == 3 + } + func testCenterViewBetweenTopAndBottomPriority() { // GIVEN @@ -755,6 +815,32 @@ final class LayoutTests: XCTestCase { } } + func testCenterViewBetweenTopAndBottomPriority_givenNilSuperview() { + + // GIVEN + + var superview: UIView? = .init() + let view: UIView = .init() + let siblingView: UIView = .init() + let layout: Layout = superview!.layout().addItems(view, siblingView) + let topAnchor: NSLayoutYAxisAnchor = siblingView.bottom + let bottomAcnhor: NSLayoutYAxisAnchor = superview!.bottom + + // THEN + + expect(layout.center(view, between: topAnchor, and: bottomAcnhor)) === layout + expect(layout.constraints.count) == 3 + + // WHEN + + superview = nil + + // THEN + + expect(layout.center(view, between: topAnchor, and: bottomAcnhor)) === layout + expect(layout.constraints.count) == 3 + } + // MARK: - Stack func testHorizontalViewsSpacingDirectionPriorityAlignment() { @@ -848,6 +934,40 @@ final class LayoutTests: XCTestCase { } } + func testHorizontalViewsSpacingDirectionPriorityAlignment_givenEmptyArray() { + + // GIVEN + + let superview: UIView = .init() + let view1: UIView = .init() + let view2: UIView = .init() + let layout: Layout = superview.layout().addItems(view1, view2) + + // WHEN + + layout.horizontal([]) + + // THEN + + expect(layout.constraints).to(beEmpty()) + + // WHEN + + layout.horizontal([view1]) + + // THEN + + expect(layout.constraints).to(beEmpty()) + + // WHEN + + layout.horizontal([view1, view2]) + + // THEN + + expect(layout.constraints.count) == 1 + } + func testVerticalViewsSpacingPriorityAlignment() { // GIVEN @@ -916,6 +1036,40 @@ final class LayoutTests: XCTestCase { } } + func testVerticalViewsSpacingPriorityAlignment_givenEmptyArray() { + + // GIVEN + + let superview: UIView = .init() + let view1: UIView = .init() + let view2: UIView = .init() + let layout: Layout = superview.layout().addItems(view1, view2) + + // WHEN + + layout.vertical([]) + + // THEN + + expect(layout.constraints).to(beEmpty()) + + // WHEN + + layout.vertical([view1]) + + // THEN + + expect(layout.constraints).to(beEmpty()) + + // WHEN + + layout.vertical([view1, view2]) + + // THEN + + expect(layout.constraints.count) == 1 + } + // MARK: - Visual Format Language func testHorizontalWithFormatMetricsOptions_givenDefaults() { diff --git a/Tests/LayoutTests/UIKit/NSDirectionalEdgeInsetsTests.swift b/Tests/LayoutTests/UIKit/NSDirectionalEdgeInsetsTests.swift index 63df2024..5aed3fc3 100644 --- a/Tests/LayoutTests/UIKit/NSDirectionalEdgeInsetsTests.swift +++ b/Tests/LayoutTests/UIKit/NSDirectionalEdgeInsetsTests.swift @@ -13,6 +13,10 @@ import XCTest final class NSDirectionalEdgeInsetsTests: XCTestCase { + func testEdgeType() { + expect(NSDirectionalEdgeInsets().edgeType == DirectionalEdge.self) == true + } + func testInitWithInset() { // GIVEN diff --git a/Tests/LayoutTests/UIKit/UIEdgeInsetsTests.swift b/Tests/LayoutTests/UIKit/UIEdgeInsetsTests.swift index 2e4ba71d..72d8cf9c 100644 --- a/Tests/LayoutTests/UIKit/UIEdgeInsetsTests.swift +++ b/Tests/LayoutTests/UIKit/UIEdgeInsetsTests.swift @@ -14,6 +14,10 @@ import XCTest final class UIEdgeInsetsTests: XCTestCase { + func testEdgeType() { + expect(UIEdgeInsets().edgeType == CanonicalEdge.self) == true + } + func testInitWithInset() { // GIVEN diff --git a/Tests/LayoutTests/UIKit/UIView+AutoLayoutTests.swift b/Tests/LayoutTests/UIKit/UIView+AutoLayoutTests.swift index 85b3dd46..60f58009 100644 --- a/Tests/LayoutTests/UIKit/UIView+AutoLayoutTests.swift +++ b/Tests/LayoutTests/UIKit/UIView+AutoLayoutTests.swift @@ -458,6 +458,26 @@ final class UIViewAutoLayoutTests: XCTestCase { expect(constraints2.first?.constant) == 5 } + func testConstraintForAttributeIsRelationToSuperviewMultiplierConstant_givenNilSuperview() { + + // GIVEN + + let superview: UIView = .init() + let view: UIView = .init() + + // THEN + + expect(view.constraints(toSuperview: [.top])).to(throwAssertion()) + + // WHEN + + superview.addSubview(view) + + // THEN + + expect(view.constraints(toSuperview: [.top]).count) == 1 + } + func testConstraintForAttributeIsRelationToTargetAttributeOfTargetViewMultiplierConstant() { // GIVEN