Skip to content
Permalink
Browse files

[Banner] Add snapshot tests for setting preferredFont with adjustsFon…

…tForContentSizeCategory (#8623)

This PR adds 2 snapshot tests to verify the behavior for setting preferredFont on the Banner's text elements when adjustsFontForContentSizeCategory is set to YES.

Closes #8626
  • Loading branch information
yarneo committed Oct 24, 2019
1 parent 6123da4 commit dc66b7fe8764a7da914a7d33616b5546fdf67594
@@ -62,6 +62,7 @@ mdc_snapshot_objc_library(
name = "snapshot_test_lib",
deps = [
":Banner",
":Theming",
"//components/Buttons",
"//components/schemes/Typography",
],
@@ -14,7 +14,8 @@

#import "MaterialSnapshot.h"

#import "MDCBannerView.h"
#import "MaterialBanner+Theming.h"
#import "MaterialBanner.h"
#import "MaterialButtons.h"
#import "MaterialTypographyScheme.h"

@@ -437,4 +438,62 @@ - (void)testDynamicTypeForAttributedTextStringWhenContentSizeCategoryIsExtraExtr
}
}

- (void)testPreferredFontForAXXLContentSizeCategory {
if (@available(iOS 11.0, *)) {
// Given
self.bannerView = [[MDCBannerView alloc] init];
[self.bannerView applyThemeWithScheme:[[MDCContainerScheme alloc] init]];
self.bannerView.textView.text = kBannerLongText;
MDCButton *button1 = self.bannerView.leadingButton;
[button1 setTitle:@"Action1" forState:UIControlStateNormal];
button1.enableTitleFontForState = NO;
MDCButton *button2 = self.bannerView.trailingButton;
[button2 setTitle:@"Action2" forState:UIControlStateNormal];
button2.enableTitleFontForState = NO;

// When
UIFontMetrics *bodyMetrics = [UIFontMetrics metricsForTextStyle:UIFontTextStyleBody];
UIFont *font = [bodyMetrics scaledFontForFont:[UIFont fontWithName:@"Zapfino" size:20]];
self.bannerView.textView.font = font;
self.bannerView.leadingButton.titleLabel.font = font;
self.bannerView.trailingButton.titleLabel.font = font;
self.bannerView.textView.adjustsFontForContentSizeCategory = YES;
self.bannerView.leadingButton.titleLabel.adjustsFontForContentSizeCategory = YES;
self.bannerView.trailingButton.titleLabel.adjustsFontForContentSizeCategory = YES;

// Then
[self generateSnapshotWithContentSizeCategoryAndNotificationPost:
UIContentSizeCategoryExtraExtraLarge
andVerifyForView:self.bannerView];
}
}

- (void)testPreferredFontForAXSContentSizeCategory {
if (@available(iOS 11.0, *)) {
// Given
self.bannerView = [[MDCBannerView alloc] init];
[self.bannerView applyThemeWithScheme:[[MDCContainerScheme alloc] init]];
self.bannerView.textView.text = kBannerLongText;
MDCButton *button1 = self.bannerView.leadingButton;
[button1 setTitle:@"Action1" forState:UIControlStateNormal];
button1.enableTitleFontForState = NO;
MDCButton *button2 = self.bannerView.trailingButton;
[button2 setTitle:@"Action2" forState:UIControlStateNormal];
button2.enableTitleFontForState = NO;

// When
UIFontMetrics *bodyMetrics = [UIFontMetrics metricsForTextStyle:UIFontTextStyleBody];
UIFont *font = [bodyMetrics scaledFontForFont:[UIFont fontWithName:@"Zapfino" size:20]];
self.bannerView.textView.font = font;
self.bannerView.leadingButton.titleLabel.font = font;
self.bannerView.trailingButton.titleLabel.font = font;
self.bannerView.textView.adjustsFontForContentSizeCategory = YES;
self.bannerView.leadingButton.titleLabel.adjustsFontForContentSizeCategory = YES;
self.bannerView.trailingButton.titleLabel.adjustsFontForContentSizeCategory = YES;

// Then
[self generateSnapshotWithContentSizeCategoryAndNotificationPost:UIContentSizeCategoryExtraSmall
andVerifyForView:self.bannerView];
}
}
@end

0 comments on commit dc66b7f

Please sign in to comment.
You can’t perform that action at this time.