mirror of
https://github.com/material-components/material-components-ios.git
synced 2026-02-20 08:27:32 +08:00
Pull request #8959 changed the accessibility behavior of Feature Highlight but did not update the tests. Somehow the last commit in the PR failed CI tests, but the PR itself was marked as passing. This commit updates the unit tests to reflect the latest behavioral expectations for accessibility. Follow-up for #8961
93 lines
3.4 KiB
Objective-C
93 lines
3.4 KiB
Objective-C
// Copyright 2018-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 "MDCFeatureHighlightView+Private.h"
|
|
#import "MaterialFeatureHighlight.h"
|
|
|
|
@interface MDCFeatureHighlightViewController (Testing)
|
|
@property(nonatomic, strong) MDCFeatureHighlightView *view;
|
|
@end
|
|
|
|
@interface FeatureHighlightAccessibilityTests : XCTestCase
|
|
|
|
@end
|
|
|
|
@implementation FeatureHighlightAccessibilityTests
|
|
|
|
- (void)testAccessibilityHintDefaultAfterLoadingView {
|
|
// Given
|
|
UIView *view = [[UIView alloc] init];
|
|
UIView *view2 = [[UIView alloc] init];
|
|
MDCFeatureHighlightViewController *controller =
|
|
[[MDCFeatureHighlightViewController alloc] initWithHighlightedView:view
|
|
andShowView:view2
|
|
completion:nil];
|
|
|
|
// When (cause the view to load)
|
|
[controller loadViewIfNeeded];
|
|
|
|
// Then
|
|
XCTAssertNil(controller.accessibilityHint);
|
|
XCTAssertNil(controller.view.accessibilityHint);
|
|
}
|
|
|
|
- (void)testAccessibilityDismissElementAfterLoadingView {
|
|
// Given
|
|
UIView *view = [[UIView alloc] init];
|
|
UIView *view2 = [[UIView alloc] init];
|
|
MDCFeatureHighlightViewController *controller =
|
|
[[MDCFeatureHighlightViewController alloc] initWithHighlightedView:view
|
|
andShowView:view2
|
|
completion:nil];
|
|
|
|
// When (cause the view to load)
|
|
[controller loadViewIfNeeded];
|
|
|
|
// Then
|
|
id dismissElement = controller.view.accessibilityElements.lastObject;
|
|
if (![dismissElement isKindOfClass:[UIView class]]) {
|
|
XCTFail(@"There must be at least one accessibility element and the last must be a UIView.");
|
|
return;
|
|
}
|
|
UIView *dismissView = (UIView *)dismissElement;
|
|
XCTAssertTrue(dismissView.isAccessibilityElement);
|
|
XCTAssertEqualObjects(dismissView.accessibilityLabel, @"Dismiss");
|
|
XCTAssertNil(dismissView.accessibilityHint);
|
|
}
|
|
|
|
- (void)testSetAccessibilityHint {
|
|
// Given
|
|
NSString *accessibilityHint = @"A great blue ox.";
|
|
UIView *view = [[UIView alloc] init];
|
|
UIView *view2 = [[UIView alloc] init];
|
|
MDCFeatureHighlightViewController *controller =
|
|
[[MDCFeatureHighlightViewController alloc] initWithHighlightedView:view
|
|
andShowView:view2
|
|
completion:nil];
|
|
controller.accessibilityHint = accessibilityHint;
|
|
|
|
// Then
|
|
id dismissElement = controller.view.accessibilityElements.lastObject;
|
|
if (![dismissElement isKindOfClass:[UIView class]]) {
|
|
XCTFail(@"There must be at least one accessibility element and the last must be a UIView.");
|
|
return;
|
|
}
|
|
UIView *dismissView = (UIView *)dismissElement;
|
|
XCTAssertEqualObjects(dismissView.accessibilityHint, accessibilityHint);
|
|
}
|
|
|
|
@end
|