Skip to content

Commit

Permalink
[Dialogs] Add a snapshot test for extea long buttons (material-compon…
Browse files Browse the repository at this point in the history
…ents#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 material-components#9878.

![image](https://user-images.githubusercontent.com/2329102/76674303-3a836700-6584-11ea-87f7-040fcf12bc82.png)

## Issues
Closes #8434
b/137070719, cl/299735845
  • Loading branch information
galiak11 authored Mar 15, 2020
1 parent 9ea7f0d commit 6ec85ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
29 changes: 24 additions & 5 deletions components/Dialogs/tests/snapshot/MDCAlertControllerActionsTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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];
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6ec85ff

Please sign in to comment.