Skip to content

Commit

Permalink
Refactor unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Pospesel authored and devyml committed Apr 4, 2023
1 parent b61509e commit 577ffd9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
12 changes: 6 additions & 6 deletions Sources/YTags/TagView+Shape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import UIKit

extension TagView.Appearance {
/// Tag shape.
/// Tag shape
public enum Shape: Equatable {
/// Rectangle.
/// Rectangle
case rectangle
/// Rounded rectangle.
/// Rounded rectangle
case roundRect(cornerRadius: CGFloat)
/// Capsule.
case capsule
/// Scaled round rect.
/// Scaled round rect
case scaledRoundRect(cornerRadius: CGFloat)
/// Capsule
case capsule
}
}
23 changes: 14 additions & 9 deletions Tests/YTagsTests/TagViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ final class TagViewTests: XCTestCase {

func test_customShape() {
let sut = makeSUT()
let cornerRadius: CGFloat = 13
let cornerRadius = CGFloat(Int.random(in: 1...13))
sut.appearance.shape = .roundRect(cornerRadius: cornerRadius)

sut.layoutIfNeeded()
Expand All @@ -139,16 +139,21 @@ final class TagViewTests: XCTestCase {
XCTAssertEqual(sut.appearance.shape, .roundRect(cornerRadius: cornerRadius))
}

func test_customScaledShape() {
func test_scaledRoundRectShape() {
// Given
let sut = makeSUT()
let cornerRadius: CGFloat = 13
sut.titleLabel.maximumScaleFactor = 2
let cornerRadius = CGFloat(Int.random(in: 1...8))
sut.appearance.shape = .scaledRoundRect(cornerRadius: cornerRadius)

sut.layoutIfNeeded()

let scaledFactor = sut.titleLabel.layout.lineHeight / sut.titleLabel.typography.lineHeight

XCTAssertEqual(sut.layer.cornerRadius, cornerRadius * scaledFactor )
let (parent, child) = makeNestedViewControllers(subview: sut)

// When
let traits = UITraitCollection(preferredContentSizeCategory: .accessibilityExtraExtraExtraLarge)
parent.setOverrideTraitCollection(traits, forChild: child)
sut.traitCollectionDidChange(traits)

// Then
XCTAssertEqual(sut.layer.cornerRadius, 2 * cornerRadius)
XCTAssertEqual(sut.appearance.shape, .scaledRoundRect(cornerRadius: cornerRadius))
}

Expand Down

0 comments on commit 577ffd9

Please sign in to comment.