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 tests for default parameters #240

Merged
merged 10 commits into from
Nov 29, 2023
48 changes: 33 additions & 15 deletions Tests/LayoutTests/LayoutItemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ final class LayoutItemTests: XCTestCase {
view.layout {
pinkView
.to([.top, .leading])
.size(width: 150, height: 250, priority: .high)
.size(width: 100, height: 200)
yellowView
.to([.top, .trailing])
Expand All @@ -60,6 +61,7 @@ final class LayoutItemTests: XCTestCase {
view.layout {
pinkView
.to([.top, .leading])
.size(CGSize(width: 150, height: 250), priority: .high)
.size(CGSize(width: 100, height: 200))
yellowView
.to([.top, .trailing])
Expand All @@ -82,6 +84,7 @@ final class LayoutItemTests: XCTestCase {
pinkView
.to([.top, .leading])
.size(height: 100)
.size(is: .greaterThanOrEqual, width: 100, priority: .high)
.size(width: 50)

// With High Priority
Expand Down Expand Up @@ -142,6 +145,7 @@ final class LayoutItemTests: XCTestCase {
pinkView
.to([.top, .leading])
.size(width: 50)
.size(is: .greaterThanOrEqual, height: 150, priority: .high)
.size(height: 100)

// With Priority
Expand Down Expand Up @@ -209,6 +213,7 @@ final class LayoutItemTests: XCTestCase {
view.layout {
pinkView
.to([.top, .leading])
.square(200, priority: .high)
.square(100)
yellowView
.to([.top, .trailing])
Expand All @@ -224,6 +229,7 @@ final class LayoutItemTests: XCTestCase {
pinkView
.to([.top, .leading])
.size(height: 100)
.aspectRatio(0.5, priority: .high)
.aspectRatio(0.75)
yellowView
.to([.top, .trailing])
Expand All @@ -242,6 +248,7 @@ final class LayoutItemTests: XCTestCase {

pinkView
.size(width: 50, height: 50)
.center(offset: UIOffset(horizontal: 50, vertical: 50), priority: .high)
.center()

// With Custom Offset
Expand Down Expand Up @@ -269,13 +276,15 @@ final class LayoutItemTests: XCTestCase {
pinkView
.size(width: 100, height: 100)
.to(.leading)
.center(.vertical, offset: 50, multiplier: 0.5, priority: .high)
.center(.vertical)

// Horizontal Axis

yellowView
.size(width: 100, height: 100)
.to(.top)
.center(.horizontal, offset: 50, multiplier: 0.5, priority: .high)
.center(.horizontal)

// With Offset
Expand Down Expand Up @@ -333,6 +342,8 @@ final class LayoutItemTests: XCTestCase {

pinkView
.size(width: 100, height: 100)
.to(.top, is: .greaterThanOrEqual, multiplier: 0.5, constant: 50, priority: .high)
.to(.leading, is: .greaterThanOrEqual, multiplier: 0.5, constant: 50, priority: .high)
.to(.top)
.to(.leading)

Expand Down Expand Up @@ -416,6 +427,7 @@ final class LayoutItemTests: XCTestCase {

pinkView
.size(width: 100, height: 100)
.to([.bottom, .leading], constant: 50, priority: .high)
.to([.bottom, .leading])

// To Bottom Trailing with Constant
Expand All @@ -440,6 +452,8 @@ final class LayoutItemTests: XCTestCase {

// Insets
pinkView
.toEdges(insets: NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0),
priority: .high)
.toEdges(insets: NSDirectionalEdgeInsets(top: 0, leading: 5, bottom: 10, trailing: 15))

// Insets with Priority
Expand All @@ -463,6 +477,7 @@ final class LayoutItemTests: XCTestCase {
// To Edges with Insets

pinkView
.toEdges(insets: UIEdgeInsets(top: 0, left: 5, bottom: 10, right: 15), priority: .high)
.toEdges(insets: UIEdgeInsets(top: 0, left: 5, bottom: 10, right: 15))

// To Edges with Insets and Priority
Expand All @@ -482,6 +497,7 @@ final class LayoutItemTests: XCTestCase {

pinkView
.size(height: 100)
.toEdges([.top, .leading, .trailing], inset: 50, priority: .high)
.toEdges([.top, .leading, .trailing])

// To Bottom, Leading and Trailing with Inset
Expand All @@ -508,6 +524,7 @@ final class LayoutItemTests: XCTestCase {
// Defaults

pinkView
.toEdges([.top, .leading], inset: 50, priority: .high)
.toEdges()

// To Top, Left and Right
Expand Down Expand Up @@ -542,6 +559,7 @@ final class LayoutItemTests: XCTestCase {
pinkView
.size(height: 100)
.to(.top)
.toSideEdges(inset: 50, priority: .high)
.toSideEdges()

// To Side Edges with Inset
Expand All @@ -566,11 +584,10 @@ final class LayoutItemTests: XCTestCase {
assertLayout { view in
view.layout {
pinkView
.toMargins(insets: NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10),
priority: .high)
.toMargins(insets: NSDirectionalEdgeInsets.zero)
blueView
.toMargins(insets: NSDirectionalEdgeInsets.zero, priority: .high)
.toMargins(insets: NSDirectionalEdgeInsets(top: 10, leading: 20, bottom: 40, trailing: 80))
orangeView
.toMargins(insets: NSDirectionalEdgeInsets.zero, priority: .low)
.toMargins(insets: NSDirectionalEdgeInsets(top: 20, leading: 30, bottom: 50, trailing: 90),
priority: .high)
Expand All @@ -582,11 +599,9 @@ final class LayoutItemTests: XCTestCase {
assertLayout { view in
view.layout {
pinkView
.toMargins(insets: UIEdgeInsets.zero)
blueView
.toMargins(insets: UIEdgeInsets.zero, priority: .high)
.toMargins(insets: UIEdgeInsets(top: 10, left: 20, bottom: 40, right: 80))
orangeView
blueView
.toMargins(insets: UIEdgeInsets.zero, priority: .low)
.toMargins(insets: UIEdgeInsets(top: 20, left: 30, bottom: 50, right: 90), priority: .high)
}
Expand All @@ -597,6 +612,7 @@ final class LayoutItemTests: XCTestCase {
assertLayout { view in
view.layout {
pinkView
.toMargins([.top, .leading, .trailing, .bottom], inset: 50, priority: .high)
.toMargins([.top, .leading, .trailing, .bottom])
blueView
.toMargins([.top, .leading, .trailing, .bottom], inset: 25)
Expand All @@ -611,14 +627,16 @@ final class LayoutItemTests: XCTestCase {
assertLayout { view in
view.layout {
pinkView
.toMargins(canonical: CanonicalEdge.allCases, inset: 50, priority: .high)
.toMargins()
blueView
.toMargins(inset: 25)
orangeView
.toMargins(inset: 0, priority: .low)
.toMargins(inset: 50, priority: .high)
yellowView
.toMargins(canonical: [.top, .left, .right, .bottom], inset: 75, priority: .required)
.size(CGSize(width: 50, height: 50))
.toMargins(canonical: [.top, .left], inset: 75)
}
}
}
Expand Down Expand Up @@ -653,6 +671,7 @@ final class LayoutItemTests: XCTestCase {
pinkView
.size(width: 100, height: 100)
.to(.leading)
.toBottomMargin(minInset: 200, priority: .high)
.toBottomMargin(minInset: 100)

// To Bottom Trailing with Priority
Expand All @@ -673,6 +692,8 @@ final class LayoutItemTests: XCTestCase {
// To Insets

pinkView
.toSafeArea(insets: NSDirectionalEdgeInsets(top: 5, leading: 5, bottom: 5, trailing: 5),
priority: .high)
.toSafeArea(insets: NSDirectionalEdgeInsets(top: 0, leading: 5, bottom: 10, trailing: 15))

// To Insets with Priority
Expand All @@ -697,6 +718,7 @@ final class LayoutItemTests: XCTestCase {
// To Insets

pinkView
.toSafeArea(insets: UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5), priority: .high)
.toSafeArea(insets: UIEdgeInsets(top: 0, left: 5, bottom: 10, right: 15))

// To Insets with Priority
Expand All @@ -712,13 +734,11 @@ final class LayoutItemTests: XCTestCase {
assertLayout { view in
view.layout {
pinkView
.toSafeArea(DirectionalEdge.allCases, inset: 50, priority: .high)
.toSafeArea(DirectionalEdge.allCases)
blueView
.toSafeArea(DirectionalEdge.allCases, inset: 0, priority: .low)
.toSafeArea(DirectionalEdge.allCases, inset: 25, priority: .high)
orangeView
.toSafeArea(DirectionalEdge.allCases, inset: 25, priority: .high)
.toSafeArea(DirectionalEdge.allCases, inset: 50)
}
}
}
Expand All @@ -727,15 +747,13 @@ final class LayoutItemTests: XCTestCase {
assertLayout { view in
view.layout {
pinkView
.toSafeArea(canonical: [.top, .left], inset: 50, priority: .high)
.toSafeArea()
blueView
.toSafeArea(inset: 0, priority: .high)
.toSafeArea(inset: 25)
orangeView
.toSafeArea(inset: 0, priority: .low)
.toSafeArea(inset: 50, priority: .high)
yellowView
.toSafeArea(canonical: [.top, .left, .right, .bottom], inset: 75)
orangeView
.toSafeArea(canonical: CanonicalEdge.allCases, inset: 75)
}
}
}
Expand Down
45 changes: 32 additions & 13 deletions Tests/LayoutTests/LayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,11 @@ final class LayoutTests: XCTestCase {

// To Anchor

layout.constrain(pinkView.leading,
is: .greaterThanOrEqual,
to: view.leading,
constant: 50,
priority: .high)
layout.constrain(pinkView.leading, to: view.leading)

// To Anchor with Constant
Expand Down Expand Up @@ -491,6 +496,7 @@ final class LayoutTests: XCTestCase {

// THEN

// swiftlint:disable:next closure_body_length
assertLayout { view in

let layout: Layout = view.layout {
Expand All @@ -509,6 +515,12 @@ final class LayoutTests: XCTestCase {

// To Anchor

layout.constrain(pinkView.height,
is: .greaterThanOrEqual,
to: yellowView.height,
multiplier: 0.5,
constant: 50,
priority: .high)
layout.constrain(pinkView.height, to: yellowView.height)

// To Anchor with Constant
Expand Down Expand Up @@ -589,24 +601,14 @@ final class LayoutTests: XCTestCase {
// GIVEN

let pinkView: UIView = pinkView
let yellowView: UIView = yellowView

// THEN

assertLayout { view in

let layout: Layout = view.layout {
pinkView
yellowView
}

// Pin to View

layout.constrain(pinkView, to: view)
let layout: Layout = view.layout(pinkView)

// Pin to View with EdgeInsets

layout.constrain(yellowView,
layout.constrain(pinkView,
to: view,
insets: NSDirectionalEdgeInsets(top: 40, leading: 40, bottom: 40, trailing: 40))

Expand Down Expand Up @@ -732,6 +734,7 @@ final class LayoutTests: XCTestCase {

// THEN

// swiftlint:disable:next closure_body_length
assertLayout { view in

let layout: Layout = view.layout {
Expand All @@ -749,6 +752,11 @@ final class LayoutTests: XCTestCase {

// Horizontal With Views and Alignment

layout.horizontal([pinkView, yellowView],
spacing: 20,
direction: .leftToRight,
priority: .high,
alignment: .centerY)
layout.horizontal([pinkView, yellowView], alignment: .centerY)

// Spacing, Direction and Priority
Expand Down Expand Up @@ -794,6 +802,12 @@ final class LayoutTests: XCTestCase {

// Horizontal With Views and Alignment

layout.horizontal([pinkView, yellowView],
spacing: 20,
direction: .leftToRight,
priority: .high,
alignment: .top,
.bottom)
layout.horizontal([pinkView, yellowView], alignment: .top, .bottom)

return layout
Expand Down Expand Up @@ -828,11 +842,13 @@ final class LayoutTests: XCTestCase {

// Vertical With Views and Alignment

layout.vertical([pinkView, yellowView], spacing: 20, priority: .high, alignment: .centerX)
layout.vertical([pinkView, yellowView], alignment: .centerX)

// Spacing

layout.vertical([blueView, greenView], spacing: 12, alignment: .centerX)
layout.vertical([blueView, greenView], spacing: 20, priority: .low, alignment: .centerX)
layout.vertical([blueView, greenView], spacing: 12, priority: .high, alignment: .centerX)

return layout
}
Expand All @@ -859,6 +875,7 @@ final class LayoutTests: XCTestCase {

// Vertical With Views and Alignment

layout.vertical([pinkView, yellowView], spacing: 20, priority: .high, alignment: .leading, .trailing)
layout.vertical([pinkView, yellowView], alignment: .leading, .trailing)

return layout
Expand All @@ -879,6 +896,7 @@ final class LayoutTests: XCTestCase {
.size(width: 100, height: 100)
.to(.top)
)
.center(pinkView, between: view.leading, and: view.leading, priority: .high)
.center(pinkView, between: view.leading, and: view.trailing)
}
}
Expand All @@ -905,6 +923,7 @@ final class LayoutTests: XCTestCase {

// Center Between

layout.center(yellowView, between: view.top, and: view.centerY, priority: .high)
layout.center(yellowView, between: view.top, and: view.bottom)

// With Priority
Expand Down
Loading