-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add imprecise comparison variants to iOSSnapshotTestCase extension
This adds variants of the `SnapshotVerify*(...)` methods that allow for imprecise comparisons, i.e. using the `perPixelTolerance` and `overallTolerance` parameters. ## Why is this necessary? Adding tolerances has been a highly requested feature (see #63) to work around...
- Loading branch information
Showing
15 changed files
with
362 additions
and
25 deletions.
There are no files selected for viewing
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
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,92 @@ | ||
// | ||
// Copyright 2023 Block Inc. | ||
// | ||
// 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 AccessibilitySnapshot; | ||
@import FBSnapshotTestCase; | ||
@import XCTest; | ||
|
||
|
||
@interface ImpreciseObjectiveCTests : FBSnapshotTestCase | ||
|
||
@end | ||
|
||
|
||
@implementation ImpreciseObjectiveCTests | ||
|
||
- (void)setUp; | ||
{ | ||
[super setUp]; | ||
|
||
self.fileNameOptions = FBSnapshotTestCaseFileNameIncludeOptionOS | FBSnapshotTestCaseFileNameIncludeOptionScreenSize | FBSnapshotTestCaseFileNameIncludeOptionScreenScale; | ||
} | ||
|
||
- (void)testSimpleView; | ||
{ | ||
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 50)]; | ||
|
||
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(25, 10, 150, 30)]; | ||
label.text = @"Objective-C Snapshot"; | ||
label.textColor = [UIColor redColor]; | ||
label.font = [UIFont systemFontOfSize:12]; | ||
label.textAlignment = NSTextAlignmentCenter; | ||
[view addSubview:label]; | ||
|
||
SnapshotImpreciseVerifyAccessibility(view, nil, 0, 0); | ||
} | ||
|
||
- (void)testSimpleViewWithIdentifier; | ||
{ | ||
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 50)]; | ||
|
||
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(25, 10, 150, 30)]; | ||
label.text = @"Objective-C Snapshot"; | ||
label.textColor = [UIColor redColor]; | ||
label.font = [UIFont systemFontOfSize:12]; | ||
label.textAlignment = NSTextAlignmentCenter; | ||
[view addSubview:label]; | ||
|
||
SnapshotImpreciseVerifyAccessibility(view, @"identifier", 0, 0); | ||
} | ||
|
||
- (void)testSimpleViewWithActivationPointAlways; | ||
{ | ||
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 50)]; | ||
|
||
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(25, 10, 150, 30)]; | ||
label.text = @"Objective-C Snapshot"; | ||
label.textColor = [UIColor redColor]; | ||
label.font = [UIFont systemFontOfSize:12]; | ||
label.textAlignment = NSTextAlignmentCenter; | ||
[view addSubview:label]; | ||
|
||
SnapshotImpreciseVerifyAccessibilityWithOptions(view, nil, YES, YES, 0, 0); | ||
} | ||
|
||
- (void)testViewWithInvertedColors; | ||
{ | ||
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; | ||
[view setBackgroundColor:[UIColor redColor]]; | ||
|
||
UIView *subview = [[UIView alloc] initWithFrame:CGRectMake(25, 25, 50, 50)]; | ||
[subview setBackgroundColor:[UIColor greenColor]]; | ||
|
||
[subview setAccessibilityIgnoresInvertColors:YES]; | ||
[view addSubview:subview]; | ||
|
||
SnapshotImpreciseVerifyWithInvertedColors(view, nil, 0, 0); | ||
} | ||
|
||
@end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
63 changes: 63 additions & 0 deletions
63
...litySnapshot/iOSSnapshotTestCase/ObjC/include/FBSnapshotTestCase_ImpreciseAccessibility.h
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,63 @@ | ||
// | ||
// Copyright 2023 Block Inc. | ||
// | ||
// 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. | ||
// | ||
|
||
#define SnapshotImpreciseVerifyAccessibility(view__, identifier__, perPixelTolerance__, overallTolerance__)\ | ||
{\ | ||
_Pragma("clang diagnostic push")\ | ||
_Pragma("clang diagnostic ignored \"-Wundeclared-selector\"")\ | ||
SEL selector = @selector(snapshotVerifyAccessibility:identifier:perPixelTolerance:overallTolerance:);\ | ||
_Pragma("clang diagnostic pop")\ | ||
typedef NSString * (*SnapshotMethod)(id, SEL, UIView *, NSString *, CGFloat, CGFloat);\ | ||
SnapshotMethod snapshotVerifyAccessibility = (SnapshotMethod)[self methodForSelector:selector];\ | ||
NSString *errorDescription = snapshotVerifyAccessibility(self, selector, view__, identifier__ ?: @"", perPixelTolerance__, overallTolerance__);\ | ||
if (errorDescription == nil) {\ | ||
XCTAssertTrue(YES);\ | ||
} else {\ | ||
XCTFail("%@", errorDescription);\ | ||
}\ | ||
} | ||
|
||
#define SnapshotImpreciseVerifyAccessibilityWithOptions(view__, identifier__, showActivationPoints__, useMonochromeSnapshot__, perPixelTolerance__, overallTolerance__)\ | ||
{\ | ||
_Pragma("clang diagnostic push")\ | ||
_Pragma("clang diagnostic ignored \"-Wundeclared-selector\"")\ | ||
SEL selector = @selector(snapshotVerifyAccessibility:identifier:showActivationPoints:useMonochromeSnapshot:perPixelTolerance:overallTolerance:);\ | ||
_Pragma("clang diagnostic pop")\ | ||
typedef NSString * (*SnapshotMethod)(id, SEL, UIView *, NSString *, BOOL, BOOL, CGFloat, CGFloat);\ | ||
SnapshotMethod snapshotVerifyAccessibility = (SnapshotMethod)[self methodForSelector:selector];\ | ||
NSString *errorDescription = snapshotVerifyAccessibility(self, selector, view__, identifier__ ?: @"", showActivationPoints__, useMonochromeSnapshot__, perPixelTolerance__, overallTolerance__);\ | ||
if (errorDescription == nil) {\ | ||
XCTAssertTrue(YES);\ | ||
} else {\ | ||
XCTFail("%@", errorDescription);\ | ||
}\ | ||
} | ||
|
||
#define SnapshotImpreciseVerifyWithInvertedColors(view__, identifier__, perPixelTolerance__, overallTolerance__)\ | ||
{\ | ||
_Pragma("clang diagnostic push")\ | ||
_Pragma("clang diagnostic ignored \"-Wundeclared-selector\"")\ | ||
SEL selector = @selector(snapshotVerifyWithInvertedColors:identifier:perPixelTolerance:overallTolerance:);\ | ||
_Pragma("clang diagnostic pop")\ | ||
typedef NSString * (*SnapshotMethod)(id, SEL, UIView *, NSString *, CGFloat, CGFloat);\ | ||
SnapshotMethod snapshotVerifyWithInvertedColors = (SnapshotMethod)[self methodForSelector:selector];\ | ||
NSString *errorDescription = snapshotVerifyWithInvertedColors(self, selector, view__, identifier__ ?: @"", perPixelTolerance__, overallTolerance__);\ | ||
if (errorDescription == nil) {\ | ||
XCTAssertTrue(YES);\ | ||
} else {\ | ||
XCTFail("%@", errorDescription);\ | ||
}\ | ||
} |
2 changes: 1 addition & 1 deletion
2
...es/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+Accessibility.swift
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
Oops, something went wrong.