Skip to content

Commit 21f44a0

Browse files
authored
Merge pull request #22 from TimOliver/unit-tests
Added unit tests and fixed failing ones
2 parents 411179c + f08012e commit 21f44a0

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
x.y.z Release Notes (yyyy-MM-dd)
22
=============================================================
33

4-
1.1.0 Release Notes (yyyy-MM-dd)
4+
1.1.1 Release Notes (2019-06-21)
5+
=============================================================
6+
7+
### Enhancements
8+
9+
* Added unit tests to check consistent initial behaviour. ([#22](https://github.com/TimOliver/TORoundedButton/pull/22))
10+
* Updated the documentation in the header to match expected default values. ([#22](https://github.com/TimOliver/TORoundedButton/pull/22))
11+
12+
### Fixed
13+
14+
* A bug where the dynamic text size would not properly restore. ([#22](https://github.com/TimOliver/TORoundedButton/pull/22))
15+
16+
17+
1.1.0 Release Notes (2019-06-21)
518
=============================================================
619

720
### Enchancements

TORoundedButton/TORoundedButton.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ IB_DESIGNABLE @interface TORoundedButton : UIControl
4242
/** The color of the text in this button (Default is white) */
4343
@property (nonatomic, strong) IBInspectable UIColor *textColor;
4444

45-
/** When tapped, the level of transparency that the text label animates to. (Defaults to 0.5f) */
45+
/** When tapped, the level of transparency that the text label animates to. (Defaults to off with 1.0f) */
4646
@property (nonatomic, assign) IBInspectable CGFloat tappedTextAlpha;
4747

4848
/** The font of the text in the button (Default is size UIFontTextStyleBody with bold) */
@@ -57,7 +57,7 @@ IB_DESIGNABLE @interface TORoundedButton : UIControl
5757
/** If desired, explicity set the background color of the button when tapped (Default is nil). */
5858
@property (nonatomic, strong, nullable) IBInspectable UIColor *tappedTintColor;
5959

60-
/** When tapped, the scale by which the button shrinks during the animation (Default is off with 0.97f) */
60+
/** When tapped, the scale by which the button shrinks during the animation (Default is 0.97f) */
6161
@property (nonatomic, assign) IBInspectable CGFloat tappedButtonScale;
6262

6363
/** The duration of the tapping cross-fade animation (Default is 0.4f) */

TORoundedButton/TORoundedButton.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ - (instancetype)initWithText:(NSString *)text
5959
if (self = [super initWithFrame:(CGRect){0,0, 288.0f, 50.0f}]) {
6060
[self roundedButtonCommonInit];
6161
_titleLabel.text = text;
62+
[_titleLabel sizeToFit];
6263
}
6364

6465
return self;
@@ -113,8 +114,7 @@ - (void)roundedButtonCommonInit
113114
[self.containerView addSubview:self.backgroundView];
114115

115116
// Create the title label that will display the button text
116-
UIFont *buttonFont = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
117-
buttonFont = [UIFont systemFontOfSize:buttonFont.pointSize weight:UIFontWeightBold];
117+
UIFont *buttonFont = [UIFont systemFontOfSize:17.0f weight:UIFontWeightBold];
118118
if (@available(iOS 11.0, *)) {
119119
// Apply resizable button metrics to font
120120
UIFontMetrics *metrics = [[UIFontMetrics alloc] initForTextStyle:UIFontTextStyleBody];
@@ -128,7 +128,6 @@ - (void)roundedButtonCommonInit
128128
self.titleLabel.adjustsFontForContentSizeCategory = YES;
129129
self.titleLabel.backgroundColor = self.tintColor;
130130
self.titleLabel.text = @"Button";
131-
[self.titleLabel sizeToFit];
132131
[self.containerView addSubview:self.titleLabel];
133132

134133
// Create action events for all possible interactions with this control
@@ -145,6 +144,7 @@ - (void)layoutSubviews
145144
[super layoutSubviews];
146145

147146
// Configure the button text
147+
[self.titleLabel sizeToFit];
148148
self.titleLabel.center = self.containerView.center;
149149
self.titleLabel.frame = CGRectIntegral(self.titleLabel.frame);
150150
}

TORoundedButtonExampleTests/TORoundedButtonExampleTests.m

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,43 @@ @implementation TORoundedButtonExampleTests
1818
- (void)testDefaultValues
1919
{
2020
TORoundedButton *button = [[TORoundedButton alloc] initWithText:@"Test"];
21-
2221
XCTAssertNotNil(button);
22+
XCTAssertEqual(button.text, @"Test");
23+
XCTAssertEqual(button.cornerRadius, 12.0f);
24+
XCTAssertEqual(button.textColor, [UIColor whiteColor]);
25+
XCTAssertEqual(button.tappedTextAlpha, 1.0f);
26+
XCTAssertEqual(button.tappedTintColorBrightnessOffset, -0.1f);
27+
XCTAssertEqual(button.tappedButtonScale, 0.97f);
28+
}
29+
30+
- (void)testMinimimumWidth
31+
{
32+
TORoundedButton *button = [[TORoundedButton alloc] initWithText:@"Long Button Name"];
33+
34+
// Manually
35+
UILabel *titleLabel = nil;
36+
for (UIView *subview in button.subviews.firstObject.subviews) {
37+
if ([subview isKindOfClass:[UILabel class]]) {
38+
titleLabel = (UILabel *)subview;
39+
break;
40+
}
41+
}
42+
43+
XCTAssert(button.minimumWidth > 0.0f);
44+
XCTAssertEqual(titleLabel.frame.size.width, button.minimumWidth);
45+
}
46+
47+
- (void)testButtonInteraction
48+
{
49+
TORoundedButton *button = [[TORoundedButton alloc] initWithText:@"Long Button Name"];
50+
51+
XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"Button was tapped"];
52+
button.tappedHandler = ^{ [expectation fulfill]; };
53+
54+
// Simulate button tap
55+
[button sendActionsForControlEvents:UIControlEventTouchUpInside];
56+
57+
[self waitForExpectations:@[expectation] timeout:0.5f];
2358
}
2459

2560
@end

0 commit comments

Comments
 (0)