mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
add ASTextNode2 snapshot test (#935)
* fix SIMULATE_WEB_RESPONSE not imported #449 * Fix to make rangeMode update in right time * remove uncessary assert * textnode2-snapshot-test * add change log * fix image recording * disable recording * renaming test method * reset experiment in teardown
This commit is contained in:
@@ -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 = "<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>"; };
|
||||
@@ -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 */,
|
||||
|
||||
@@ -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).
|
||||
|
||||
150
Tests/ASTextNode2SnapshotTests.m
Normal file
150
Tests/ASTextNode2SnapshotTests.m
Normal file
@@ -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
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
Reference in New Issue
Block a user