forked from material-components/material-components-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TextFields] Add tests for preferredFont APIs. (material-components#8635
) Adds tests to demonstrate that MDCTextField responds as expected to `-[UIFont preferredFontForTextStyle:]` APIs. Closes #8640
- Loading branch information
Robert Moore
authored
Oct 24, 2019
1 parent
dc66b7f
commit bdf183d
Showing
222 changed files
with
1,149 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
.../TextFields/tests/snapshot/MDCTextAreaOutlinedControllerPreferredFontAXXXLSnapshotTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// 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 "supplemental/MDCAbstractTextFieldSnapshotTests.h" | ||
|
||
#import "MaterialTextFields.h" | ||
#import "supplemental/MDCTextFieldSnapshotTestsStrings.h" | ||
#import "supplemental/SnapshotFakeMDCMultilineTextField.h" | ||
|
||
@interface MDCTextAreaOutlinedControllerPreferredFontAXXXLSnapshotTestsFake | ||
: SnapshotFakeMDCMultilineTextField | ||
@property(nonatomic, strong) UITraitCollection *traitCollectionOverride; | ||
@end | ||
|
||
@implementation MDCTextAreaOutlinedControllerPreferredFontAXXXLSnapshotTestsFake | ||
|
||
- (UITraitCollection *)traitCollection { | ||
return self.traitCollectionOverride ?: [super traitCollection]; | ||
} | ||
|
||
@end | ||
|
||
@interface MDCTextAreaOutlinedControllerPreferredFontAXXXLSnapshotTests | ||
: MDCAbstractTextFieldSnapshotTests <MDCTextFieldSnapshotTestCaseHooking> | ||
|
||
@end | ||
|
||
@implementation MDCTextAreaOutlinedControllerPreferredFontAXXXLSnapshotTests | ||
|
||
- (void)setUp { | ||
[super setUp]; | ||
|
||
// Uncomment below to recreate the golden images for all test methods. Add it to a test method to | ||
// update only that golden image. | ||
// self.recordMode = YES; | ||
|
||
// Skip empty tests since this is only testing Dynamic Type. | ||
self.shouldExecuteEmptyTests = NO; | ||
|
||
if (@available(iOS 11.0, *)) { | ||
MDCTextAreaOutlinedControllerPreferredFontAXXXLSnapshotTestsFake *fakeTextField = | ||
[[MDCTextAreaOutlinedControllerPreferredFontAXXXLSnapshotTestsFake alloc] init]; | ||
fakeTextField.traitCollectionOverride = | ||
[UITraitCollection traitCollectionWithPreferredContentSizeCategory: | ||
UIContentSizeCategoryAccessibilityExtraExtraExtraLarge]; | ||
self.textField = fakeTextField; | ||
self.textField.clearButtonMode = UITextFieldViewModeAlways; | ||
|
||
MDCTextInputControllerOutlinedTextArea *controller = | ||
[[MDCTextInputControllerOutlinedTextArea alloc] initWithTextInput:self.textField]; | ||
UIFontMetrics *bodyMetrics = [UIFontMetrics metricsForTextStyle:UIFontTextStyleBody]; | ||
controller.textInputFont = [bodyMetrics scaledFontForFont:[UIFont fontWithName:@"Zapfino" | ||
size:20]]; | ||
controller.inlinePlaceholderFont = | ||
[bodyMetrics scaledFontForFont:[UIFont fontWithName:@"Zapfino" size:20]]; | ||
controller.leadingUnderlineLabelFont = | ||
[bodyMetrics scaledFontForFont:[UIFont fontWithName:@"Zapfino" size:20]]; | ||
controller.trailingUnderlineLabelFont = | ||
[bodyMetrics scaledFontForFont:[UIFont fontWithName:@"Zapfino" size:20]]; | ||
self.textFieldController = controller; | ||
|
||
((id<UIContentSizeCategoryAdjusting>)self.textField).adjustsFontForContentSizeCategory = YES; | ||
} | ||
} | ||
|
||
- (void)willGenerateSnapshotAndVerify { | ||
[self.textField traitCollectionDidChange:nil]; | ||
} | ||
|
||
// NOTE: Additional test methods can be found in MDCAbstractTextFieldSnapshotTests.m | ||
|
||
@end |
82 changes: 82 additions & 0 deletions
82
...nts/TextFields/tests/snapshot/MDCTextAreaOutlinedControllerPreferredFontXSSnapshotTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// 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 "supplemental/MDCAbstractTextFieldSnapshotTests.h" | ||
|
||
#import "MaterialTextFields.h" | ||
#import "supplemental/MDCTextFieldSnapshotTestsStrings.h" | ||
#import "supplemental/SnapshotFakeMDCMultilineTextField.h" | ||
|
||
@interface MDCTextAreaOutlinedControllerPreferredFontXSSnapshotTestsFake | ||
: SnapshotFakeMDCMultilineTextField | ||
@property(nonatomic, strong) UITraitCollection *traitCollectionOverride; | ||
@end | ||
|
||
@implementation MDCTextAreaOutlinedControllerPreferredFontXSSnapshotTestsFake | ||
|
||
- (UITraitCollection *)traitCollection { | ||
return self.traitCollectionOverride ?: [super traitCollection]; | ||
} | ||
|
||
@end | ||
|
||
@interface MDCTextAreaOutlinedControllerPreferredFontXSSnapshotTests | ||
: MDCAbstractTextFieldSnapshotTests <MDCTextFieldSnapshotTestCaseHooking> | ||
|
||
@end | ||
|
||
@implementation MDCTextAreaOutlinedControllerPreferredFontXSSnapshotTests | ||
|
||
- (void)setUp { | ||
[super setUp]; | ||
|
||
// Uncomment below to recreate the golden images for all test methods. Add it to a test method to | ||
// update only that golden image. | ||
// self.recordMode = YES; | ||
|
||
// Skip empty tests since this is only testing Dynamic Type. | ||
self.shouldExecuteEmptyTests = NO; | ||
|
||
if (@available(iOS 11.0, *)) { | ||
MDCTextAreaOutlinedControllerPreferredFontXSSnapshotTestsFake *fakeTextField = | ||
[[MDCTextAreaOutlinedControllerPreferredFontXSSnapshotTestsFake alloc] init]; | ||
fakeTextField.traitCollectionOverride = [UITraitCollection | ||
traitCollectionWithPreferredContentSizeCategory:UIContentSizeCategoryExtraSmall]; | ||
self.textField = fakeTextField; | ||
self.textField.clearButtonMode = UITextFieldViewModeAlways; | ||
|
||
MDCTextInputControllerOutlinedTextArea *controller = | ||
[[MDCTextInputControllerOutlinedTextArea alloc] initWithTextInput:self.textField]; | ||
UIFontMetrics *bodyMetrics = [UIFontMetrics metricsForTextStyle:UIFontTextStyleBody]; | ||
controller.textInputFont = [bodyMetrics scaledFontForFont:[UIFont fontWithName:@"Zapfino" | ||
size:20]]; | ||
controller.inlinePlaceholderFont = | ||
[bodyMetrics scaledFontForFont:[UIFont fontWithName:@"Zapfino" size:20]]; | ||
controller.leadingUnderlineLabelFont = | ||
[bodyMetrics scaledFontForFont:[UIFont fontWithName:@"Zapfino" size:20]]; | ||
controller.trailingUnderlineLabelFont = | ||
[bodyMetrics scaledFontForFont:[UIFont fontWithName:@"Zapfino" size:20]]; | ||
self.textFieldController = controller; | ||
|
||
((id<UIContentSizeCategoryAdjusting>)self.textField).adjustsFontForContentSizeCategory = YES; | ||
} | ||
} | ||
|
||
- (void)willGenerateSnapshotAndVerify { | ||
[self.textField traitCollectionDidChange:nil]; | ||
} | ||
|
||
// NOTE: Additional test methods can be found in MDCAbstractTextFieldSnapshotTests.m | ||
|
||
@end |
82 changes: 82 additions & 0 deletions
82
...s/TextFields/tests/snapshot/MDCTextFieldFilledControllerPreferredFontAXXXLSnapshotTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// 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 "supplemental/MDCAbstractTextFieldSnapshotTests.h" | ||
|
||
#import "MaterialTextFields.h" | ||
#import "supplemental/MDCTextFieldSnapshotTestsStrings.h" | ||
#import "supplemental/SnapshotFakeMDCTextField.h" | ||
|
||
@interface MDCTextFieldFilledControllerPreferredFontXSSnapshotTestsFake : SnapshotFakeMDCTextField | ||
@property(nonatomic, strong) UITraitCollection *traitCollectionOverride; | ||
@end | ||
|
||
@implementation MDCTextFieldFilledControllerPreferredFontXSSnapshotTestsFake | ||
|
||
- (UITraitCollection *)traitCollection { | ||
return self.traitCollectionOverride ?: [super traitCollection]; | ||
} | ||
|
||
@end | ||
|
||
@interface MDCTextFieldFilledControllerPreferredFontXSSnapshotTests | ||
: MDCAbstractTextFieldSnapshotTests <MDCTextFieldSnapshotTestCaseHooking> | ||
|
||
@end | ||
|
||
@implementation MDCTextFieldFilledControllerPreferredFontXSSnapshotTests | ||
|
||
- (void)setUp { | ||
[super setUp]; | ||
|
||
// Uncomment below to recreate the golden images for all test methods. Add it to a test method to | ||
// update only that golden image. | ||
// self.recordMode = YES; | ||
|
||
// Skip empty tests since this is only testing Dynamic Type. | ||
self.shouldExecuteEmptyTests = NO; | ||
|
||
if (@available(iOS 11.0, *)) { | ||
MDCTextFieldFilledControllerPreferredFontXSSnapshotTestsFake *fakeTextField = | ||
[[MDCTextFieldFilledControllerPreferredFontXSSnapshotTestsFake alloc] init]; | ||
fakeTextField.traitCollectionOverride = [UITraitCollection | ||
traitCollectionWithPreferredContentSizeCategory:UIContentSizeCategoryExtraSmall]; | ||
self.textField = fakeTextField; | ||
self.textField.clearButtonMode = UITextFieldViewModeAlways; | ||
|
||
MDCTextInputControllerFilled *controller = | ||
[[MDCTextInputControllerFilled alloc] initWithTextInput:self.textField]; | ||
UIFontMetrics *bodyMetrics = [UIFontMetrics metricsForTextStyle:UIFontTextStyleBody]; | ||
controller.textInputFont = [bodyMetrics scaledFontForFont:[UIFont fontWithName:@"Zapfino" | ||
size:20]]; | ||
controller.inlinePlaceholderFont = | ||
[bodyMetrics scaledFontForFont:[UIFont fontWithName:@"Zapfino" size:20]]; | ||
controller.leadingUnderlineLabelFont = | ||
[bodyMetrics scaledFontForFont:[UIFont fontWithName:@"Zapfino" size:20]]; | ||
controller.trailingUnderlineLabelFont = | ||
[bodyMetrics scaledFontForFont:[UIFont fontWithName:@"Zapfino" size:20]]; | ||
controller.floatingEnabled = YES; | ||
self.textFieldController = controller; | ||
|
||
((id<UIContentSizeCategoryAdjusting>)self.textField).adjustsFontForContentSizeCategory = YES; | ||
} | ||
} | ||
|
||
- (void)willGenerateSnapshotAndVerify { | ||
[self.textField traitCollectionDidChange:nil]; | ||
} | ||
|
||
// NOTE: Additional test methods can be found in MDCAbstractTextFieldSnapshotTests.m | ||
|
||
@end |
90 changes: 90 additions & 0 deletions
90
...ents/TextFields/tests/snapshot/MDCTextFieldFilledControllerPreferredFontXSSnapshotTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// 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 "supplemental/MDCAbstractTextFieldSnapshotTests.h" | ||
|
||
#import "MaterialTextFields.h" | ||
#import "supplemental/MDCTextFieldSnapshotTestsStrings.h" | ||
#import "supplemental/SnapshotFakeMDCTextField.h" | ||
|
||
@interface MDCTextFieldFilledControllerPreferredFontAXXXLSnapshotTestsFake | ||
: SnapshotFakeMDCTextField | ||
@property(nonatomic, strong) UITraitCollection *traitCollectionOverride; | ||
@end | ||
|
||
@implementation MDCTextFieldFilledControllerPreferredFontAXXXLSnapshotTestsFake | ||
|
||
- (UITraitCollection *)traitCollection { | ||
return self.traitCollectionOverride ?: [super traitCollection]; | ||
} | ||
|
||
@end | ||
|
||
@interface MDCTextFieldFilledControllerPreferredFontAXXXLSnapshotTests | ||
: MDCAbstractTextFieldSnapshotTests <MDCTextFieldSnapshotTestCaseHooking> | ||
|
||
@end | ||
|
||
@implementation MDCTextFieldFilledControllerPreferredFontAXXXLSnapshotTests | ||
|
||
- (void)setUp { | ||
[super setUp]; | ||
|
||
// Uncomment below to recreate the golden images for all test methods. Add it to a test method to | ||
// update only that golden image. | ||
// self.recordMode = YES; | ||
|
||
// Skip empty tests since this is only testing Dynamic Type. | ||
self.shouldExecuteEmptyTests = NO; | ||
|
||
if (@available(iOS 11.0, *)) { | ||
MDCTextFieldFilledControllerPreferredFontAXXXLSnapshotTestsFake *fakeTextField = | ||
[[MDCTextFieldFilledControllerPreferredFontAXXXLSnapshotTestsFake alloc] init]; | ||
fakeTextField.traitCollectionOverride = | ||
[UITraitCollection traitCollectionWithPreferredContentSizeCategory: | ||
UIContentSizeCategoryAccessibilityExtraExtraExtraLarge]; | ||
self.textField = fakeTextField; | ||
self.textField.clearButtonMode = UITextFieldViewModeAlways; | ||
|
||
MDCTextInputControllerFilled *controller = | ||
[[MDCTextInputControllerFilled alloc] initWithTextInput:self.textField]; | ||
UIFontMetrics *bodyMetrics = [UIFontMetrics metricsForTextStyle:UIFontTextStyleBody]; | ||
controller.textInputFont = [bodyMetrics scaledFontForFont:[UIFont fontWithName:@"Zapfino" | ||
size:20]]; | ||
controller.inlinePlaceholderFont = | ||
[bodyMetrics scaledFontForFont:[UIFont fontWithName:@"Zapfino" size:20]]; | ||
controller.leadingUnderlineLabelFont = | ||
[bodyMetrics scaledFontForFont:[UIFont fontWithName:@"Zapfino" size:20]]; | ||
controller.trailingUnderlineLabelFont = | ||
[bodyMetrics scaledFontForFont:[UIFont fontWithName:@"Zapfino" size:20]]; | ||
controller.floatingEnabled = YES; | ||
self.textFieldController = controller; | ||
UITextField *textField = [[UITextField alloc] init]; | ||
textField.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; | ||
NSLog(@"%d", textField.adjustsFontForContentSizeCategory); | ||
UILabel *label = [[UILabel alloc] init]; | ||
label.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; | ||
NSLog(@"%d", label.adjustsFontForContentSizeCategory); | ||
|
||
((id<UIContentSizeCategoryAdjusting>)self.textField).adjustsFontForContentSizeCategory = YES; | ||
} | ||
} | ||
|
||
- (void)willGenerateSnapshotAndVerify { | ||
[self.textField traitCollectionDidChange:nil]; | ||
} | ||
|
||
// NOTE: Additional test methods can be found in MDCAbstractTextFieldSnapshotTests.m | ||
|
||
@end |
Oops, something went wrong.