Skip to content

Commit

Permalink
Merge pull request #5 from cashapp/entin/core-subspec
Browse files Browse the repository at this point in the history
Split framework into subspecs
  • Loading branch information
NickEntin authored May 30, 2020
2 parents 851c1bf + 0754159 commit 9b1a71d
Show file tree
Hide file tree
Showing 24 changed files with 78 additions and 41 deletions.
37 changes: 24 additions & 13 deletions AccessibilitySnapshot.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'AccessibilitySnapshot'
s.version = '0.3.0'
s.version = '0.3.1'
s.summary = 'Easy regression testing for iOS accessibility'

s.homepage = 'https://github.com/CashApp/AccessibilitySnapshot'
Expand All @@ -12,20 +12,31 @@ Pod::Spec.new do |s|

s.ios.deployment_target = '10.0'

s.source_files = 'AccessibilitySnapshot/Classes/**/*.{swift,h,m}'
s.public_header_files = [
'AccessibilitySnapshot/Classes/FBSnapshotTestCase_Accessibility.h',
'AccessibilitySnapshot/Classes/UIAccessibilityStatusUtility.h',
'AccessibilitySnapshot/Classes/UIView+DynamicTypeSnapshotting.h',
]
s.default_subspecs = 'Core', 'iOSSnapshotTestCase'

s.resource_bundles = {
'AccessibilitySnapshot' => ['AccessibilitySnapshot/Assets/**/*.{strings,xcassets}']
}
s.subspec 'Core' do |ss|
ss.source_files = 'AccessibilitySnapshot/Core/Classes/**/*.{swift,h,m}'
ss.public_header_files = [
'AccessibilitySnapshot/Core/Classes/UIAccessibilityStatusUtility.h',
'AccessibilitySnapshot/Core/Classes/UIView+DynamicTypeSnapshotting.h',
]
ss.resource_bundles = {
'AccessibilitySnapshot' => ['AccessibilitySnapshot/Core/Assets/**/*.{strings,xcassets}']
}

ss.dependency 'fishhook', '~> 0.2'
end

s.subspec 'iOSSnapshotTestCase' do |ss|
ss.source_files = 'AccessibilitySnapshot/iOSSnapshotTestCase/Classes/**/*.{swift,h,m}'
ss.public_header_files = [
'AccessibilitySnapshot/iOSSnapshotTestCase/Classes/FBSnapshotTestCase_Accessibility.h',
]

ss.dependency 'AccessibilitySnapshot/Core'
ss.dependency 'iOSSnapshotTestCase', '~> 6.0'
end

s.frameworks = 'XCTest'
s.weak_frameworks = 'XCTest'

s.dependency 'iOSSnapshotTestCase', '~> 6.0'
s.dependency 'fishhook', '~> 0.2'
end
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

import UIKit

