Files
Texture/Tests/ASButtonNodeSnapshotTests.mm
Rahul Malik 540f1344ab Add support for tintColor on ASImageNode and ASButtonNode (#1603)
- Add the ability to specify a tintColor for images / buttons that behave similarly to how they would under UIKit.
- Add flag to control if tint color is applied to ASTextNode to match how
UIKit controls if it is .applied to UILabel.
- Update tests for not-tinting automatic render mode for UIImage.
- Add property on ASTextNode2.
- Add tint color support to ASTextNode2.
2019-08-12 09:14:54 -07:00

84 lines
2.5 KiB
Plaintext

//
// ASButtonNodeSnapshotTests.mm
// Texture
//
// Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import <AsyncDisplayKit/AsyncDisplayKit.h>
#import "ASSnapshotTestCase.h"
@interface ASButtonNodeSnapshotTests : ASSnapshotTestCase
@end
@implementation ASButtonNodeSnapshotTests
- (void)setUp
{
[super setUp];
self.recordMode = NO;
}
- (UIImage *)testImage
{
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"logo-square"
ofType:@"png"
inDirectory:@"TestResources"];
return [[UIImage imageWithContentsOfFile:path] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}
- (void)testTintColor
{
ASButtonNode *node = [[ASButtonNode alloc] init];
node.tintColor = UIColor.redColor;
[node setImage:[self testImage] forState:UIControlStateNormal];
[node setTitle:@"Press Me"
withFont:[UIFont systemFontOfSize:48]
withColor:nil
forState:UIControlStateNormal];
node.imageNode.style.width = ASDimensionMake(200);
node.imageNode.style.height = ASDimensionMake(200);
ASDisplayNodeSizeToFitSize(node, CGSizeMake(1000, 1000));
ASSnapshotVerifyNode(node, nil);
}
- (void)testChangingTintColor
{
ASButtonNode *node = [[ASButtonNode alloc] init];
node.tintColor = UIColor.redColor;
[node setImage:[self testImage] forState:UIControlStateNormal];
[node setTitle:@"Press Me"
withFont:[UIFont systemFontOfSize:48]
withColor:nil
forState:UIControlStateNormal];
node.imageNode.style.width = ASDimensionMake(200);
node.imageNode.style.height = ASDimensionMake(200);
ASDisplayNodeSizeToFitSize(node, CGSizeMake(1000, 1000));
ASSnapshotVerifyNode(node, nil);
node.tintColor = UIColor.blueColor;
ASSnapshotVerifyNode(node, @"modified_tint");
}
- (void)testTintColorWithForegroundColorSet
{
ASButtonNode *node = [[ASButtonNode alloc] init];
node.tintColor = UIColor.redColor;
[node setImage:[self testImage] forState:UIControlStateNormal];
[node setTitle:@"Press Me"
withFont:[UIFont systemFontOfSize:48]
withColor:[UIColor blueColor]
forState:UIControlStateNormal];
node.imageNode.style.width = ASDimensionMake(200);
node.imageNode.style.height = ASDimensionMake(200);
ASDisplayNodeSizeToFitSize(node, CGSizeMake(1000, 1000));
ASSnapshotVerifyNode(node, nil);
}
@end