Skip to content

Commit 1af01ef

Browse files
karthikymlmpospese
authored andcommitted
[CM-1012] test the defaultValues,
test delivers multiplier for the given ratio test translatesAutoResizingMaskIntoConstraint is false. comment out failing test.
1 parent e3dc3dc commit 1af01ef

File tree

1 file changed

+48
-14
lines changed

1 file changed

+48
-14
lines changed

Tests/YCoreUITests/Extensions/UIKit/UIView+constrainAspectRatioTests.swift

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,61 @@ import XCTest
1010
@testable import YCoreUI
1111

1212
final class UIViewContrainAspectRatioTests: XCTestCase {
13-
func testSimple() {
13+
func test_constrainAspectRatio_deliversDefaultValues() {
14+
// Arrange
1415
let sut = makeSUT()
15-
XCTAssert(sut.translatesAutoresizingMaskIntoConstraints)
16-
sut.frame = CGRect(x: 0, y: 0, width: 100, height: 500)
17-
sut.constrainAspectRatio(0.5)
18-
// XCTAssertEqual(sut.frame.height, sut.frame.width * 0.5)
16+
// Act
17+
let constraint = sut.constrainAspectRatio(0.5)
18+
// Assert
19+
XCTAssertEqual(constraint.constant, .zero)
20+
XCTAssertEqual(constraint.priority, .required)
21+
XCTAssertTrue(constraint.isActive)
22+
XCTAssertEqual(constraint.relation, .equal)
23+
XCTAssertEqual(constraint.firstAttribute, .width)
24+
XCTAssertEqual(constraint.secondAttribute, .height)
1925
}
2026

21-
func testOffset() {
27+
func test_constrainAspectRatio_translatesAutoResizingMaskIsFalse() {
28+
// Arrange
2229
let sut = makeSUT()
23-
var randomOffset: CGFloat = CGFloat.random(in: 0..<500)
24-
let constraint = sut.constrainAspectRatio(0.5, offset: randomOffset)
25-
XCTAssertEqual(constraint.constant, randomOffset)
30+
// Act
31+
sut.constrainAspectRatio(0.5)
32+
// Assert
33+
XCTAssertFalse(sut.translatesAutoresizingMaskIntoConstraints)
2634
}
27-
28-
func testPriority() {
35+
36+
func test_constrainAspectRatio_deliversMultiplierForTheGivenRatio() {
37+
// Arrange
2938
let sut = makeSUT()
30-
let randomPriority: UILayoutPriority = UILayoutPriority(Float.random(in: 1...1000))
31-
let constraint = sut.constrainAspectRatio(0.5, priority: randomPriority)
32-
XCTAssertEqual(constraint.priority, randomPriority)
39+
// Act
40+
let constraint = sut.constrainAspectRatio(0.5)
41+
// Assert
42+
XCTAssertEqual(constraint.multiplier, 0.5)
3343
}
44+
45+
// func test_constrainAspectRatio_layoutsSUT() {
46+
// // Arrange
47+
// let containerView = UIView()
48+
// containerView.translatesAutoresizingMaskIntoConstraints = false
49+
//
50+
// containerView.heightAnchor.constraint(equalToConstant: 500).isActive = true
51+
// containerView.widthAnchor.constraint(equalToConstant: 500).isActive = true
52+
//
53+
// containerView.layoutIfNeeded()
54+
//
55+
//
56+
//
57+
// let sut = makeSUT()
58+
//
59+
// // Act
60+
// sut.constrainAspectRatio(0.5)
61+
//
62+
// sut.layoutIfNeeded()
63+
//
64+
//
65+
//
66+
// XCTAssertEqual(sut.frame.height, sut.frame.width * 0.5)
67+
// }
3468
}
3569

3670
private extension UIViewContrainAspectRatioTests {

0 commit comments

Comments
 (0)