diff --git a/Sources/YTags/TagView+Shape.swift b/Sources/YTags/TagView+Shape.swift index a380335..d909519 100644 --- a/Sources/YTags/TagView+Shape.swift +++ b/Sources/YTags/TagView+Shape.swift @@ -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 } } diff --git a/Tests/YTagsTests/TagViewTests.swift b/Tests/YTagsTests/TagViewTests.swift index c53ad6f..c3d0b79 100644 --- a/Tests/YTagsTests/TagViewTests.swift +++ b/Tests/YTagsTests/TagViewTests.swift @@ -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() @@ -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)) }