diff --git a/AsyncDisplayKit.xcodeproj/project.pbxproj b/AsyncDisplayKit.xcodeproj/project.pbxproj index c9f5cba820..e6efd3309b 100644 --- a/AsyncDisplayKit.xcodeproj/project.pbxproj +++ b/AsyncDisplayKit.xcodeproj/project.pbxproj @@ -311,6 +311,7 @@ B350625E1B0111780018CF92 /* AssetsLibrary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 051943121A1575630030A7D0 /* AssetsLibrary.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; BB5FC3CE1F9BA689007F191E /* ASNavigationControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BB5FC3CD1F9BA688007F191E /* ASNavigationControllerTests.m */; }; BB5FC3D11F9C9389007F191E /* ASTabBarControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BB5FC3D01F9C9389007F191E /* ASTabBarControllerTests.m */; }; + C057D9BD20B5453D00FC9112 /* ASTextNode2SnapshotTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C057D9BC20B5453D00FC9112 /* ASTextNode2SnapshotTests.m */; }; C78F7E2B1BF7809800CDEAFC /* ASTableNode.h in Headers */ = {isa = PBXBuildFile; fileRef = B0F880581BEAEC7500D17647 /* ASTableNode.h */; settings = {ATTRIBUTES = (Public, ); }; }; CC034A091E60BEB400626263 /* ASDisplayNode+Convenience.h in Headers */ = {isa = PBXBuildFile; fileRef = CC034A071E60BEB400626263 /* ASDisplayNode+Convenience.h */; settings = {ATTRIBUTES = (Public, ); }; }; CC034A0A1E60BEB400626263 /* ASDisplayNode+Convenience.m in Sources */ = {isa = PBXBuildFile; fileRef = CC034A081E60BEB400626263 /* ASDisplayNode+Convenience.m */; }; @@ -816,6 +817,7 @@ BB5FC3CD1F9BA688007F191E /* ASNavigationControllerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ASNavigationControllerTests.m; sourceTree = ""; }; BB5FC3D01F9C9389007F191E /* ASTabBarControllerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ASTabBarControllerTests.m; sourceTree = ""; }; BDC2D162BD55A807C1475DA5 /* Pods-AsyncDisplayKitTests.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AsyncDisplayKitTests.profile.xcconfig"; path = "Pods/Target Support Files/Pods-AsyncDisplayKitTests/Pods-AsyncDisplayKitTests.profile.xcconfig"; sourceTree = ""; }; + C057D9BC20B5453D00FC9112 /* ASTextNode2SnapshotTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ASTextNode2SnapshotTests.m; sourceTree = ""; }; CC034A071E60BEB400626263 /* ASDisplayNode+Convenience.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ASDisplayNode+Convenience.h"; sourceTree = ""; }; CC034A081E60BEB400626263 /* ASDisplayNode+Convenience.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "ASDisplayNode+Convenience.m"; sourceTree = ""; }; CC034A111E649F1300626263 /* AsyncDisplayKit+IGListKitMethods.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AsyncDisplayKit+IGListKitMethods.h"; sourceTree = ""; }; @@ -1298,6 +1300,7 @@ 4496D0721FA9EA6B001CC8D5 /* ASTraitCollectionTests.m */, CC0AEEA31D66316E005D1C78 /* ASUICollectionViewTests.m */, AEEC47E31C21D3D200EC1693 /* ASVideoNodeTests.m */, + C057D9BC20B5453D00FC9112 /* ASTextNode2SnapshotTests.m */, CCA221D21D6FA7EF00AF6A0F /* ASViewControllerTests.m */, 83A7D95D1D446A6E00BF333E /* ASWeakMapTests.m */, CC3B208D1C3F7D0A00798563 /* ASWeakSetTests.m */, @@ -2279,6 +2282,7 @@ CC0AEEA41D66316E005D1C78 /* ASUICollectionViewTests.m in Sources */, CCE4F9B51F0DA4F300062E4E /* ASLayoutEngineTests.mm in Sources */, 69B225671D72535E00B25B22 /* ASDisplayNodeLayoutTests.mm in Sources */, + C057D9BD20B5453D00FC9112 /* ASTextNode2SnapshotTests.m in Sources */, ACF6ED621B178DC700DA7C62 /* ASRatioLayoutSpecSnapshotTests.mm in Sources */, 7AB338691C55B97B0055FDE8 /* ASRelativeLayoutSpecSnapshotTests.mm in Sources */, CCDD148B1EEDCD9D0020834E /* ASCollectionModernDataSourceTests.m in Sources */, diff --git a/CHANGELOG.md b/CHANGELOG.md index 238a009c5a..76d905564d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ * Add your own contributions to the next release on the line below this with your name. - Make `ASPerformMainThreadDeallocation` visible in C. [Adlai Holler](https://github.com/Adlai-Holler) +- Add snapshot test for astextnode2. [Max Wang](https://github.com/wsdwsd0829) [#935](https://github.com/TextureGroup/Texture/pull/935) + ## 2.7 - Fix pager node for interface coalescing. [Max Wang](https://github.com/wsdwsd0829) [#877](https://github.com/TextureGroup/Texture/pull/877) - [ASTextNode2] Upgrade lock safety by protecting all ivars (including rarely-changed ones). diff --git a/Tests/ASTextNode2SnapshotTests.m b/Tests/ASTextNode2SnapshotTests.m new file mode 100644 index 0000000000..680433e971 --- /dev/null +++ b/Tests/ASTextNode2SnapshotTests.m @@ -0,0 +1,150 @@ +// +// ASTextNode2SnapshotTests.mm +// Texture +// +// Copyright (c) 2017-present, Pinterest, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// + + +#import "ASTestCase.h" +#import "ASSnapshotTestCase.h" +#import + +@interface ASTextNode2SnapshotTests : ASSnapshotTestCase + +@end + +@implementation ASTextNode2SnapshotTests + +- (void)setUp +{ + [super setUp]; + + // This will use ASTextNode2 for snapshot tests. + // All tests are duplicated from ASTextNodeSnapshotTests. + ASConfiguration *config = [[ASConfiguration alloc] initWithDictionary:nil]; + config.experimentalFeatures = ASExperimentalTextNode; + [ASConfigurationManager test_resetWithConfiguration:config]; + + self.recordMode = NO; +} + +- (void)tearDown +{ + [super tearDown]; + ASConfiguration *config = [[ASConfiguration alloc] initWithDictionary:nil]; + config.experimentalFeatures = kNilOptions; + [ASConfigurationManager test_resetWithConfiguration:config]; +} + +- (void)testTextContainerInset_ASTextNode2 +{ + // trivial test case to ensure ASSnapshotTestCase works + ASTextNode *textNode = [[ASTextNode alloc] init]; + textNode.attributedText = [[NSAttributedString alloc] initWithString:@"judar" + attributes:@{NSFontAttributeName : [UIFont italicSystemFontOfSize:24]}]; + textNode.textContainerInset = UIEdgeInsetsMake(0, 2, 0, 2); + ASDisplayNodeSizeToFitSizeRange(textNode, ASSizeRangeMake(CGSizeZero, CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX))); + + ASSnapshotVerifyNode(textNode, nil); +} + +- (void)testTextContainerInsetIsIncludedWithSmallerConstrainedSize_ASTextNode2 +{ + UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectZero]; + backgroundView.layer.as_allowsHighlightDrawing = YES; + + ASTextNode *textNode = [[ASTextNode alloc] init]; + textNode.attributedText = [[NSAttributedString alloc] initWithString:@"judar judar judar judar judar judar" + attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:30] }]; + + textNode.textContainerInset = UIEdgeInsetsMake(10, 10, 10, 10); + + ASLayout *layout = [textNode layoutThatFits:ASSizeRangeMake(CGSizeZero, CGSizeMake(100, 80))]; + textNode.frame = CGRectMake(50, 50, layout.size.width, layout.size.height); + + [backgroundView addSubview:textNode.view]; + backgroundView.frame = UIEdgeInsetsInsetRect(textNode.bounds, UIEdgeInsetsMake(-50, -50, -50, -50)); + + textNode.highlightRange = NSMakeRange(0, textNode.attributedText.length); + + [ASSnapshotTestCase hackilySynchronouslyRecursivelyRenderNode:textNode]; + ASSnapshotVerifyLayer(backgroundView.layer, nil); +} + +- (void)testTextContainerInsetHighlight_ASTextNode2 +{ + UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectZero]; + backgroundView.layer.as_allowsHighlightDrawing = YES; + + ASTextNode *textNode = [[ASTextNode alloc] init]; + textNode.attributedText = [[NSAttributedString alloc] initWithString:@"yolo" + attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:30] }]; + + textNode.textContainerInset = UIEdgeInsetsMake(5, 10, 10, 5); + ASLayout *layout = [textNode layoutThatFits:ASSizeRangeMake(CGSizeZero, CGSizeMake(INFINITY, INFINITY))]; + textNode.frame = CGRectMake(50, 50, layout.size.width, layout.size.height); + + [backgroundView addSubview:textNode.view]; + backgroundView.frame = UIEdgeInsetsInsetRect(textNode.bounds, UIEdgeInsetsMake(-50, -50, -50, -50)); + + textNode.highlightRange = NSMakeRange(0, textNode.attributedText.length); + + [ASSnapshotTestCase hackilySynchronouslyRecursivelyRenderNode:textNode]; + ASSnapshotVerifyView(backgroundView, nil); +} + +// This test is disabled because the fast-path is disabled. +- (void)DISABLED_testThatFastPathTruncationWorks_ASTextNode2 +{ + ASTextNode *textNode = [[ASTextNode alloc] init]; + textNode.attributedText = [[NSAttributedString alloc] initWithString:@"Quality is Important" attributes:@{ NSForegroundColorAttributeName: [UIColor blueColor], NSFontAttributeName: [UIFont italicSystemFontOfSize:24] }]; + [textNode layoutThatFits:ASSizeRangeMake(CGSizeZero, CGSizeMake(100, 50))]; + ASSnapshotVerifyNode(textNode, nil); +} + +- (void)testThatSlowPathTruncationWorks_ASTextNode2 +{ + ASTextNode *textNode = [[ASTextNode alloc] init]; + textNode.attributedText = [[NSAttributedString alloc] initWithString:@"Quality is Important" attributes:@{ NSForegroundColorAttributeName: [UIColor blueColor], NSFontAttributeName: [UIFont italicSystemFontOfSize:24] }]; + // Set exclusion paths to trigger slow path + textNode.exclusionPaths = @[ [UIBezierPath bezierPath] ]; + ASDisplayNodeSizeToFitSizeRange(textNode, ASSizeRangeMake(CGSizeZero, CGSizeMake(100, 50))); + ASSnapshotVerifyNode(textNode, nil); +} + +- (void)testShadowing_ASTextNode2 +{ + ASTextNode *textNode = [[ASTextNode alloc] init]; + textNode.attributedText = [[NSAttributedString alloc] initWithString:@"Quality is Important"]; + textNode.shadowColor = [UIColor blackColor].CGColor; + textNode.shadowOpacity = 0.3; + textNode.shadowRadius = 3; + textNode.shadowOffset = CGSizeMake(0, 1); + ASDisplayNodeSizeToFitSizeRange(textNode, ASSizeRangeMake(CGSizeZero, CGSizeMake(INFINITY, INFINITY))); + ASSnapshotVerifyNode(textNode, nil); +} + +/** + * https://github.com/TextureGroup/Texture/issues/822 + */ +- (void)DISABLED_testThatTruncationTokenAttributesPrecedeThoseInheritedFromTextWhenTruncateTailMode_ASTextNode2 +{ + ASTextNode *textNode = [[ASTextNode alloc] init]; + textNode.style.maxSize = CGSizeMake(20, 80); + NSMutableAttributedString *mas = [[NSMutableAttributedString alloc] initWithString:@"Quality is an important "]; + [mas appendAttributedString:[[NSAttributedString alloc] initWithString:@"thing" attributes:@{ NSBackgroundColorAttributeName : UIColor.yellowColor}]]; + textNode.attributedText = mas; + textNode.truncationMode = NSLineBreakByTruncatingTail; + + textNode.truncationAttributedText = [[NSAttributedString alloc] initWithString:@"\u2026" attributes:@{ NSBackgroundColorAttributeName: UIColor.greenColor }]; + ASDisplayNodeSizeToFitSizeRange(textNode, ASSizeRangeMake(CGSizeZero, CGSizeMake(INFINITY, INFINITY))); + ASSnapshotVerifyNode(textNode, nil); +} + +@end diff --git a/Tests/ReferenceImages_iOS_10/ASTextNode2SnapshotTests/testShadowing_ASTextNode2@2x.png b/Tests/ReferenceImages_iOS_10/ASTextNode2SnapshotTests/testShadowing_ASTextNode2@2x.png new file mode 100644 index 0000000000..7a336db723 Binary files /dev/null and b/Tests/ReferenceImages_iOS_10/ASTextNode2SnapshotTests/testShadowing_ASTextNode2@2x.png differ diff --git a/Tests/ReferenceImages_iOS_10/ASTextNode2SnapshotTests/testTextContainerInsetHighlight_ASTextNode2@2x.png b/Tests/ReferenceImages_iOS_10/ASTextNode2SnapshotTests/testTextContainerInsetHighlight_ASTextNode2@2x.png new file mode 100644 index 0000000000..37dfc5986d Binary files /dev/null and b/Tests/ReferenceImages_iOS_10/ASTextNode2SnapshotTests/testTextContainerInsetHighlight_ASTextNode2@2x.png differ diff --git a/Tests/ReferenceImages_iOS_10/ASTextNode2SnapshotTests/testTextContainerInsetIsIncludedWithSmallerConstrainedSize_ASTextNode2@2x.png b/Tests/ReferenceImages_iOS_10/ASTextNode2SnapshotTests/testTextContainerInsetIsIncludedWithSmallerConstrainedSize_ASTextNode2@2x.png new file mode 100644 index 0000000000..dd3b0ccf4d Binary files /dev/null and b/Tests/ReferenceImages_iOS_10/ASTextNode2SnapshotTests/testTextContainerInsetIsIncludedWithSmallerConstrainedSize_ASTextNode2@2x.png differ diff --git a/Tests/ReferenceImages_iOS_10/ASTextNode2SnapshotTests/testTextContainerInset_ASTextNode2@2x.png b/Tests/ReferenceImages_iOS_10/ASTextNode2SnapshotTests/testTextContainerInset_ASTextNode2@2x.png new file mode 100644 index 0000000000..d66bb3bce9 Binary files /dev/null and b/Tests/ReferenceImages_iOS_10/ASTextNode2SnapshotTests/testTextContainerInset_ASTextNode2@2x.png differ diff --git a/Tests/ReferenceImages_iOS_10/ASTextNode2SnapshotTests/testThatSlowPathTruncationWorks_ASTextNode2@2x.png b/Tests/ReferenceImages_iOS_10/ASTextNode2SnapshotTests/testThatSlowPathTruncationWorks_ASTextNode2@2x.png new file mode 100644 index 0000000000..b8123efd43 Binary files /dev/null and b/Tests/ReferenceImages_iOS_10/ASTextNode2SnapshotTests/testThatSlowPathTruncationWorks_ASTextNode2@2x.png differ diff --git a/Tests/ReferenceImages_iOS_10/ASTextNodeSnapshotTests/testTextContainerInset2@2x.png b/Tests/ReferenceImages_iOS_10/ASTextNodeSnapshotTests/testTextContainerInset2@2x.png new file mode 100644 index 0000000000..d66bb3bce9 Binary files /dev/null and b/Tests/ReferenceImages_iOS_10/ASTextNodeSnapshotTests/testTextContainerInset2@2x.png differ