This repository was archived by the owner on Dec 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 371
Expand file tree
/
Copy pathCustomizationTests.m
More file actions
153 lines (123 loc) · 6.46 KB
/
CustomizationTests.m
File metadata and controls
153 lines (123 loc) · 6.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//
// CustomizationTests.m
// SimpleLineChart
//
// Created by Bobo on 8/26/15.
// Copyright (c) 2015 Boris Emorine. All rights reserved.
//
@import XCTest;
#import "BEMSimpleLineGraphView.h"
#import "contantsTests.h"
/// Same tags as in BEMSimpleLineGraphView.m
typedef NS_ENUM(NSInteger, BEMInternalTags)
{
DotFirstTag100 = 100,
DotLastTag1000 = 1000,
LabelYAxisTag2000 = 2000,
BackgroundYAxisTag2100 = 2100,
BackgroundXAxisTag2200 = 2200,
PermanentPopUpViewTag3100 = 3100,
};
@interface CustomizationTests : XCTestCase <BEMSimpleLineGraphDelegate, BEMSimpleLineGraphDataSource>
@property (strong, nonatomic) BEMSimpleLineGraphView *lineGraph;
@end
@implementation CustomizationTests
- (void)setUp {
[super setUp];
self.lineGraph = [[BEMSimpleLineGraphView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
self.lineGraph.delegate = self;
self.lineGraph.dataSource = self;
}
#pragma mark BEMSimpleLineGraph Data Source
- (NSInteger)numberOfPointsInLineGraph:(BEMSimpleLineGraphView * __nonnull)graph {
return numberOfPoints;
}
- (CGFloat)lineGraph:(BEMSimpleLineGraphView * __nonnull)graph valueForPointAtIndex:(NSInteger)index {
return pointValue;
}
- (NSString *)lineGraph:(nonnull BEMSimpleLineGraphView *)graph labelOnXAxisForIndex:(NSInteger)index {
return xAxisLabelString;
}
- (NSString *)popUpPrefixForlineGraph:(BEMSimpleLineGraphView * __nonnull)graph atIndex:(NSUInteger)index{
return popUpPrefix;
}
- (NSString *)popUpSuffixForlineGraph:(BEMSimpleLineGraphView * __nonnull)graph atIndex:(NSUInteger)index{
return popUpSuffix;
}
#pragma mark Tests
- (void)testDotCustomization {
CGFloat sizePoint = 20.0;
self.lineGraph.alwaysDisplayDots = YES;
self.lineGraph.animationGraphEntranceTime = 0.0;
self.lineGraph.sizePoint = sizePoint;
self.lineGraph.colorPoint = [UIColor greenColor];
[self.lineGraph reloadGraph];
NSMutableArray *dots = [NSMutableArray new];
for (UIView *dot in self.lineGraph.subviews) {
if ([dot isKindOfClass:[BEMCircle class]] && dot.tag >= DotFirstTag100 && dot.tag <= DotLastTag1000) {
[dots addObject:dot];
}
}
XCTAssert(dots.count == numberOfPoints, @"There should be as many BEMCircle views in the graph's subviews as the data source method 'numberOfPointsInLineGraph:' returns");
for (BEMCircle *dot in dots) {
XCTAssert(dot.bounds.size.width == sizePoint, @"Dots size point has been customized to 20.0");
XCTAssert(dot.bounds.size.height == sizePoint, @"Dots size point has been customized to 20.0");
XCTAssert([dot.Pointcolor isEqual:[UIColor greenColor]], @"Dots color has been set to green");
XCTAssert(dot.absoluteValue == pointValue, @"Dots are expected to have a value equal to the value returned by the data source method 'valueForPointAtIndex:'");
XCTAssert(dot.alpha >= 0.98 && dot.alpha <= 1.0, @"Dots are expected to always be displayed (alpha of 0.7)");
XCTAssert([dot.backgroundColor isEqual:[UIColor clearColor]], @"Dots are expected to have a clearColor background color by default");
}
}
- (void)testXAxisCustomization {
UIFont *font = [UIFont systemFontOfSize:25.0];
self.lineGraph.labelFont = font;
self.lineGraph.colorXaxisLabel = [UIColor greenColor];
[self.lineGraph reloadGraph];
NSArray *labels = [self.lineGraph graphLabelsForXAxis];
XCTAssert(labels.count == numberOfPoints, @"The number of X-Axis labels should be the same as the number of points on the graph");
for (UILabel *XAxisLabel in labels) {
XCTAssert([XAxisLabel isMemberOfClass:[UILabel class]], @"The array returned by 'graphLabelsForXAxis' should only return UILabels");
XCTAssert([XAxisLabel.text isEqualToString:xAxisLabelString], @"The X-Axis label's strings should be the same as the one returned by the data source method 'labelOnXAxisForIndex:'");
XCTAssert([XAxisLabel.backgroundColor isEqual:[UIColor clearColor]], @"X-Axis labels are expected to have a clear beackground color by default");
XCTAssert(XAxisLabel.textAlignment == NSTextAlignmentCenter, @"X-Axis labels are expected to have their text centered by default");
XCTAssert(XAxisLabel.tag == DotLastTag1000, @"X-Axis labels are expected to have a certain tag by default");
XCTAssert(XAxisLabel.font == font, @"X-Axis label's font is expected to be the customized one");
XCTAssert(XAxisLabel.textColor = [UIColor greenColor], @"X-Axis label's text color is expected to tbe the customized one");
}
}
- (void)testPopUps {
self.lineGraph.alwaysDisplayPopUpLabels = YES;
self.lineGraph.colorBackgroundPopUplabel = [UIColor greenColor];
UIFont *font = [UIFont systemFontOfSize:25.0];
self.lineGraph.labelFont = font;
[self.lineGraph reloadGraph];
NSMutableArray *popUps = [NSMutableArray new];
for (BEMPermanentPopupView *popUp in self.lineGraph.subviews) {
if ([popUp isKindOfClass:[BEMPermanentPopupView class]] && popUp.tag == PermanentPopUpViewTag3100) {
[popUps addObject:popUp];
}
}
XCTAssert(popUps.count == numberOfPoints, @"We should have a popup above each and every dot");
for (BEMPermanentPopupView *popUp in popUps) {
XCTAssert(popUp.backgroundColor == [UIColor greenColor], @"The popups backgorunf color should be the one set by the property");
XCTAssert(popUp.alpha >= 0.69 && popUp.alpha <= 0.71, @"The popups should always be displayed and have an alpha of 0.7");
}
NSMutableArray *popUpsLabels = [NSMutableArray new];
for (UILabel *label in self.lineGraph.subviews) {
if ([label isKindOfClass:[BEMPermanentPopupLabel class]]) {
[popUpsLabels addObject:label];
}
}
XCTAssert(popUpsLabels.count == numberOfPoints, @"We should have a popup above each and every dot");
NSString *expectedLabelText = [NSString stringWithFormat:@"%@%.f%@", popUpPrefix,pointValue,popUpSuffix];
for (BEMPermanentPopupLabel *label in popUpsLabels) {
XCTAssert([label.text isEqualToString:expectedLabelText], @"The popup labels should display the value of the dot and the suffix and prefix returned by the delegate");
XCTAssert(label.font == font, @"The popup label's font is expected to be the customized one");
XCTAssert(label.backgroundColor == [UIColor clearColor], @"The popup label's backgorund color should always be clear color");
}
}
- (void)tearDown {
self.lineGraph = nil;
[super tearDown];
}
@end