Skip to content

Commit 1ce9e1b

Browse files
authored
Support new a11y snapshot API (#659)
We removed a11y snapshots from the snapshot testing repo to decouple the accessibility framework from the snapshot test itself. Updating our tests here to still use the same a11y framework
1 parent 3c7b642 commit 1ce9e1b

File tree

3 files changed

+92
-13
lines changed

3 files changed

+92
-13
lines changed

ios/HackerNews.xcodeproj/project.pbxproj

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
F48E9DA82D4D2A3C00FD8B30 /* Common in Embed Frameworks */ = {isa = PBXBuildFile; productRef = F48E9DA62D4D2A3C00FD8B30 /* Common */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
3535
F48E9ECB2D4D691600FD8B30 /* ETDistribution in Frameworks */ = {isa = PBXBuildFile; productRef = F48E9ECA2D4D691600FD8B30 /* ETDistribution */; };
3636
F48E9FDB2D51690400FD8B30 /* ETDistribution in Embed Frameworks */ = {isa = PBXBuildFile; productRef = F48E9ECA2D4D691600FD8B30 /* ETDistribution */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
37+
FA80C2702EC78D7500A700AB /* AccessibilitySnapshotCore in Frameworks */ = {isa = PBXBuildFile; productRef = FA80C26F2EC78D7500A700AB /* AccessibilitySnapshotCore */; };
38+
FA80C2732EC78F2D00A700AB /* AccessibilitySnapshotCore in Frameworks */ = {isa = PBXBuildFile; productRef = FA80C2722EC78F2D00A700AB /* AccessibilitySnapshotCore */; };
3739
/* End PBXBuildFile section */
3840

3941
/* Begin PBXContainerItemProxy section */
@@ -203,10 +205,12 @@
203205
isa = PBXFrameworksBuildPhase;
204206
buildActionMask = 2147483647;
205207
files = (
208+
FA80C2732EC78F2D00A700AB /* AccessibilitySnapshotCore in Frameworks */,
206209
A495A6662CED57BB009A2A6B /* SnapshotTesting in Frameworks */,
207210
C3AC6AD92CB6E8F7006BD22D /* SnapshottingTests in Frameworks */,
208211
A4BED5C32AD5E083001642B3 /* (null) in Frameworks */,
209212
F48E9DA32D4D2A3500FD8B30 /* Common in Frameworks */,
213+
FA80C2702EC78D7500A700AB /* AccessibilitySnapshotCore in Frameworks */,
210214
);
211215
runOnlyForDeploymentPostprocessing = 0;
212216
};
@@ -492,12 +496,13 @@
492496
A47309B22AA29D9600201376 /* XCRemoteSwiftPackageReference "SwiftSoup" */,
493497
995A2BEDEF224F7085D3DB13 /* XCRemoteSwiftPackageReference "sentry-cocoa" */,
494498
A495B2932BFEA11B00A8A8A9 /* XCRemoteSwiftPackageReference "Reaper" */,
495-
A4D28AEC2C237E2A007F20D0 /* XCRemoteSwiftPackageReference "SnapshotPreviews-iOS" */,
499+
A4D28AEC2C237E2A007F20D0 /* XCRemoteSwiftPackageReference "SnapshotPreviews" */,
496500
A495A6642CED57BB009A2A6B /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */,
497501
F45F6E532D4D1D3E003FA9A3 /* XCLocalSwiftPackageReference "Packages/Common" */,
498502
F45F6F4C2D4D2554003FA9A3 /* XCLocalSwiftPackageReference "Packages/Fonts" */,
499503
F48E9EC92D4D691600FD8B30 /* XCRemoteSwiftPackageReference "ETDistribution" */,
500504
A42271692DE78DEF002F03D5 /* XCRemoteSwiftPackageReference "faultordering" */,
505+
FA80C2712EC78F2D00A700AB /* XCRemoteSwiftPackageReference "AccessibilitySnapshot" */,
501506
);
502507
productRefGroup = A427057A2A4293B10057E439 /* Products */;
503508
projectDirPath = "";
@@ -1260,9 +1265,9 @@
12601265
minimumVersion = 1.6.0;
12611266
};
12621267
};
1263-
A4D28AEC2C237E2A007F20D0 /* XCRemoteSwiftPackageReference "SnapshotPreviews-iOS" */ = {
1268+
A4D28AEC2C237E2A007F20D0 /* XCRemoteSwiftPackageReference "SnapshotPreviews" */ = {
12641269
isa = XCRemoteSwiftPackageReference;
1265-
repositoryURL = "https://github.com/EmergeTools/SnapshotPreviews-iOS";
1270+
repositoryURL = "https://github.com/EmergeTools/SnapshotPreviews";
12661271
requirement = {
12671272
branch = main;
12681273
kind = branch;
@@ -1276,6 +1281,22 @@
12761281
minimumVersion = 0.2.1;
12771282
};
12781283
};
1284+
FA80C26E2EC78D7500A700AB /* XCRemoteSwiftPackageReference "AccessibilitySnapshot" */ = {
1285+
isa = XCRemoteSwiftPackageReference;
1286+
repositoryURL = "https://github.com/cashapp/AccessibilitySnapshot.git";
1287+
requirement = {
1288+
kind = exactVersion;
1289+
version = 1.0.2;
1290+
};
1291+
};
1292+
FA80C2712EC78F2D00A700AB /* XCRemoteSwiftPackageReference "AccessibilitySnapshot" */ = {
1293+
isa = XCRemoteSwiftPackageReference;
1294+
repositoryURL = "https://github.com/cashapp/AccessibilitySnapshot";
1295+
requirement = {
1296+
kind = upToNextMajorVersion;
1297+
minimumVersion = 0.10.0;
1298+
};
1299+
};
12791300
/* End XCRemoteSwiftPackageReference section */
12801301

12811302
/* Begin XCSwiftPackageProductDependency section */
@@ -1311,17 +1332,17 @@
13111332
};
13121333
A4D28AED2C237E2A007F20D0 /* SnapshotPreferences */ = {
13131334
isa = XCSwiftPackageProductDependency;
1314-
package = A4D28AEC2C237E2A007F20D0 /* XCRemoteSwiftPackageReference "SnapshotPreviews-iOS" */;
1335+
package = A4D28AEC2C237E2A007F20D0 /* XCRemoteSwiftPackageReference "SnapshotPreviews" */;
13151336
productName = SnapshotPreferences;
13161337
};
13171338
A4D28AEF2C237E2A007F20D0 /* SnapshottingTests */ = {
13181339
isa = XCSwiftPackageProductDependency;
1319-
package = A4D28AEC2C237E2A007F20D0 /* XCRemoteSwiftPackageReference "SnapshotPreviews-iOS" */;
1340+
package = A4D28AEC2C237E2A007F20D0 /* XCRemoteSwiftPackageReference "SnapshotPreviews" */;
13201341
productName = SnapshottingTests;
13211342
};
13221343
C3AC6AD82CB6E8F7006BD22D /* SnapshottingTests */ = {
13231344
isa = XCSwiftPackageProductDependency;
1324-
package = A4D28AEC2C237E2A007F20D0 /* XCRemoteSwiftPackageReference "SnapshotPreviews-iOS" */;
1345+
package = A4D28AEC2C237E2A007F20D0 /* XCRemoteSwiftPackageReference "SnapshotPreviews" */;
13251346
productName = SnapshottingTests;
13261347
};
13271348
F40E429F2EA80E1600E53876 /* SentrySwiftUI */ = {
@@ -1364,6 +1385,16 @@
13641385
package = F48E9EC92D4D691600FD8B30 /* XCRemoteSwiftPackageReference "ETDistribution" */;
13651386
productName = ETDistribution;
13661387
};
1388+
FA80C26F2EC78D7500A700AB /* AccessibilitySnapshotCore */ = {
1389+
isa = XCSwiftPackageProductDependency;
1390+
package = FA80C26E2EC78D7500A700AB /* XCRemoteSwiftPackageReference "AccessibilitySnapshot" */;
1391+
productName = AccessibilitySnapshotCore;
1392+
};
1393+
FA80C2722EC78F2D00A700AB /* AccessibilitySnapshotCore */ = {
1394+
isa = XCSwiftPackageProductDependency;
1395+
package = FA80C2712EC78F2D00A700AB /* XCRemoteSwiftPackageReference "AccessibilitySnapshot" */;
1396+
productName = AccessibilitySnapshotCore;
1397+
};
13671398
/* End XCSwiftPackageProductDependency section */
13681399
};
13691400
rootObject = A42705712A4293B10057E439 /* Project object */;

