-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from cashapp/entin/hit-test-snapshot
Add utilities for highlighting hit test regions
- Loading branch information
Showing
24 changed files
with
790 additions
and
165 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
22 changes: 22 additions & 0 deletions
22
...cbaselines/607FACE41AFB9204008FA782.xcbaseline/EDA548A6-E453-4CBA-9366-15D413356833.plist
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,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>classNames</key> | ||
<dict> | ||
<key>HitTargetTests</key> | ||
<dict> | ||
<key>testPerformance()</key> | ||
<dict> | ||
<key>com.apple.XCTPerformanceMetric_WallClockTime</key> | ||
<dict> | ||
<key>baselineAverage</key> | ||
<real>48.792810</real> | ||
<key>baselineIntegrationDisplayName</key> | ||
<string>Local Baseline</string> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</plist> |
40 changes: 40 additions & 0 deletions
40
...napshot.xcodeproj/xcshareddata/xcbaselines/607FACE41AFB9204008FA782.xcbaseline/Info.plist
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,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>runDestinationsByUUID</key> | ||
<dict> | ||
<key>EDA548A6-E453-4CBA-9366-15D413356833</key> | ||
<dict> | ||
<key>localComputer</key> | ||
<dict> | ||
<key>busSpeedInMHz</key> | ||
<integer>0</integer> | ||
<key>cpuCount</key> | ||
<integer>1</integer> | ||
<key>cpuKind</key> | ||
<string>Apple M1 Max</string> | ||
<key>cpuSpeedInMHz</key> | ||
<integer>0</integer> | ||
<key>logicalCPUCoresPerPackage</key> | ||
<integer>10</integer> | ||
<key>modelCode</key> | ||
<string>MacBookPro18,2</string> | ||
<key>physicalCPUCoresPerPackage</key> | ||
<integer>10</integer> | ||
<key>platformIdentifier</key> | ||
<string>com.apple.platform.macosx</string> | ||
</dict> | ||
<key>targetArchitecture</key> | ||
<string>arm64</string> | ||
<key>targetDevice</key> | ||
<dict> | ||
<key>modelCode</key> | ||
<string>iPhone13,3</string> | ||
<key>platformIdentifier</key> | ||
<string>com.apple.platform.iphonesimulator</string> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</plist> |
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,83 @@ | ||
// | ||
// 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 Paralayout | ||
|
||
@testable import AccessibilitySnapshotDemo | ||
|
||
final class HitTargetTests: SnapshotTestCase { | ||
|
||
func testButtonHitTarget() { | ||
let buttonTraitsViewController = ButtonAccessibilityTraitsViewController() | ||
buttonTraitsViewController.view.frame = UIScreen.main.bounds | ||
SnapshotVerifyWithHitTargets(buttonTraitsViewController.view) | ||
} | ||
|
||
@available(iOS 14, *) | ||
func testTableHitTarget() throws { | ||
try XCTSkipUnless( | ||
ProcessInfo().operatingSystemVersion.majorVersion >= 14, | ||
"This test only supports iOS 14 and later" | ||
) | ||
|
||
let viewController = TableViewController() | ||
viewController.view.frame = UIScreen.main.bounds | ||
SnapshotVerifyWithHitTargets(viewController.view) | ||
} | ||
|
||
func testPerformance() throws { | ||
let buttonTraitsViewController = ButtonAccessibilityTraitsViewController() | ||
buttonTraitsViewController.view.frame = UIScreen.main.bounds | ||
|
||
measure { | ||
do { | ||
_ = try HitTargetSnapshotUtility.generateSnapshotImage( | ||
for: buttonTraitsViewController.view, | ||
useMonochromeSnapshot: true, | ||
viewRenderingMode: .drawHierarchyInRect | ||
) | ||
} catch { | ||
XCTFail("Utility should not fail to generate snapshot image") | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
// MARK: - | ||
|
||
@available(iOS 14, *) | ||
private final class TableViewController: UITableViewController { | ||
|
||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
return 3 | ||
} | ||
|
||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
let cell = UITableViewCell() | ||
|
||
var config = cell.defaultContentConfiguration() | ||
config.text = "Hello World" | ||
cell.contentConfiguration = config | ||
|
||
cell.accessoryView = UISwitch() | ||
|
||
return cell | ||
} | ||
|
||
} |
Binary file added
BIN
+101 KB
...Images/_64/SnapshotTests.HitTargetTests/testButtonHitTarget_13_7_375x812@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+129 KB
...Images/_64/SnapshotTests.HitTargetTests/testButtonHitTarget_14_5_390x844@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+129 KB
...Images/_64/SnapshotTests.HitTargetTests/testButtonHitTarget_16_4_393x852@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+87.3 KB
...pshotTests.HitTargetTests/testTableHitTargetAndReturnError__14_5_390x844@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+87.3 KB
...pshotTests.HitTargetTests/testTableHitTargetAndReturnError__16_4_393x852@3x.png
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
Binary file added
BIN
+101 KB
...shotTests/__Snapshots__/SnapshotTestingTests/testHitTargets.375x812-13-7-3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+129 KB
...shotTests/__Snapshots__/SnapshotTestingTests/testHitTargets.390x844-14-5-3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+129 KB
...shotTests/__Snapshots__/SnapshotTestingTests/testHitTargets.393x852-16-4-3x.png
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
Oops, something went wrong.