@@ -14,25 +14,25 @@ @implementation RCTConvert_UIFontTests
1414 XCTAssertEqualObjects (font1, font2); \
1515}
1616
17- - (void )DISABLED_testWeight // task #7118691
17+ - (void )testWeight
1818{
1919 {
20- UIFont *expected = [UIFont fontWithName: @" HelveticaNeue-Bold " size: 14 ];
20+ UIFont *expected = [UIFont systemFontOfSize: 14 weight: UIFontWeightBold ];
2121 UIFont *result = [RCTConvert UIFont: @{@" fontWeight" : @" bold" }];
2222 RCTAssertEqualFonts (expected, result);
2323 }
2424 {
25- UIFont *expected = [UIFont fontWithName: @" HelveticaNeue-Medium " size: 14 ];
25+ UIFont *expected = [UIFont systemFontOfSize: 14 weight: UIFontWeightMedium ];
2626 UIFont *result = [RCTConvert UIFont: @{@" fontWeight" : @" 500" }];
2727 RCTAssertEqualFonts (expected, result);
2828 }
2929 {
30- UIFont *expected = [UIFont fontWithName: @" HelveticaNeue-UltraLight " size: 14 ];
30+ UIFont *expected = [UIFont systemFontOfSize: 14 weight: UIFontWeightUltraLight ];
3131 UIFont *result = [RCTConvert UIFont: @{@" fontWeight" : @" 100" }];
3232 RCTAssertEqualFonts (expected, result);
3333 }
3434 {
35- UIFont *expected = [UIFont fontWithName: @" HelveticaNeue " size: 14 ];
35+ UIFont *expected = [UIFont systemFontOfSize: 14 weight: UIFontWeightRegular ];
3636 UIFont *result = [RCTConvert UIFont: @{@" fontWeight" : @" normal" }];
3737 RCTAssertEqualFonts (expected, result);
3838 }
@@ -41,7 +41,7 @@ - (void)DISABLED_testWeight // task #7118691
4141- (void )testSize
4242{
4343 {
44- UIFont *expected = [UIFont fontWithName: @" HelveticaNeue " size :18.5 ];
44+ UIFont *expected = [UIFont systemFontOfSize :18.5 ];
4545 UIFont *result = [RCTConvert UIFont: @{@" fontSize" : @18.5 }];
4646 RCTAssertEqualFonts (expected, result);
4747 }
@@ -69,32 +69,47 @@ - (void)testFamily
6969- (void )testStyle
7070{
7171 {
72- UIFont *expected = [UIFont fontWithName: @" HelveticaNeue-Italic" size: 14 ];
72+ UIFont *font = [UIFont systemFontOfSize: 14 ];
73+ UIFontDescriptor *fontDescriptor = [font fontDescriptor ];
74+ UIFontDescriptorSymbolicTraits symbolicTraits = fontDescriptor.symbolicTraits ;
75+ symbolicTraits |= UIFontDescriptorTraitItalic;
76+ fontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits: symbolicTraits];
77+ UIFont *expected = [UIFont fontWithDescriptor: fontDescriptor size: 14 ];
7378 UIFont *result = [RCTConvert UIFont: @{@" fontStyle" : @" italic" }];
7479 RCTAssertEqualFonts (expected, result);
7580 }
7681 {
77- UIFont *expected = [UIFont fontWithName: @" HelveticaNeue " size :14 ];
82+ UIFont *expected = [UIFont systemFontOfSize :14 ];
7883 UIFont *result = [RCTConvert UIFont: @{@" fontStyle" : @" normal" }];
7984 RCTAssertEqualFonts (expected, result);
8085 }
8186}
8287
83- - (void )DISABLED_testStyleAndWeight // task #7118691
88+ - (void )testStyleAndWeight
8489{
8590 {
86- UIFont *expected = [UIFont fontWithName: @" HelveticaNeue-UltraLightItalic" size: 14 ];
91+ UIFont *font = [UIFont systemFontOfSize: 14 weight: UIFontWeightUltraLight];
92+ UIFontDescriptor *fontDescriptor = [font fontDescriptor ];
93+ UIFontDescriptorSymbolicTraits symbolicTraits = fontDescriptor.symbolicTraits ;
94+ symbolicTraits |= UIFontDescriptorTraitItalic;
95+ fontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits: symbolicTraits];
96+ UIFont *expected = [UIFont fontWithDescriptor: fontDescriptor size: 14 ];
8797 UIFont *result = [RCTConvert UIFont: @{@" fontStyle" : @" italic" , @" fontWeight" : @" 100" }];
8898 RCTAssertEqualFonts (expected, result);
8999 }
90100 {
91- UIFont *expected = [UIFont fontWithName: @" HelveticaNeue-BoldItalic" size: 14 ];
101+ UIFont *font = [UIFont systemFontOfSize: 14 weight: UIFontWeightBold];
102+ UIFontDescriptor *fontDescriptor = [font fontDescriptor ];
103+ UIFontDescriptorSymbolicTraits symbolicTraits = fontDescriptor.symbolicTraits ;
104+ symbolicTraits |= UIFontDescriptorTraitItalic;
105+ fontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits: symbolicTraits];
106+ UIFont *expected = [UIFont fontWithDescriptor: fontDescriptor size: 14 ];
92107 UIFont *result = [RCTConvert UIFont: @{@" fontStyle" : @" italic" , @" fontWeight" : @" bold" }];
93108 RCTAssertEqualFonts (expected, result);
94109 }
95110}
96111
97- - (void )DISABLED_testFamilyAndWeight // task #7118691
112+ - (void )testFamilyAndWeight
98113{
99114 {
100115 UIFont *expected = [UIFont fontWithName: @" HelveticaNeue-Bold" size: 14 ];
@@ -111,11 +126,6 @@ - (void)DISABLED_testFamilyAndWeight // task #7118691
111126 UIFont *result = [RCTConvert UIFont: @{@" fontFamily" : @" Cochin" , @" fontWeight" : @" 700" }];
112127 RCTAssertEqualFonts (expected, result);
113128 }
114- {
115- UIFont *expected = [UIFont fontWithName: @" Cochin" size: 14 ];
116- UIFont *result = [RCTConvert UIFont: @{@" fontFamily" : @" Cochin" , @" fontWeight" : @" 500" }]; // regular Cochin is actually medium bold
117- RCTAssertEqualFonts (expected, result);
118- }
119129 {
120130 UIFont *expected = [UIFont fontWithName: @" Cochin" size: 14 ];
121131 UIFont *result = [RCTConvert UIFont: @{@" fontFamily" : @" Cochin" , @" fontWeight" : @" 100" }];
@@ -137,7 +147,7 @@ - (void)testFamilyAndStyle
137147 }
138148}
139149
140- - (void )DISABLED_testFamilyStyleAndWeight // task #7118691
150+ - (void )testFamilyStyleAndWeight
141151{
142152 {
143153 UIFont *expected = [UIFont fontWithName: @" HelveticaNeue-UltraLightItalic" size: 14 ];
@@ -156,4 +166,18 @@ - (void)DISABLED_testFamilyStyleAndWeight // task #7118691
156166 }
157167}
158168
169+ - (void )testInvalidFont
170+ {
171+ {
172+ UIFont *expected = [UIFont systemFontOfSize: 14 ];
173+ UIFont *result = [RCTConvert UIFont: @{@" fontFamily" : @" foobar" }];
174+ RCTAssertEqualFonts (expected, result);
175+ }
176+ {
177+ UIFont *expected = [UIFont boldSystemFontOfSize: 14 ];
178+ UIFont *result = [RCTConvert UIFont: @{@" fontFamily" : @" foobar" , @" fontWeight" : @" bold" }];
179+ RCTAssertEqualFonts (expected, result);
180+ }
181+ }
182+
159183@end
0 commit comments