Skip to content

Commit

Permalink
Add tests for default parameters (#240)
Browse files Browse the repository at this point in the history
* Update Layout snapshot

* Update LayoutItem snapshots

* Update Tests/LayoutTests/LayoutItemTests.swift

Co-authored-by: Garric Nahapetian <[email protected]>

* Test defaults in LayoutItemTests.swift

* Test defaults in LayoutTests.swift

* Add tests for UIView+AutoLayout

* Update Tests/LayoutTests/LayoutItemTests.swift

Co-authored-by: Garric Nahapetian <[email protected]>

* Implement review feedback

---------

Co-authored-by: Garric Nahapetian <[email protected]>
  • Loading branch information
1 parent 966b9a4 commit e46f329
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 22 deletions.
24 changes: 24 additions & 0 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 Down Expand Up @@ -594,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 Down Expand Up @@ -652,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 @@ -672,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 @@ -696,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 Down Expand Up @@ -724,6 +747,7 @@ final class LayoutItemTests: XCTestCase {
assertLayout { view in
view.layout {
pinkView
.toSafeArea(canonical: [.top, .left], inset: 50, priority: .high)
.toSafeArea()
blueView
.toSafeArea(inset: 0, priority: .low)
Expand Down
31 changes: 30 additions & 1 deletion 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 @@ -719,6 +731,7 @@ final class LayoutTests: XCTestCase {

// THEN

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

let layout: Layout = view.layout {
Expand All @@ -736,6 +749,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 @@ -781,6 +799,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 @@ -815,11 +839,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 @@ -846,6 +872,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 @@ -866,6 +893,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 @@ -892,6 +920,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

0 comments on commit e46f329

Please sign in to comment.