struct AccessibilityMarker {
public struct AccessibilityMarker {

// MARK: - Public Types

enum Shape {
public enum Shape {

/// Accessibility frame, in the coordinate space of the view being snapshotted.
case frame(CGRect)
Expand All @@ -34,29 +34,29 @@ struct AccessibilityMarker {

/// The description of the accessibility element that will be read by VoiceOver when the element is brought into
/// focus.
var description: String
public var description: String

/// A hint that will be read by VoiceOver if focus remains on the element after the `description` is read.
var hint: String?
public var hint: String?

/// The shape that will be highlighted on screen while the element is in focus.
var shape: Shape
public var shape: Shape

/// The accessibility activation point, in the coordinate space of the view being snapshotted.
var activationPoint: CGPoint
public var activationPoint: CGPoint

/// Whether or not the `activationPoint` is the default activation point for the object.
///
/// For most elements, the default activation point is the midpoint of the element's accessibility frame. Certain
/// elements have distinct defaults - for example, a `UISlider` puts its activation point at the center of its thumb
/// by default.
var usesDefaultActivationPoint: Bool
public var usesDefaultActivationPoint: Bool

}

// MARK: -

protocol UserInterfaceLayoutDirectionProviding {
public protocol UserInterfaceLayoutDirectionProviding {

var userInterfaceLayoutDirection: UIUserInterfaceLayoutDirection { get }

Expand All @@ -66,12 +66,12 @@ extension UIApplication: UserInterfaceLayoutDirectionProviding {}

// MARK: -

final class AccessibilityHierarchyParser {
public final class AccessibilityHierarchyParser {

// MARK: - Public Types

/// Represents a context in which elements are contained.
enum Context {
public enum Context {

/// Indicates the element is part of a series of elements.
/// Reads as "`index` of `count`."
Expand Down Expand Up @@ -138,6 +138,10 @@ final class AccessibilityHierarchyParser {

}

// MARK: - Life Cycle

public init() {}

// MARK: - Public Methods

/// Parses the accessibility hierarchy starting from the `root` view and returns markers for each element in the
Expand All @@ -147,7 +151,7 @@ final class AccessibilityHierarchyParser {
/// relative to this view's coordinate space.
/// - parameter userInterfaceLayoutDirectionProvider: The provider of the device's user interface layout direction.
/// In most cases, this should use the default value, `UIApplication.shared`.
func parseAccessibilityElements(
public func parseAccessibilityElements(
in root: UIView,
userInterfaceLayoutDirectionProvider: UserInterfaceLayoutDirectionProviding = UIApplication.shared
) -> [AccessibilityMarker] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,20 @@ public enum ActivationPointDisplayMode {
///
/// The overlays and legend will be added when `parseAccessibility()` is called. In order for the coordinates to be
/// calculated properly, the view must already be in the view hierarchy.
final class AccessibilitySnapshotView: UIView {
public final class AccessibilitySnapshotView: UIView {

// MARK: - Life Cycle

init(
/// Initializes a new snapshot container view.
///
/// - parameter containedView: The view that should be snapshotted, and for which the accessibility markers should
/// be generated.
/// - parameter viewRenderingMode: The method to use when snapshotting the `containedView`.
/// - parameter markerColors: An array of colors to use for the highlighted regions. These colors will be used in
/// order, repeating through the array as necessary.
/// - parameter activationPointDisplayMode: Controls when to show indicators for elements' accessibility activation
/// points.
public init(
containedView: UIView,
viewRenderingMode: ViewRenderingMode,
markerColors: [UIColor] = defaultMarkerColors,
Expand Down Expand Up @@ -85,7 +94,7 @@ final class AccessibilitySnapshotView: UIView {
/// Parse the `containedView`'s accessibility and add appropriate visual elements to represent it.
///
/// This must be called _after_ the view is in the view hierarchy.
func parseAccessibility(useMonochromeSnapshot: Bool) {
public func parseAccessibility(useMonochromeSnapshot: Bool) {
// Clean up any previous markers.
self.displayMarkers.forEach {
$0.legendView.removeFromSuperview()
Expand Down Expand Up @@ -175,7 +184,7 @@ final class AccessibilitySnapshotView: UIView {

// MARK: - UIView

override func layoutSubviews() {
public override func layoutSubviews() {
let legendViews = displayMarkers.map { $0.legendView }

switch legendLocation(viewSize: snapshotView.bounds.size) {
Expand Down Expand Up @@ -225,7 +234,7 @@ final class AccessibilitySnapshotView: UIView {
}
}

override func sizeThatFits(_ size: CGSize) -> CGSize {
public override func sizeThatFits(_ size: CGSize) -> CGSize {
guard !displayMarkers.isEmpty else {
return snapshotView.bounds.size
}
Expand Down Expand Up @@ -323,9 +332,9 @@ final class AccessibilitySnapshotView: UIView {
}
}

// MARK: - Private Static Properties
// MARK: - Public Static Properties

private static let defaultMarkerColors: [UIColor] = [ .cyan, .magenta, .green, .blue, .yellow, .purple, .orange ]
public static let defaultMarkerColors: [UIColor] = [ .cyan, .magenta, .green, .blue, .yellow, .purple, .orange ]

// MARK: - Private Types

Expand Down Expand Up @@ -369,10 +378,12 @@ final class AccessibilitySnapshotView: UIView {

extension AccessibilitySnapshotView {

enum ViewRenderingMode {
public enum ViewRenderingMode {

/// Render the view's layer in a `CGContext` using the `render(in:)` method.
case renderLayerInContext

/// Draw the view's hierarchy after screen updates using the `drawHierarchy(in:afterScreenUpdates:)` method.
case drawHierarchyInRect

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import UIKit

extension UIView {

// MARK: - Internal Methods
// MARK: - Public Methods

@available(iOS 11, *)
func drawHierarchyWithInvertedColors(in rect: CGRect, using context: UIGraphicsImageRendererContext) {
public func drawHierarchyWithInvertedColors(in rect: CGRect, using context: UIGraphicsImageRendererContext) {
if accessibilityIgnoresInvertColors {
drawHierarchy(in: rect, afterScreenUpdates: false)

Expand Down
2 changes: 1 addition & 1 deletion Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ target 'AccessibilitySnapshotDemo' do
target 'UnitTests' do
inherit! :search_paths

pod 'AccessibilitySnapshot', :path => '../AccessibilitySnapshot.podspec'
pod 'AccessibilitySnapshot/Core', :path => '../AccessibilitySnapshot.podspec'
end
end

Expand Down
12 changes: 9 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
PODS:
- AccessibilitySnapshot (0.3.0):
- AccessibilitySnapshot (0.3.1):
- AccessibilitySnapshot/Core (= 0.3.1)
- AccessibilitySnapshot/iOSSnapshotTestCase (= 0.3.1)
- AccessibilitySnapshot/Core (0.3.1):
- fishhook (~> 0.2)
- AccessibilitySnapshot/iOSSnapshotTestCase (0.3.1):
- AccessibilitySnapshot/Core
- iOSSnapshotTestCase (~> 6.0)
- fishhook (0.2)
- iOSSnapshotTestCase (6.2.0):
Expand All @@ -12,6 +17,7 @@ PODS:

DEPENDENCIES:
- AccessibilitySnapshot (from `../AccessibilitySnapshot.podspec`)
- AccessibilitySnapshot/Core (from `../AccessibilitySnapshot.podspec`)
- Paralayout (~> 0.9)

SPEC REPOS:
Expand All @@ -25,11 +31,11 @@ EXTERNAL SOURCES:
:path: "../AccessibilitySnapshot.podspec"

SPEC CHECKSUMS:
AccessibilitySnapshot: 4ef5ec8d06dd9aa167fcc3afa86539a59d649161
AccessibilitySnapshot: 5c623007716998e3b9d040fd28f42407c0e38502
fishhook: ea19933abfe8f2f52c55fd8b6e2718467d3ebc89
iOSSnapshotTestCase: 9ab44cb5aa62b84d31847f40680112e15ec579a6
Paralayout: e36bf8c795ed9930159b9635ebb802d026667d0b

PODFILE CHECKSUM: 75c7dd396546765a95d746610aba834d2b137c84
PODFILE CHECKSUM: a46ca457f96c3770fea5e16fe5218c1408222d82

COCOAPODS: 1.9.1
3 changes: 1 addition & 2 deletions Example/UnitTests/AccessibilityHierarchyParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
// limitations under the License.
//

import AccessibilitySnapshot
import UIKit
import XCTest

@testable import AccessibilitySnapshot

final class AccessibilityHierarchyParserTests: XCTestCase {

func testUserInterfaceLayoutDirection() {
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ AccessibilitySnapshots makes it simple to add regression tests for accessibility

## Getting Started

AccessibilitySnapshot is built on top of [iOSSnapshotTestCase](https://github.com/uber/ios-snapshot-test-case). Before setting up accessibility snapshot tests, make sure your project is set up for standard snapshot testing. Accessibility snapshot tests require that the test target has a host application.
By default, AccessibilitySnapshot uses [iOSSnapshotTestCase](https://github.com/uber/ios-snapshot-test-case) to record snapshots and perform comparisons. Before setting up accessibility snapshot tests, make sure your project is set up for standard snapshot testing. Accessibility snapshot tests require that the test target has a host application.

### CocoaPods

Expand All @@ -19,6 +19,12 @@ Install with [CocoaPods](https://cocoapods.org) by adding the following to your
pod 'AccessibilitySnapshot'
```

To use only the core accessibility parser, add a dependency on the Core subspec alone.

```ruby
pod 'AccessibilitySnapshot/Core'
```

## Usage

To run a snapshot test, simply call the `SnapshotVerifyAccessibility` method:
Expand Down

0 comments on commit 9b1a71d

Please sign in to comment.