Skip to content

Commit

Permalink
[Dialogs] Add example snapshot tests.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 309275412
  • Loading branch information
Jeff Verkoeyen authored and material-automation committed Apr 30, 2020
1 parent f4b7c8e commit 1920b96
Show file tree
Hide file tree
Showing 13 changed files with 288 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,39 @@ extension DialogsAccessoryExampleViewController {
]
}
}

// MARK: Snapshot Testing by Convention
extension DialogsAccessoryExampleViewController {

func resetTests() {
if presentedViewController != nil {
dismiss(animated: false)
}
}

@objc func testTextView() {
resetTests()
self.present(performTextView(), animated: false, completion: nil)
}

@objc func testTextField() {
resetTests()
self.present(performTextField(), animated: false, completion: nil)
}

@objc func testMDCTextField() {
resetTests()
self.present(performMDCTextField(), animated: false, completion: nil)
}

@objc func testCustomLabelWithButton() {
resetTests()
self.present(performCustomLabelWithButton(), animated: false, completion: nil)
}

@objc func testDefaultLabelWithButton() {
resetTests()
self.present(performDefaultLabelWithButton(), animated: false, completion: nil)
}

}
25 changes: 25 additions & 0 deletions components/Dialogs/examples/DialogsAlertComparisonExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,28 @@ extension DialogsAlertComparisonExample {
]
}
}

// MARK: Snapshot Testing by Convention
extension DialogsAlertComparisonExample {

func resetTests() {
if presentedViewController != nil {
dismiss(animated: false)
}
}

@objc func testMaterial() {
resetTests()
tapMaterial(UIButton())
}

@objc func testThemed() {
resetTests()
tapThemed(UIButton())
}

@objc func testUIKit() {
resetTests()
tapUIKit(UIButton())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,79 @@ extension DialogsAlertCustomizationExampleViewController {
]
}
}

// MARK: Snapshot Testing by Convention
extension DialogsAlertCustomizationExampleViewController {

func resetTests() {
if presentedViewController != nil {
dismiss(animated: false)
}
}

@objc func testCenteredTitle() {
resetTests()
present(performCenteredTitle(), animated: false, completion: nil)
}

@objc func testCenteredTitleWithIcon() {
resetTests()
present(performCenteredTitleWithIcon(), animated: false, completion: nil)
}

@objc func testNaturalTitleWithIcon() {
resetTests()
present(performNaturalTitleWithIcon(), animated: false, completion: nil)
}

@objc func testRightTitleWithResizedIcon() {
resetTests()
present(performRightTitleWithResizedIcon(), animated: false, completion: nil)
}

@objc func testTintedTitleIconNoTitle() {
resetTests()
present(performTintedTitleIconNoTitle(), animated: false, completion: nil)
}

@objc func testScrimColor() {
resetTests()
present(performScrimColor(), animated: false, completion: nil)
}

@objc func testLowElevationAlert() {
resetTests()
present(performLowElevationAlert(), animated: false, completion: nil)
}

@objc func testEmphasisButtonTheming() {
resetTests()
present(performEmphasisButtonTheming(), animated: false, completion: nil)
}

@objc func testDeprecatedTextButtonTheming() {
resetTests()
present(performDeprecatedTextButtonTheming(), animated: false, completion: nil)
}

@objc func testTextButtonThemingTheRightWay() {
resetTests()
present(performTextButtonThemingTheRightWay(), animated: false, completion: nil)
}

@objc func testCustomButtonTheming() {
resetTests()
present(performCustomButtonTheming(), animated: false, completion: nil)
}

@objc func testDarkTheming() {
resetTests()
present(performDarkTheming(), animated: false, completion: nil)
}

@objc func testNoTheming() {
resetTests()
present(performNoTheming(), animated: false, completion: nil)
}

}
20 changes: 20 additions & 0 deletions components/Dialogs/examples/DialogsAlertExampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,23 @@ + (NSDictionary *)catalogMetadata {
}

@end

@implementation DialogsAlertExampleViewController (SnapshotTestingByConvention)

