Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing coverage #303

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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).count) == 4
}

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).count) == 4
}

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 trailingAnchor: NSLayoutXAxisAnchor = superview!.trailing

// THEN

expect(layout.center(view, between: leadingAnchor, and: trailingAnchor)) === layout
expect(layout.constraints.count) == 3

// WHEN

superview = nil

// THEN

expect(layout.center(view, between: leadingAnchor, and: trailingAnchor)) === 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 bottomAnchor: NSLayoutYAxisAnchor = superview!.bottom

// THEN

expect(layout.center(view, between: topAnchor, and: bottomAnchor)) === layout
expect(layout.constraints.count) == 3

// WHEN

superview = nil

// THEN

expect(layout.center(view, between: topAnchor, and: bottomAnchor)) === 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