Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ASTextNode2 snapshot test #935

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
929d118
fix SIMULATE_WEB_RESPONSE not imported #449
wsdwsd0829 Jul 16, 2017
dd24d8f
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Sep 6, 2017
b8eaffa
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Oct 4, 2017
2918ea0
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Oct 11, 2017
9c42266
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Oct 12, 2017
329f35f
Fix to make rangeMode update in right time
wsdwsd0829 Feb 5, 2018
5f8b7ec
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Feb 7, 2018
d87bb11
merge master from upstream
wsdwsd0829 Feb 15, 2018
269c2ab
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Mar 10, 2018
24c1ce8
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Mar 12, 2018
233169e
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Mar 26, 2018
b19f90d
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Mar 28, 2018
b50cec4
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Apr 5, 2018
b75a5f3
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 May 3, 2018
64b46e0
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 May 16, 2018
5fabc1e
remove uncessary assert
wsdwsd0829 May 17, 2018
3d5b84b
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 May 21, 2018
9c2746d
textnode2-snapshot-test
wsdwsd0829 May 23, 2018
8415a65
add change log
wsdwsd0829 May 23, 2018
88416e7
fix image recording
wsdwsd0829 May 23, 2018
34d0be8
disable recording
wsdwsd0829 May 23, 2018
8b140ea
renaming test method
wsdwsd0829 May 29, 2018
a8dc634
reset experiment in teardown
wsdwsd0829 May 30, 2018
ce0d636
Merge branch 'master' into ASTextNode2-snapshot-test
wsdwsd0829 May 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions AsyncDisplayKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -816,6 +817,7 @@
BB5FC3CD1F9BA688007F191E /* ASNavigationControllerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ASNavigationControllerTests.m; sourceTree = "<group>"; };
BB5FC3D01F9C9389007F191E /* ASTabBarControllerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ASTabBarControllerTests.m; sourceTree = "<group>"; };
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 = "<group>"; };
C057D9BC20B5453D00FC9112 /* ASTextNode2SnapshotTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ASTextNode2SnapshotTests.m; sourceTree = "<group>"; };
CC034A071E60BEB400626263 /* ASDisplayNode+Convenience.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ASDisplayNode+Convenience.h"; sourceTree = "<group>"; };
CC034A081E60BEB400626263 /* ASDisplayNode+Convenience.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "ASDisplayNode+Convenience.m"; sourceTree = "<group>"; };
CC034A111E649F1300626263 /* AsyncDisplayKit+IGListKitMethods.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AsyncDisplayKit+IGListKitMethods.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## master
* Add your own contributions to the next release on the line below this with your name.

- 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).
Expand Down
150 changes: 150 additions & 0 deletions Tests/ASTextNode2SnapshotTests.m
Original file line number Diff line number Diff line change
@@ -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 <AsyncDisplayKit/AsyncDisplayKit.h>

@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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.