Skip to content

Commit

Permalink
[Dialogs] Using the new Testing target in accessory snapshots.
Browse files Browse the repository at this point in the history
A followup for cl/305814799 - replacing calls to all private APIs in MDCAlertControllerAccessoryTests.m with the new testing utilities in MDCAlertController+Testing.h

PiperOrigin-RevId: 305878401
  • Loading branch information
galiak11 authored and Jeff Verkoeyen committed Apr 13, 2020
1 parent 5a2b2ca commit f7d799a
Showing 1 changed file with 4 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#import "MaterialSnapshot.h"

#import "MaterialDialogs.h"
#import "MDCAlertController+Testing.h"
#import "MaterialDialogs+Theming.h"
#import "MDCAlertControllerView+Private.h"
#import "MaterialTextFields.h"
#import "MaterialContainerScheme.h"

Expand All @@ -41,8 +41,6 @@ - (void)setUp {
self.alert = [MDCAlertController alertControllerWithTitle:@"Title" message:nil];
[self addOutlinedActionWithTitle:@"OK"];

self.alert.view.bounds = CGRectMake(0.f, 0.f, 300.f, 300.f);

self.containerScheme = [[MDCContainerScheme alloc] init];
self.containerScheme.colorScheme =
[[MDCSemanticColorScheme alloc] initWithDefaults:MDCColorSchemeDefaultsMaterial201907];
Expand All @@ -59,26 +57,16 @@ - (void)tearDown {

#pragma mark - Helpers

- (void)sizeAlertToFitContentForAlert:(MDCAlertController *)alert {
// Ensure snapshot view size resembles actual runtime size of the alert. This is the closest
// simulation to how an actual dialog will be sized on a screen. The dialog layouts itself with
// final size when calculatePreferredContentSizeForBounds: is called - after all the dialog
// configuration is complete.
MDCAlertControllerView *alertView = (MDCAlertControllerView *)alert.view;
CGSize bounds = [alertView calculatePreferredContentSizeForBounds:alertView.bounds.size];
alertView.bounds = CGRectMake(0.f, 0.f, bounds.width, bounds.height);
}

- (void)addOutlinedActionWithTitle:(NSString *)actionTitle {
[self.alert addAction:[MDCAlertAction actionWithTitle:actionTitle
emphasis:MDCActionEmphasisMedium
handler:nil]];
}

- (void)generateSizedSnapshotAndVerifyForAlert:(MDCAlertController *)alert {
[self sizeAlertToFitContentForAlert:alert];
[self highlightSectionsForAlert:self.alert];
[self generateSnapshotAndVerifyForView:self.alert.view];
[alert sizeToFitContentInBounds:CGSizeMake(300.0f, 300.0f)];
[alert highlightAlertPanels];
[self generateSnapshotAndVerifyForView:alert.view];
}

- (void)generateSnapshotAndVerifyForView:(UIView *)view {
Expand All @@ -92,15 +80,6 @@ - (void)changeToRTL:(MDCAlertController *)alert {
[self changeViewToRTL:alert.view];
}

- (void)highlightSectionsForAlert:(MDCAlertController *)alert {
MDCAlertControllerView *alertView = (MDCAlertControllerView *)alert.view;
alertView.titleScrollView.backgroundColor = [[UIColor purpleColor] colorWithAlphaComponent:.2f];
alertView.titleLabel.backgroundColor = [[UIColor purpleColor] colorWithAlphaComponent:.2f];
alertView.contentScrollView.backgroundColor = [[UIColor orangeColor] colorWithAlphaComponent:.1f];
alertView.messageLabel.backgroundColor = [[UIColor orangeColor] colorWithAlphaComponent:.2f];
alertView.actionsScrollView.backgroundColor = [[UIColor blueColor] colorWithAlphaComponent:.2f];
}

#pragma mark - Tests

- (void)testAlertHasTextFieldAccessory {
Expand All @@ -117,7 +96,6 @@ - (void)testAlertHasTextFieldAccessory {
}

- (void)testAlertHasCollectionViewAccessory {
// Given
// Given
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
CGRect frame = CGRectMake(0.0f, 0.0f, 320.0f, 160.0f);
Expand Down

0 comments on commit f7d799a

Please sign in to comment.