Files
Texture/Tests/ASDisplayNodeSnapshotTests.mm
Andy Finnell e9bd484149 Update to Xcode 15 (#2107)
* Update to Xcode 15

## Summary

We want to make Texture build with recent tools like Xcode 15. Part of this is bumping the minimum supported OS to iOS 14.

I only removed the dead code (i.e. code gated on versions older than iOS 14). There are still some warnings about outdated APIs in use, but they are non-trivial changes to fix.

## Test plan

Run all the examples. Run all the unit tests and make them pass.

* Use Xcode 15.3 so we have 17.4 simulators

* Fixing an asset catalog compiler error when building against iPhone SE

* Fix a couple of file extensions for assets

A couple of PNGs were marked as JPGs
2024-05-21 13:04:39 -04:00

141 lines
4.9 KiB
Plaintext

//
// ASDisplayNodeSnapshotTests.mm
// Texture
//
// Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import "ASSnapshotTestCase.h"
#import <AsyncDisplayKit/AsyncDisplayKit.h>
#import <AsyncDisplayKit/ASDisplayNodeInternal.h>
@interface ASDisplayNodeSnapshotTests : ASSnapshotTestCase
@end
@implementation ASDisplayNodeSnapshotTests
- (void)testBasicHierarchySnapshotTesting
{
ASDisplayNode *node = [[ASDisplayNode alloc] init];
node.backgroundColor = [UIColor blueColor];
ASTextNode *subnode = [[ASTextNode alloc] init];
subnode.backgroundColor = [UIColor whiteColor];
subnode.attributedText = [[NSAttributedString alloc] initWithString:@"Hello"];
node.automaticallyManagesSubnodes = YES;
node.layoutSpecBlock = ^(ASDisplayNode * _Nonnull node, ASSizeRange constrainedSize) {
return [ASInsetLayoutSpec insetLayoutSpecWithInsets:UIEdgeInsetsMake(5, 5, 5, 5) child:subnode];
};
ASDisplayNodeSizeToFitSizeRange(node, ASSizeRangeMake(CGSizeZero, CGSizeMake(INFINITY, INFINITY)));
ASSnapshotVerifyNode(node, nil);
}
NS_INLINE UIImage *BlueImageMake(CGRect bounds)
{
UIGraphicsBeginImageContextWithOptions(bounds.size, YES, 0);
[[UIColor blueColor] setFill];
UIRectFill(bounds);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
- (void)testPrecompositedCornerRounding
{
for (CACornerMask c = 1; c <= kASCACornerAllCorners; c |= (c << 1)) {
auto node = [[ASImageNode alloc] init];
auto bounds = CGRectMake(0, 0, 100, 100);
node.image = BlueImageMake(bounds);
node.frame = bounds;
node.cornerRoundingType = ASCornerRoundingTypePrecomposited;
node.backgroundColor = UIColor.greenColor;
node.maskedCorners = c;
node.cornerRadius = 15;
ASSnapshotVerifyNode(node, ([NSString stringWithFormat:@"%d", (int)c]));
}
}
- (void)testClippingCornerRounding
{
for (CACornerMask c = 1; c <= kASCACornerAllCorners; c |= (c << 1)) {
auto node = [[ASImageNode alloc] init];
auto bounds = CGRectMake(0, 0, 100, 100);
node.image = BlueImageMake(bounds);
node.frame = bounds;
node.cornerRoundingType = ASCornerRoundingTypeClipping;
node.backgroundColor = UIColor.systemBackgroundColor;
node.maskedCorners = c;
node.cornerRadius = 15;
// A layout pass is required, because that's where we lay out the clip layers.
[node.layer layoutIfNeeded];
[[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight] performAsCurrentTraitCollection:^{
ASSnapshotVerifyNode(node, ([NSString stringWithFormat:@"%d_light", (int)c]));
}];
[[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark] performAsCurrentTraitCollection:^{
ASSnapshotVerifyNode(node, ([NSString stringWithFormat:@"%d_dark", (int)c]));
}];
}
}
- (void)testUserInterfaceStyleSnapshotTesting
{
ASDisplayNode *node = [[ASDisplayNode alloc] init];
[node setLayerBacked:YES];
node.backgroundColor = [UIColor systemBackgroundColor];
node.style.preferredSize = CGSizeMake(100, 100);
ASDisplayNodeSizeToFitSizeRange(node, ASSizeRangeMake(CGSizeZero, CGSizeMake(INFINITY, INFINITY)));
[[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight] performAsCurrentTraitCollection:^{
ASSnapshotVerifyNode(node, @"user_interface_style_light");
}];
[[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark] performAsCurrentTraitCollection:^{
ASSnapshotVerifyNode(node, @"user_interface_style_dark");
}];
}
- (void)testBackgroundDynamicColor {
ASDisplayNode *node = [[ASImageNode alloc] init];
node.backgroundColor = [UIColor systemGray6Color];
auto bounds = CGRectMake(0, 0, 100, 100);
node.frame = bounds;
UITraitCollection *tcLight = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight];
[tcLight performAsCurrentTraitCollection: ^{
ASSnapshotVerifyNode(node, @"light");
}];
UITraitCollection *tcDark = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark];
[tcDark performAsCurrentTraitCollection: ^{
ASSnapshotVerifyNode(node, @"dark");
}];
}
- (void)testBackgroundDynamicColorLayerBacked {
ASDisplayNode *node = [[ASImageNode alloc] init];
node.backgroundColor = [UIColor systemGray6Color];
node.layerBacked = YES;
auto bounds = CGRectMake(0, 0, 100, 100);
node.frame = bounds;
UITraitCollection *tcLight = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight];
[tcLight performAsCurrentTraitCollection: ^{
ASSnapshotVerifyNode(node, @"light");
}];
UITraitCollection *tcDark = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark];
[tcDark performAsCurrentTraitCollection: ^{
ASSnapshotVerifyNode(node, @"dark");
}];
}
@end