Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions Example/SSDynamicTextExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/* Begin PBXBuildFile section */
25DE1D35E98A96562C2C3C9F /* libPods-SSDynamicTextExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A40B656FCA8C692363D81440 /* libPods-SSDynamicTextExample.a */; };
5E90DACD19F9655600257F8E /* SSDynamicTextTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E90DACC19F9655600257F8E /* SSDynamicTextTests.m */; };
4181AA311C30229E0000DDC1 /* SSDynamicsView.m in Sources */ = {isa = PBXBuildFile; fileRef = B74328F41B9461E60098E793 /* SSDynamicsView.m */; };
5EE286D7180239B800D286ED /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EE286D6180239B800D286ED /* Foundation.framework */; };
5EE286D9180239B800D286ED /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EE286D8180239B800D286ED /* CoreGraphics.framework */; };
5EE286DB180239B800D286ED /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EE286DA180239B800D286ED /* UIKit.framework */; };
Expand Down Expand Up @@ -49,7 +49,6 @@
46106B6E541D73855CEB3345 /* Pods-SSDynamicTextTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SSDynamicTextTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SSDynamicTextTests/Pods-SSDynamicTextTests.debug.xcconfig"; sourceTree = "<group>"; };
5E90DAC819F9655600257F8E /* SSDynamicTextTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SSDynamicTextTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
5E90DACB19F9655600257F8E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5E90DACC19F9655600257F8E /* SSDynamicTextTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SSDynamicTextTests.m; sourceTree = "<group>"; };
5EE286D3180239B800D286ED /* SSDynamicTextExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SSDynamicTextExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
5EE286D6180239B800D286ED /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
5EE286D8180239B800D286ED /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -111,9 +110,6 @@
5E90DAC919F9655600257F8E /* SSDynamicTextTests */ = {
isa = PBXGroup;
children = (
B70414E41BAAF5750055958F /* SSTestsHelper.h */,
B70414E51BAAF5750055958F /* SSTestsHelper.m */,
5E90DACC19F9655600257F8E /* SSDynamicTextTests.m */,
B74328EF1B9455DC0098E793 /* SSDynamicLabelTests.m */,
B74328F61B946E2A0098E793 /* SSDynamicTextFieldTests.m */,
B74328F81B946EEB0098E793 /* SSDynamicTextViewTests.m */,
Expand All @@ -122,6 +118,8 @@
6696C9C11C14E7880067D4A4 /* SSDynamicViewsReleaseTests.m */,
667FF3871C0E4B0A00973E4C /* UIApplication+SSTextSizeTests.m */,
6611CBF41C0E52CC003E68A3 /* UIView+SSTextSizeTests.m */,
B70414E41BAAF5750055958F /* SSTestsHelper.h */,
B70414E51BAAF5750055958F /* SSTestsHelper.m */,
B74328FC1B9476010098E793 /* SSAttributedStringValidator.h */,
B74328FD1B9476010098E793 /* SSAttributedStringValidator.m */,
5E90DACA19F9655600257F8E /* Supporting Files */,
Expand Down Expand Up @@ -377,11 +375,11 @@
files = (
B74328F01B9455DC0098E793 /* SSDynamicLabelTests.m in Sources */,
B74328F91B946EEB0098E793 /* SSDynamicTextViewTests.m in Sources */,
4181AA311C30229E0000DDC1 /* SSDynamicsView.m in Sources */,
B74328F71B946E2A0098E793 /* SSDynamicTextFieldTests.m in Sources */,
B74328FE1B9476010098E793 /* SSAttributedStringValidator.m in Sources */,
6696C9C21C14E7880067D4A4 /* SSDynamicViewsReleaseTests.m in Sources */,
661812031C0CED6C00F558EC /* UIFont+SSTextSizeTests.m in Sources */,
5E90DACD19F9655600257F8E /* SSDynamicTextTests.m in Sources */,
6611CBF51C0E52CC003E68A3 /* UIView+SSTextSizeTests.m in Sources */,
667FF3881C0E4B0A00973E4C /* UIApplication+SSTextSizeTests.m in Sources */,
B70414E61BAAF5750055958F /* SSTestsHelper.m in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Example/SSDynamicTextTests/SSAttributedStringValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SSDynamicTextExample
//
// Created by Remigiusz Herba on 31/08/15.
//
// Copyright (c) 2015 Splinesoft. All rights reserved.
//

#import <UIKit/UIKit.h>
Expand Down
125 changes: 90 additions & 35 deletions Example/SSDynamicTextTests/SSDynamicButtonTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,126 @@
// SSDynamicTextExample
//
// Created by Remigiusz Herba on 31/08/15.
//
// Copyright (c) 2015 Splinesoft. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import <SSDynamicButton.h>
#import "SSDynamicsView.h"
#import "SSAttributedStringValidator.h"
#import "SSTestsHelper.h"
#import "SSAttributedStringValidator.h"

@interface SSDynamicButtonTests : XCTestCase

@property (nonatomic, strong) SSDynamicButton *dynamicButton;
@property (nonatomic, strong) SSDynamicButton *dynamicButtonFromXib;
#import "SSDynamicButton.h"
#import "SSDynamicsView.h"

@interface SSDynamicButtonTests : XCTestCase
@end

@implementation SSDynamicButtonTests

- (void)setUp {
[super setUp];
self.dynamicButton = [SSDynamicButton buttonWithFont:SSTestFontName baseSize:SSTestFontSize];

SSDynamicsView *view = [[NSBundle mainBundle] loadNibNamed:@"SSDynamicsView" owner:nil options:nil].firstObject;
self.dynamicButtonFromXib = view.button;
[SSTestsHelper startMockingPreferredContentSizeCategory:UIContentSizeCategoryExtraExtraLarge];
//Default content size category
[SSTestsHelper startMockingPreferredContentSizeCategory:UIContentSizeCategoryLarge];
}

- (void)tearDown {
[SSTestsHelper stopMockingPreferredContentSizeCategory];
[super tearDown];
}

- (void)testDefaultSettings {
//Assert
XCTAssertEqualObjects(self.dynamicButton.titleLabel.font.fontName, SSTestFontName);
XCTAssertEqualObjects(self.dynamicButtonFromXib.titleLabel.font.fontName, SSTestFontName);
XCTAssertEqual(self.dynamicButton.titleLabel.font.pointSize, SSTestFontSize);
XCTAssertEqual(self.dynamicButtonFromXib.titleLabel.font.pointSize, SSTestFontSize);
- (NSArray<SSDynamicButton *> *)dynamicButtonsWithFontName:(NSString *)fontName fontSize:(CGFloat)fontSize {
SSDynamicButton *dynamicButtonWithFont = [SSDynamicButton buttonWithFont:fontName baseSize:fontSize];

UIFontDescriptor *fontDescriptor = [UIFontDescriptor fontDescriptorWithName:fontName size:fontSize];
SSDynamicButton *dynamicButtonWithFontDescriptor = [SSDynamicButton buttonWithFontDescriptor:fontDescriptor];

SSDynamicsView *view = [[NSBundle mainBundle] loadNibNamed:@"SSDynamicsView" owner:nil options:nil].firstObject;
SSDynamicButton *dynamicButtonFromXib = view.button;

return @[ dynamicButtonWithFont, dynamicButtonWithFontDescriptor, dynamicButtonFromXib ];
}

- (void)testContentSizeChange {
- (void)testButtonTitleLabelFontNameShouldBeEqualToFontNameFromConstructor {
//Arrange
NSString *expectedFontName = SSTestFontName;

//Act
[SSTestsHelper postContentSizeChangeNotification];
NSArray<SSDynamicButton *> *dynamicButtons = [self dynamicButtonsWithFontName:SSTestFontName fontSize:SSTestFontSize];

//Assert
XCTAssertEqual(self.dynamicButton.titleLabel.font.pointSize, SSTestFontSize + SSTestFontSizeDifferenceForSizeExtraExtraLarge);
XCTAssertEqual(self.dynamicButtonFromXib.titleLabel.font.pointSize, SSTestFontSize + SSTestFontSizeDifferenceForSizeExtraExtraLarge);
for (SSDynamicButton *button in dynamicButtons) {
//Assert
XCTAssertEqualObjects(button.titleLabel.font.fontName, expectedFontName);
}
}

- (void)testAttributedStringContentSizeChange {
- (void)testButtonTitleLabelFontSizeShouldBeEqualToFontSizeInConstructorForDefaultPreferredContentSizeCategory {
//Arrange
NSAttributedString *attributedString = [SSAttributedStringValidator testAttributedString];
[self.dynamicButton setAttributedTitle:attributedString forState:UIControlStateNormal];
[self.dynamicButtonFromXib setAttributedTitle:attributedString forState:UIControlStateNormal];
[SSTestsHelper postContentSizeChangeNotification];
CGFloat expectedFontSize = SSTestFontSize;

//Act
[[NSNotificationCenter defaultCenter] postNotificationName:UIContentSizeCategoryDidChangeNotification object:nil];
NSArray<SSDynamicButton *> *dynamicButtons = [self dynamicButtonsWithFontName:SSTestFontName fontSize:SSTestFontSize];

for (SSDynamicButton *button in dynamicButtons) {
//Assert
XCTAssertEqualWithAccuracy(button.titleLabel.font.pointSize, expectedFontSize, FLT_EPSILON);
}
}

- (void)testButtonTitleLabelFontSizeShouldBeEqualToLabelFontSizeIncreasedByPreferredContentSizeCategoryDelta {
// Arrange
[SSTestsHelper startMockingPreferredContentSizeCategory:UIContentSizeCategoryExtraExtraLarge];

CGFloat initialFontSize = SSTestFontSize;

//Act
NSArray<SSDynamicButton *> *dynamicButtons = [self dynamicButtonsWithFontName:SSTestFontName fontSize:initialFontSize];

for (SSDynamicButton *button in dynamicButtons) {

//Assert
XCTAssertEqualWithAccuracy(button.titleLabel.font.pointSize, initialFontSize + SSTestFontSizeDifferenceForSizeExtraExtraLarge, FLT_EPSILON);
}
}

/**
Uncomment after fix: https://github.com/splinesoft/SSDynamicText/issues/27
- (void)testButtonTitleLabelFontSizeShouldBeEqualToNewFontSizeIncreasedByContentSizeCategoryDelta {
//Arrange
CGFloat newFontSize = 7.0f;
UIFont *newFont = [UIFont systemFontOfSize:newFontSize];

NSArray<SSDynamicButton *> *dynamicButtons = [self dynamicButtonsWithFontName:SSTestFontName fontSize:SSTestFontSize];

[SSTestsHelper startMockingPreferredContentSizeCategory:UIContentSizeCategoryExtraExtraLarge];

for (SSDynamicButton *button in dynamicButtons) {
//Act
button.titleLabel.font = newFont;

//Assert
XCTAssertEqualWithAccuracy(button.titleLabel.font.pointSize, newFontSize + SSTestFontSizeDifferenceForSizeExtraExtraLarge, FLT_EPSILON);
}
}
*/

- (void)testButtonTitleLabelAttributedStringFontSizesShouldBeIncreasedByContentSizeCategoryDelta {
//Arrange
NSAttributedString *attributedString = [SSAttributedStringValidator testAttributedString];

NSArray<SSDynamicButton *> *dynamicButtons = [self dynamicButtonsWithFontName:SSTestFontName fontSize:SSTestFontSize];

[SSTestsHelper startMockingPreferredContentSizeCategory:UIContentSizeCategoryExtraExtraLarge];

for (SSDynamicButton *button in dynamicButtons) {
//Act
[button setAttributedTitle:attributedString forState:UIControlStateNormal];

//Assert
XCTAssertTrue([SSAttributedStringValidator isValidTestAttributedString:button.titleLabel.attributedText
changedByDelta:SSTestFontSizeDifferenceForSizeExtraExtraLarge]);

//Assert
XCTAssertTrue([SSAttributedStringValidator isValidTestAttributedString:self.dynamicButton.titleLabel.attributedText
changedByDelta:SSTestFontSizeDifferenceForSizeExtraExtraLarge]);
XCTAssertTrue([SSAttributedStringValidator isValidTestAttributedString:self.dynamicButtonFromXib.titleLabel.attributedText
changedByDelta:SSTestFontSizeDifferenceForSizeExtraExtraLarge]);
XCTAssertEqualObjects(button.titleLabel.attributedText.string, attributedString.string);
}
}

@end
126 changes: 79 additions & 47 deletions Example/SSDynamicTextTests/SSDynamicLabelTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,91 +3,123 @@
// SSDynamicTextExample
//
// Created by Remigiusz Herba on 31/08/15.
//
// Copyright (c) 2015 Splinesoft. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import <SSDynamicLabel.h>
#import "SSDynamicsView.h"
#import "SSAttributedStringValidator.h"
#import "SSTestsHelper.h"
#import "SSAttributedStringValidator.h"

@interface SSDynamicLabelTests : XCTestCase

@property (nonatomic, strong) SSDynamicLabel *dynamicLabel;
@property (nonatomic, strong) SSDynamicLabel *dynamicLabelFromXib;
#import "SSDynamicLabel.h"
#import "SSDynamicsView.h"

@interface SSDynamicLabelTests : XCTestCase
@end

@implementation SSDynamicLabelTests

- (void)setUp {
[super setUp];
self.dynamicLabel = [SSDynamicLabel labelWithFont:SSTestFontName baseSize:SSTestFontSize];

SSDynamicsView *view = [[NSBundle mainBundle] loadNibNamed:@"SSDynamicsView" owner:nil options:nil].firstObject;
self.dynamicLabelFromXib = view.label;
[SSTestsHelper startMockingPreferredContentSizeCategory:UIContentSizeCategoryExtraExtraLarge];
//Default content size category
[SSTestsHelper startMockingPreferredContentSizeCategory:UIContentSizeCategoryLarge];
}

- (void)tearDown {
[SSTestsHelper stopMockingPreferredContentSizeCategory];
[super tearDown];
}

- (NSArray *)dynamicLabelsWithFontName:(NSString *)fontName fontSize:(CGFloat)fontSize {
SSDynamicLabel *dynamicLabelWithFont = [SSDynamicLabel labelWithFont:fontName baseSize:fontSize];

UIFontDescriptor *fontDescriptor = [UIFontDescriptor fontDescriptorWithName:fontName size:fontSize];
SSDynamicLabel *dynamicLabelWithFontDescriptor = [SSDynamicLabel labelWithFontDescriptor:fontDescriptor];

- (void)testDefaultSettings {
//Assert
XCTAssertEqualObjects(self.dynamicLabel.font.fontName, SSTestFontName);
XCTAssertEqualObjects(self.dynamicLabelFromXib.font.fontName, SSTestFontName);
XCTAssertEqual(self.dynamicLabel.font.pointSize, SSTestFontSize);
XCTAssertEqual(self.dynamicLabelFromXib.font.pointSize, SSTestFontSize);
SSDynamicsView *view = [[NSBundle mainBundle] loadNibNamed:@"SSDynamicsView" owner:nil options:nil].firstObject;
SSDynamicLabel *dynamicLabelFromXib = view.label;

return @[ dynamicLabelWithFont, dynamicLabelWithFontDescriptor, dynamicLabelFromXib ];
}

- (void)testContentSizeChange {
- (void)testLabelFontNameShouldBeEqualToFontNameFromConstructor {
//Arrange
NSString *expectedFontName = SSTestFontName;

//Act
[SSTestsHelper postContentSizeChangeNotification];
NSArray *dynamicLabels = [self dynamicLabelsWithFontName:SSTestFontName fontSize:SSTestFontSize];

//Assert
XCTAssertEqual(self.dynamicLabel.font.pointSize, SSTestFontSize + SSTestFontSizeDifferenceForSizeExtraExtraLarge);
XCTAssertEqual(self.dynamicLabelFromXib.font.pointSize, SSTestFontSize + SSTestFontSizeDifferenceForSizeExtraExtraLarge);
for (SSDynamicLabel *label in dynamicLabels) {
//Assert
XCTAssertEqualObjects(label.font.fontName, expectedFontName);
}
}

- (void)testFontChangeAndThenContentSizeChange {
- (void)testLabelFontSizeShouldBeEqualToFontSizeInConstructorForDefaultPreferredContentSizeCategory {
//Arrange
CGFloat expectedFontSize = SSTestFontSize;

//Act
NSArray<SSDynamicLabel *> *dynamicLabels = [self dynamicLabelsWithFontName:SSTestFontName fontSize:SSTestFontSize];

for (SSDynamicLabel *label in dynamicLabels) {
//Assert
XCTAssertEqualWithAccuracy(label.font.pointSize, expectedFontSize, FLT_EPSILON);
}
}

- (void)testLabelFontSizeShouldBeEqualToLabelFontSizeIncreasedByPreferredContentSizeCategoryDelta {
// Arrange
[SSTestsHelper startMockingPreferredContentSizeCategory:UIContentSizeCategoryExtraExtraLarge];

CGFloat initialFontSize = SSTestFontSize;

//Act
NSArray<SSDynamicLabel *> *dynamicLabels = [self dynamicLabelsWithFontName:SSTestFontName fontSize:initialFontSize];

for (SSDynamicLabel *label in dynamicLabels) {

//Assert
XCTAssertEqualWithAccuracy(label.font.pointSize, initialFontSize + SSTestFontSizeDifferenceForSizeExtraExtraLarge, FLT_EPSILON);
}
}

- (void)testLabelFontSizeShouldBeEqualToNewFontSizeIncreasedByContentSizeCategoryDelta {
//Arrange
CGFloat newFontSize = 7.0f;
UIFont *newFont = [UIFont systemFontOfSize:newFontSize];

//Act
self.dynamicLabel.font = newFont;
self.dynamicLabelFromXib.font = newFont;
[SSTestsHelper postContentSizeChangeNotification];

//Assert
XCTAssertEqualObjects(self.dynamicLabel.font.fontName, newFont.fontName);
XCTAssertEqualObjects(self.dynamicLabelFromXib.font.fontName, newFont.fontName);
XCTAssertEqual(self.dynamicLabel.font.pointSize, newFontSize + SSTestFontSizeDifferenceForSizeExtraExtraLarge);
XCTAssertEqual(self.dynamicLabelFromXib.font.pointSize, newFontSize + SSTestFontSizeDifferenceForSizeExtraExtraLarge);
NSArray<SSDynamicLabel *> *dynamicLabels = [self dynamicLabelsWithFontName:SSTestFontName fontSize:SSTestFontSize];

[SSTestsHelper startMockingPreferredContentSizeCategory:UIContentSizeCategoryExtraExtraLarge];

for (SSDynamicLabel *label in dynamicLabels) {
//Act
label.font = newFont;

//Assert
XCTAssertEqualWithAccuracy(label.font.pointSize, newFontSize + SSTestFontSizeDifferenceForSizeExtraExtraLarge, FLT_EPSILON);
}
}

- (void)testAttributedStringContentSizeChange {
- (void)testLabelAttributedStringFontSizesShouldBeIncreasedByContentSizeCategoryDelta {
//Arrange
NSAttributedString *attributedString = [SSAttributedStringValidator testAttributedString];
self.dynamicLabel.dynamicAttributedText = attributedString;
self.dynamicLabelFromXib.dynamicAttributedText = attributedString;

//Act
[SSTestsHelper postContentSizeChangeNotification];
NSArray<SSDynamicLabel *> *dynamicLabels = [self dynamicLabelsWithFontName:SSTestFontName fontSize:SSTestFontSize];

[SSTestsHelper startMockingPreferredContentSizeCategory:UIContentSizeCategoryExtraExtraLarge];

for (SSDynamicLabel *label in dynamicLabels) {
//Act
label.dynamicAttributedText = attributedString;

//Assert
XCTAssertTrue([SSAttributedStringValidator isValidTestAttributedString:self.dynamicLabel.attributedText
changedByDelta:SSTestFontSizeDifferenceForSizeExtraExtraLarge]);
XCTAssertTrue([SSAttributedStringValidator isValidTestAttributedString:self.dynamicLabelFromXib.attributedText
changedByDelta:SSTestFontSizeDifferenceForSizeExtraExtraLarge]);
//Assert
XCTAssertTrue([SSAttributedStringValidator isValidTestAttributedString:label.attributedText
changedByDelta:SSTestFontSizeDifferenceForSizeExtraExtraLarge]);

XCTAssertEqualObjects(attributedString, self.dynamicLabel.dynamicAttributedText);
XCTAssertEqualObjects(attributedString, self.dynamicLabelFromXib.dynamicAttributedText);
XCTAssertEqualObjects(label.dynamicAttributedText, attributedString);
}
}

@end
Loading