-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebd6ed9
commit 990c7c4
Showing
2 changed files
with
148 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
// | ||
// All Contributions by Match Group | ||
// | ||
// Copyright © 2023 Tinder (Match Group, LLC) | ||
// | ||
// Licensed under the Match Group Modified 3-Clause BSD License. | ||
// See https://github.com/Tinder/Layout/blob/main/LICENSE for license information. | ||
// | ||
|
||
@testable import Layout | ||
import Nimble | ||
import XCTest | ||
|
||
@MainActor | ||
final class ArrayTests: XCTestCase { | ||
|
||
func testActivation() { | ||
|
||
// GIVEN | ||
|
||
let view: UIView = .init() | ||
let constraint1: NSLayoutConstraint = .init( | ||
item: view, | ||
attribute: .height, | ||
relatedBy: .equal, | ||
toItem: nil, | ||
attribute: .notAnAttribute, | ||
multiplier: 1, | ||
constant: 0 | ||
) | ||
let constraint2: NSLayoutConstraint = .init( | ||
item: view, | ||
attribute: .width, | ||
relatedBy: .equal, | ||
toItem: nil, | ||
attribute: .notAnAttribute, | ||
multiplier: 1, | ||
constant: 0 | ||
) | ||
let constraints: [NSLayoutConstraint] = [constraint1, constraint2] | ||
|
||
// THEN | ||
|
||
expect(constraint1.isActive) == false | ||
expect(constraint2.isActive) == false | ||
|
||
// WHEN | ||
|
||
let activatedConstraints: [NSLayoutConstraint] = constraints.activate() | ||
|
||
// THEN | ||
|
||
expect(constraint1.isActive) == true | ||
expect(constraint2.isActive) == true | ||
expect(activatedConstraints) == constraints | ||
|
||
// WHEN | ||
|
||
let deactivatedConstraints: [NSLayoutConstraint] = constraints.deactivate() | ||
|
||
// THEN | ||
|
||
expect(constraint1.isActive) == false | ||
expect(constraint2.isActive) == false | ||
expect(deactivatedConstraints) == constraints | ||
} | ||
|
||
func testWithPriority() { | ||
|
||
// GIVEN | ||
|
||
let view: UIView = .init() | ||
let constraint1: NSLayoutConstraint = .init( | ||
item: view, | ||
attribute: .height, | ||
relatedBy: .equal, | ||
toItem: nil, | ||
attribute: .notAnAttribute, | ||
multiplier: 1, | ||
constant: 0 | ||
) | ||
let constraint2: NSLayoutConstraint = .init( | ||
item: view, | ||
attribute: .width, | ||
relatedBy: .equal, | ||
toItem: nil, | ||
attribute: .notAnAttribute, | ||
multiplier: 1, | ||
constant: 0 | ||
) | ||
let constraints: [NSLayoutConstraint] = [constraint1, constraint2] | ||
|
||
// THEN | ||
|
||
expect(constraint1.priority) == .required | ||
expect(constraint2.priority) == .required | ||
|
||
// WHEN | ||
|
||
let highPriorityConstraints: [NSLayoutConstraint] = constraints.withPriority(.high) | ||
|
||
// THEN | ||
|
||
expect(constraint1.priority) == .high | ||
expect(constraint2.priority) == .high | ||
expect(highPriorityConstraints) == constraints | ||
} | ||
|
||
func testPrioritize() { | ||
|
||
// GIVEN | ||
|
||
let view: UIView = .init() | ||
let constraint1: NSLayoutConstraint = .init( | ||
item: view, | ||
attribute: .height, | ||
relatedBy: .equal, | ||
toItem: nil, | ||
attribute: .notAnAttribute, | ||
multiplier: 1, | ||
constant: 0 | ||
) | ||
let constraint2: NSLayoutConstraint = .init( | ||
item: view, | ||
attribute: .width, | ||
relatedBy: .equal, | ||
toItem: nil, | ||
attribute: .notAnAttribute, | ||
multiplier: 1, | ||
constant: 0 | ||
) | ||
let constraints: [NSLayoutConstraint] = [constraint1, constraint2] | ||
|
||
// THEN | ||
|
||
expect(constraint1.priority) == .required | ||
expect(constraint2.priority) == .required | ||
|
||
// WHEN | ||
|
||
constraints.prioritize(.high) | ||
|
||
// THEN | ||
|
||
expect(constraint1.priority) == .high | ||
expect(constraint2.priority) == .high | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters