react-native-navigation的迁移库

RNNFontAttributesCreatorTest.m 3.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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)testcreateFromDictionary_shouldCreateAttributes {
  38. NSString* familyName = @"Helvetica";
  39. NSNumber* fontSize = @(20);
  40. UIColor* fontColor = UIColor.blueColor;
  41. NSDictionary* attributes = [RNNFontAttributesCreator createFromDictionary:@{} 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)testcreateFromDictionary_shouldMergeWithDictionary {
  48. NSString* familyName = @"Helvetica";
  49. NSNumber* fontSize = @(20);
  50. NSDictionary* dictionary = @{NSForegroundColorAttributeName: UIColor.redColor};
  51. NSDictionary* attributes = [RNNFontAttributesCreator createFromDictionary: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_shouldNotChangeFontFamilyWhenOnlySizeAvailable {
  58. NSNumber* fontSize = @(20);
  59. UIFont* initialFont = [UIFont systemFontOfSize:10 weight:UIFontWeightHeavy];
  60. NSMutableDictionary* initialAttributes = [NSMutableDictionary new];
  61. initialAttributes[NSFontAttributeName] = initialFont;
  62. NSDictionary* attributes = [RNNFontAttributesCreator createFromDictionary:initialAttributes fontFamily:nil fontSize:fontSize defaultFontSize:nil fontWeight:nil color:nil defaultColor:nil];
  63. UIFont* font = attributes[NSFontAttributeName];
  64. XCTAssertEqual(font.pointSize, fontSize.floatValue);
  65. XCTAssertTrue([font.familyName isEqualToString:initialFont.familyName]);
  66. }
  67. @end