react-native-navigation的迁移库

RNNFontAttributesCreatorTest.m 3.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #import <XCTest/XCTest.h>
  2. #import "RNNFontAttributesCreator.h"
  3. @interface RNNFontAttributesCreatorTest : XCTestCase
  4. @end
  5. @implementation RNNFontAttributesCreatorTest
  6. - (void)testCreateWithFontFamily_shouldCreateAttributes {
  7. NSString* familyName = @"Helvetica";
  8. NSNumber* fontSize = @(20);
  9. UIColor* fontColor = UIColor.blueColor;
  10. NSDictionary* attributes = [RNNFontAttributesCreator createWithFontFamily:familyName fontSize:fontSize fontWeight:nil color:fontColor];
  11. UIFont* font = attributes[NSFontAttributeName];
  12. XCTAssertEqual(attributes[NSForegroundColorAttributeName], fontColor);
  13. XCTAssertTrue([familyName isEqualToString:font.familyName]);
  14. XCTAssertEqual(font.pointSize, fontSize.floatValue);
  15. }
  16. - (void)testCreateWithFontFamily_shouldIgnoreFontFamilyWhenFontWeightIsNotNil {
  17. NSString* familyName = @"Helvetica";
  18. NSString* fontWeight = @"bold";
  19. NSNumber* fontSize = @(20);
  20. UIColor* fontColor = UIColor.blueColor;
  21. NSDictionary* attributes = [RNNFontAttributesCreator createWithFontFamily:familyName fontSize:fontSize fontWeight:fontWeight color:fontColor];
  22. UIFont* font = attributes[NSFontAttributeName];
  23. XCTAssertEqual(attributes[NSForegroundColorAttributeName], fontColor);
  24. XCTAssertFalse([familyName isEqualToString:font.familyName]);
  25. XCTAssertEqual(font.pointSize, fontSize.floatValue);
  26. }
  27. - (void)testCreateWithFontFamilyWithDefault_shouldCreateDefaultAttributes {
  28. NSString* familyName = @"Helvetica";
  29. NSNumber* defaultFontSize = @(20);
  30. UIColor* defaultFontColor = UIColor.blueColor;
  31. NSDictionary* attributes = [RNNFontAttributesCreator createWithFontFamily:familyName fontSize:nil defaultFontSize:defaultFontSize fontWeight:nil color:nil defaultColor:defaultFontColor];
  32. UIFont* font = attributes[NSFontAttributeName];
  33. XCTAssertEqual(attributes[NSForegroundColorAttributeName], defaultFontColor);
  34. XCTAssertTrue([familyName isEqualToString:font.familyName]);
  35. XCTAssertEqual(font.pointSize, defaultFontSize.floatValue);
  36. }
  37. - (void)testCreateWithDictionary_shouldCreateAttributes {
  38. NSString* familyName = @"Helvetica";
  39. NSNumber* fontSize = @(20);
  40. UIColor* fontColor = UIColor.blueColor;
  41. NSDictionary* attributes = [RNNFontAttributesCreator createWithDictionary:@{} fontFamily:familyName fontSize:fontSize defaultFontSize:nil fontWeight:nil color:fontColor defaultColor:nil];
  42. UIFont* font = attributes[NSFontAttributeName];
  43. XCTAssertEqual(attributes[NSForegroundColorAttributeName], fontColor);
  44. XCTAssertTrue([familyName isEqualToString:font.familyName]);
  45. XCTAssertEqual(font.pointSize, fontSize.floatValue);
  46. }
  47. - (void)testCreateWithDictionary_shouldMergeWithDictionary {
  48. NSString* familyName = @"Helvetica";
  49. NSNumber* fontSize = @(20);
  50. NSDictionary* dictionary = @{NSForegroundColorAttributeName: UIColor.redColor};
  51. NSDictionary* attributes = [RNNFontAttributesCreator createWithDictionary:dictionary fontFamily:familyName fontSize:fontSize defaultFontSize:nil fontWeight:nil color:nil defaultColor:nil];
  52. UIFont* font = attributes[NSFontAttributeName];
  53. XCTAssertEqual(attributes[NSForegroundColorAttributeName], UIColor.redColor);
  54. XCTAssertTrue([familyName isEqualToString:font.familyName]);
  55. XCTAssertEqual(font.pointSize, fontSize.floatValue);
  56. }
  57. - (void)testCreateWithFontFamily_shouldCreateSystemFontWhenOnlySizeAvailable {
  58. NSNumber* fontSize = @(20);
  59. NSDictionary* attributes = [RNNFontAttributesCreator createWithFontFamily:nil fontSize:fontSize fontWeight:nil color:nil];
  60. UIFont* font = attributes[NSFontAttributeName];
  61. NSString* systemFontFamilyName = [[UIFont systemFontOfSize:20] familyName];
  62. XCTAssertEqual(font.pointSize, fontSize.floatValue);
  63. XCTAssertTrue([font.familyName isEqualToString:systemFontFamilyName]);
  64. }
  65. @end