material-components_materia.../components/Dialogs/tests/unit/MDCAlertControllerRippleTests.m
Yarden Eitan 90938fe59f
[Dialogs] Adds the Ripple behavior to Dialogs. (#7595)
## Related links
* Bug: Closes #7379 
* Ripple: [Ripple](https://github.com/material-components/material-components-ios/tree/develop/components/Ripple)

## Introduction
This PR allows enabling the Ripple Behavior for [`MDCAlertController and MDCAlertControllerView`](https://github.com/material-components/material-components-ios/tree/develop/components/Dialogs) by enabling the ripple behavior of the internal `MDCButton`. This behavior is an opt in flag property added to MDCAlertController, `enableRippleBehavior`.  This improves the visual touch feedback for our users as MDCInkView didn't support our current motion guidelines.

## Videos
| Before | After |
| - | - |
|![oldRipple](https://user-images.githubusercontent.com/4066863/59470021-81c9a500-8e04-11e9-8071-cdc2d3a81ceb.gif)|![newRipple](https://user-images.githubusercontent.com/4066863/59470027-85f5c280-8e04-11e9-834b-a180c8805e40.gif)|
2019-06-15 12:47:00 -04:00

81 lines
2.4 KiB
Objective-C

// Copyright 2019-present the Material Components for iOS authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <XCTest/XCTest.h>
#import "MaterialDialogs.h"
#import "MDCAlertControllerView+Private.h"
#pragma mark - Subclasses for testing
@interface MDCAlertController (Testing)
@property(nonatomic, nullable, weak) MDCAlertControllerView *alertView;
@end
#pragma mark - Tests
@interface MDCAlertControllerRippleTests : XCTestCase
@property(nonatomic, nullable) MDCAlertController *alert;
@end
@implementation MDCAlertControllerRippleTests
- (void)setUp {
[super setUp];
self.alert = [MDCAlertController alertControllerWithTitle:@"title" message:@"message"];
[self.alert addAction:[MDCAlertAction actionWithTitle:@"action1" handler:nil]];
[self.alert addAction:[MDCAlertAction actionWithTitle:@"action2" handler:nil]];
}
- (void)tearDown {
self.alert = nil;
[super tearDown];
}
/**
Test to confirm behavior of initializing a @c MDCAlerController without any customization.
*/
- (void)testRippleIsDisabledForButtons {
// Then
MDCAlertControllerView *view = (MDCAlertControllerView *)self.alert.view;
XCTAssertFalse(self.alert.enableRippleBehavior);
XCTAssertFalse(view.enableRippleBehavior);
NSArray<MDCButton *> *buttons = view.actionManager.buttonsInActionOrder;
for (MDCButton *button in buttons) {
XCTAssertFalse(button.enableRippleBehavior);
}
}
/**
Test to confirm behavior of initializing a @c MDCAlerController with Ripple enabled.
*/
- (void)testRippleIsEnabledForButtonsWhenRippleBehaviorIsEnabled {
// When
self.alert.enableRippleBehavior = YES;
// Then
MDCAlertControllerView *view = (MDCAlertControllerView *)self.alert.view;
XCTAssertTrue(self.alert.enableRippleBehavior);
XCTAssertTrue(view.enableRippleBehavior);
NSArray<MDCButton *> *buttons = view.actionManager.buttonsInActionOrder;
for (MDCButton *button in buttons) {
XCTAssertTrue(button.enableRippleBehavior);
}
}
@end