From 6ec85ffb6d881ee1fe394ada75e0f46fc82751b1 Mon Sep 17 00:00:00 2001 From: Galia Kaufman Date: Sun, 15 Mar 2020 12:11:43 -0400 Subject: [PATCH] [Dialogs] Add a snapshot test for extea long buttons (#9897) # Description Adding a snapshot test to demonstrate the truncation of extra long buttons (buttons that are longer than the title). This issue is fixed in PR #9878. ![image](https://user-images.githubusercontent.com/2329102/76674303-3a836700-6584-11ea-87f7-040fcf12bc82.png) ## Issues Closes #8434 b/137070719, cl/299735845 --- .../snapshot/MDCAlertControllerActionsTests.m | 29 +++++++++++++++---- ...orizontallyForExtraLongButtons_11_2@2x.png | 3 ++ 2 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 snapshot_test_goldens/goldens_64/MDCAlertControllerActionsTests/testActionsLayoutHorizontallyForExtraLongButtons_11_2@2x.png diff --git a/components/Dialogs/tests/snapshot/MDCAlertControllerActionsTests.m b/components/Dialogs/tests/snapshot/MDCAlertControllerActionsTests.m index 1d5155b68d7..ec488e8be78 100644 --- a/components/Dialogs/tests/snapshot/MDCAlertControllerActionsTests.m +++ b/components/Dialogs/tests/snapshot/MDCAlertControllerActionsTests.m @@ -65,6 +65,14 @@ - (void)tearDown { [super tearDown]; } +- (void)sizeTofitContent { + // Ensure snapshot view size matches actual runtime size of alert + MDCAlertControllerView *alertView = (MDCAlertControllerView *)self.alertController.view; + CGSize preferredContentSize = self.alertController.preferredContentSize; + CGSize bounds = [alertView calculatePreferredContentSizeForBounds:preferredContentSize]; + self.alertController.view.bounds = CGRectMake(0.f, 0.f, bounds.width, bounds.height); +} + - (void)generateSnapshotAndVerifyForView:(UIView *)view { [view layoutIfNeeded]; @@ -221,11 +229,22 @@ - (void)testActionsLayoutHorizontallyForCatpitalizedButtonCase { } // Then - // Ensure snapshot view size matches actual runtime size of alert - CGSize preferredContentSize = self.alertController.preferredContentSize; - MDCAlertControllerView *alertView = (MDCAlertControllerView *)self.alertController.view; - CGSize bounds = [alertView calculatePreferredContentSizeForBounds:preferredContentSize]; - self.alertController.view.bounds = CGRectMake(0.f, 0.f, bounds.width, bounds.height); + [self sizeTofitContent]; + [self generateSnapshotAndVerifyForView:self.alertController.view]; +} + +- (void)testActionsLayoutHorizontallyForExtraLongButtons { + // Given + self.alertController.title = @"Recurring actions"; + self.alertController.message = nil; + [self addLowEmphasisAction:@"This and all following events"]; + [self addLowEmphasisAction:@"This and all following events"]; + + // When + [self.alertController applyThemeWithScheme:self.containerScheme2019]; + + // Then + [self sizeTofitContent]; [self generateSnapshotAndVerifyForView:self.alertController.view]; } diff --git a/snapshot_test_goldens/goldens_64/MDCAlertControllerActionsTests/testActionsLayoutHorizontallyForExtraLongButtons_11_2@2x.png b/snapshot_test_goldens/goldens_64/MDCAlertControllerActionsTests/testActionsLayoutHorizontallyForExtraLongButtons_11_2@2x.png new file mode 100644 index 00000000000..b05427c25c4 --- /dev/null +++ b/snapshot_test_goldens/goldens_64/MDCAlertControllerActionsTests/testActionsLayoutHorizontallyForExtraLongButtons_11_2@2x.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e491b6ce672b2d700ca0a4d6528921032763d4f0598707ab8b509dcf80af9cc7 +size 21393