Skip to content

Commit

Permalink
Add missing coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tinder-garricnahapetian committed Jan 22, 2024
1 parent b66b100 commit e6bb8d5
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Tests/LayoutTests/LayoutItemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
154 changes: 154 additions & 0 deletions Tests/LayoutTests/LayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions Tests/LayoutTests/UIKit/NSDirectionalEdgeInsetsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import XCTest

final class NSDirectionalEdgeInsetsTests: XCTestCase {

func testEdgeType() {
expect(NSDirectionalEdgeInsets().edgeType == DirectionalEdge.self) == true
}

func testInitWithInset() {

// GIVEN
Expand Down
4 changes: 4 additions & 0 deletions Tests/LayoutTests/UIKit/UIEdgeInsetsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import XCTest

final class UIEdgeInsetsTests: XCTestCase {

func testEdgeType() {
expect(UIEdgeInsets().edgeType == CanonicalEdge.self) == true
}

func testInitWithInset() {

// GIVEN
Expand Down
20 changes: 20 additions & 0 deletions Tests/LayoutTests/UIKit/UIView+AutoLayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e6bb8d5

Please sign in to comment.