- (NSDictionary<NSString *, void (^)(void)> *)testRunners {
NSMutableDictionary<NSString *, void (^)(void)> *runners = [NSMutableDictionary dictionary];
NSInteger index = 0;
for (NSString *mode in self.modes) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
runners[mode] = ^{
if (self.presentedViewController) {
[self dismissViewControllerAnimated:NO completion:nil];
}
[self collectionView:self.collectionView didSelectItemAtIndexPath:indexPath];
};
index++;
}
return runners;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,18 @@ class DialogsCustomShadowExampleViewController: UIViewController {
]
}
}

// MARK: Snapshot Testing by Convention
extension DialogsCustomShadowExampleViewController {

func resetTests() {
if presentedViewController != nil {
dismiss(animated: false)
}
}

@objc func testPresented() {
resetTests()
tap(UIButton())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,23 @@ - (BOOL)accessibilityPerformEscape {
}

@end

@implementation DialogsDismissingExampleViewController (SnapshotTestingByConvention)

- (NSDictionary<NSString *, void (^)(void)> *)testRunners {
NSMutableDictionary<NSString *, void (^)(void)> *runners = [NSMutableDictionary dictionary];
NSInteger index = 0;
for (NSString *mode in self.modes) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
runners[mode] = ^{
if (self.presentedViewController) {
[self dismissViewControllerAnimated:NO completion:nil];
}
[self collectionView:self.collectionView didSelectItemAtIndexPath:indexPath];
};
index++;
}
return runners;
}

@end
12 changes: 12 additions & 0 deletions components/Dialogs/examples/DialogsKeyboardExampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,15 @@ - (void)collectionView:(UICollectionView *)collectionView
}

@end

@implementation DialogsKeyboardExampleViewController (SnapshotTestingByConvention)

- (void)testPresented {
if (self.presentedViewController) {
[self dismissViewControllerAnimated:NO completion:nil];
}
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self collectionView:self.collectionView didSelectItemAtIndexPath:indexPath];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,18 @@ extension DialogsLongAlertExampleViewController {
]
}
}

// MARK: Snapshot Testing by Convention
extension DialogsLongAlertExampleViewController {

func resetTests() {
if presentedViewController != nil {
dismiss(animated: false)
}
}

@objc func testPresented() {
resetTests()
tap(UIButton())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,21 @@ + (NSDictionary *)catalogMetadata {
}

@end

@implementation DialogsRoundedCornerExampleViewController (SnapshotTestingByConvention)

- (void)testDefault {
if (self.presentedViewController) {
[self dismissViewControllerAnimated:NO completion:nil];
}
[self didTapPresentDefault:nil];
}

- (void)testThemed {
if (self.presentedViewController) {
[self dismissViewControllerAnimated:NO completion:nil];
}
[self didTapPresentThemed:nil];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,14 @@ + (NSDictionary *)catalogMetadata {
}

@end

@implementation DialogsTallTextAlertExampleViewController (SnapshotTestingByConvention)

- (void)testPresented {
if (self.presentedViewController) {
[self dismissViewControllerAnimated:NO completion:nil];
}
[self didTapPresent:nil];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,17 @@ extension DialogsThemedPresentationExampleViewController {
}
}

// MARK: Snapshot Testing by Convention
extension DialogsThemedPresentationExampleViewController {

func resetTests() {
if presentedViewController != nil {
dismiss(animated: false)
}
}

@objc func testPresented() {
resetTests()
tap(UIButton())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,14 @@ + (NSDictionary *)catalogMetadata {
}

@end

@implementation DialogsTypicalUseExampleViewController (SnapshotTestingByConvention)

- (void)testPresented {
if (self.presentedViewController) {
[self dismissViewControllerAnimated:NO completion:nil];
}
[self showAlert:nil];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,18 @@ extension DialogsWithEmphasisButtonExampleViewController {
}
}


// MARK: Snapshot Testing by Convention
extension DialogsWithEmphasisButtonExampleViewController {

func resetTests() {
if presentedViewController != nil {
dismiss(animated: false)
}
}

@objc func testPresented() {
resetTests()
tapMaterial(UIButton())
}
}

0 comments on commit 1920b96

Please sign in to comment.