ios/HackerNews.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 16 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ios/HackerNewsTests/HackerNewsSnapshotTest.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
import Foundation
99
import SnapshottingTests
10+
#if canImport(UIKit)
11+
import UIKit
12+
#endif
13+
#if canImport(AccessibilitySnapshotCore)
14+
import AccessibilitySnapshotCore
15+
#endif
1016

1117
class HackerNewsSnapshotTest: SnapshotTest {
1218
override class func snapshotPreviews() -> [String]? {
@@ -16,4 +22,37 @@ class HackerNewsSnapshotTest: SnapshotTest {
1622
override class func excludedSnapshotPreviews() -> [String]? {
1723
return nil
1824
}
25+
26+
#if canImport(UIKit) && !os(watchOS) && !os(visionOS) && !os(tvOS)
27+
override open class func setupA11y() -> ((UIViewController, UIWindow, PreviewLayout) -> UIView)? {
28+
return { (controller: UIViewController, window: UIWindow, layout: PreviewLayout) in
29+
let containerVC = controller.parent
30+
let containedView: UIView
31+
switch layout {
32+
case .device:
33+
containedView = containerVC?.view ?? controller.view
34+
default:
35+
containedView = controller.view
36+
}
37+
let a11yView = AccessibilitySnapshotView(
38+
containedView: containedView,
39+
viewRenderingMode: controller.view.bounds.size.requiresCoreAnimationSnapshot ? .renderLayerInContext : .drawHierarchyInRect,
40+
activationPointDisplayMode: .never,
41+
showUserInputLabels: true)
42+
43+
a11yView.center = window.center
44+
window.addSubview(a11yView)
45+
46+
_ = try? a11yView.parseAccessibility(useMonochromeSnapshot: false)
47+
a11yView.sizeToFit()
48+
return a11yView
49+
}
50+
}
51+
#endif
52+
}
53+
54+
extension CGSize {
55+
var requiresCoreAnimationSnapshot: Bool {
56+
height >= UIScreen.main.bounds.size.height * 2
57+
}
1958
}

0 commit comments

Comments
 (0)