Skip to content

Commit

Permalink
Merge pull request #61 from joleary1987/add-accessibility-identifiers…
Browse files Browse the repository at this point in the history
…-for-uitesting-latest-version

Add UIAccessibility properties to Brick class to pass along to BrickC…
  • Loading branch information
rubencagnie authored Jan 12, 2017
2 parents 6fcca01 + f214ad4 commit 4ef3aa0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
8 changes: 7 additions & 1 deletion Source/Cells/BrickCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ extension BaseBrickCell {

public class BrickCell: BaseBrickCell {

private var _brick: Brick!
private var _brick: Brick! {
didSet {
self.accessibilityIdentifier = _brick.accessibilityIdentifier
self.accessibilityLabel = _brick.accessibilityLabel
self.accessibilityHint = _brick.accessibilityHint
}
}
public var tapGesture: UITapGestureRecognizer?
public private(set) var index: Int = 0
public private(set) var collectionIndex: Int = 0
Expand Down
11 changes: 10 additions & 1 deletion Source/Models/BrickModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ public class Brick: CustomStringConvertible {
/// Identifier of the brick. Defaults to empty string
public let identifier: String

/// Passes string to BrickCell's accessibilityIdentifier for UIAccessibility. Defaults to the brick identifier
public var accessibilityIdentifier: String

/// Passes string to BrickCell's accessibilityLabel for UIAccessibility. Defaults to nil
public var accessibilityLabel: String?

/// Passes string to BrickCell's accessibilityHint for UIAccessibility. Defaults to nil
public var accessibilityHint: String?

public var size: BrickSize

/// Width dimension used to calculate the width. Defaults to .Ratio(ratio: 1)
Expand Down Expand Up @@ -58,7 +67,6 @@ public class Brick: CustomStringConvertible {
/// - parameter height: Height dimension used to calculate the height. Defaults to .Auto(estimate: .Fixed(size: 50))
/// - parameter backgroundColor: Background color used for the brick. Defaults to .clearColor()
/// - parameter backgroundView: Background view used for the brick. Defaults to nil
///
/// - returns: brick
convenience public init(_ identifier: String = "", width: BrickDimension = .Ratio(ratio: 1), height: BrickDimension = .Auto(estimate: .Fixed(size: 50)), backgroundColor: UIColor = .clearColor(), backgroundView: UIView? = nil) {
self.init(identifier, size: BrickSize(width: width, height: height), backgroundColor: backgroundColor, backgroundView: backgroundView)
Expand All @@ -69,6 +77,7 @@ public class Brick: CustomStringConvertible {
self.size = size
self.backgroundColor = backgroundColor
self.backgroundView = backgroundView
self.accessibilityIdentifier = identifier
}

// Mark: - Internal
Expand Down
38 changes: 37 additions & 1 deletion Tests/Cells/BaseBrickCellTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,42 @@ class BaseBrickCellTests: XCTestCase {
brickView.setSection(section)
brickView.layoutSubviews()
}


func testDefaultAccessibilityIdentifierSetFromBrickIdentifier() {
brickView.registerBrickClass(DummyBrick.self)
let dummyBrick = DummyBrick("BrickIdentifierThatIsDefaultAccessibilityIdentifier")
let section = BrickSection(bricks: [dummyBrick])
brickView.setSection(section)
brickView.layoutSubviews()
let dummyCell = brickView.cellForItemAtIndexPath(NSIndexPath(forItem: 0, inSection: 1)) as? DummyBrickCell
XCTAssertEqual(dummyBrick.identifier, "BrickIdentifierThatIsDefaultAccessibilityIdentifier")
XCTAssertNil(dummyCell?.accessibilityHint)
XCTAssertNil(dummyCell?.accessibilityLabel)
}

func testSetAccessibilityIdentifier() {
brickView.registerBrickClass(DummyBrick.self)
let dummyBrick = DummyBrick("BrickIdentifierThatIsDefaultAccessibilityIdentifier")
dummyBrick.accessibilityIdentifier = "AccessibilityIdentifierForDummyBrickCell"
let section = BrickSection(bricks: [dummyBrick])
brickView.setSection(section)
brickView.layoutSubviews()
let dummyCell = brickView.cellForItemAtIndexPath(NSIndexPath(forItem: 0, inSection: 1)) as? DummyBrickCell
XCTAssertEqual(dummyCell?.accessibilityIdentifier, "AccessibilityIdentifierForDummyBrickCell")
XCTAssertNil(dummyCell?.accessibilityHint)
XCTAssertNil(dummyCell?.accessibilityLabel)
}

func testSetAccessibilityHintAndLabel() {
brickView.registerBrickClass(DummyBrick.self)
let dummyBrick = DummyBrick("BrickIdentifierThatIsDefaultAccessibilityIdentifier")
dummyBrick.accessibilityHint = "Accessibility Hint"
dummyBrick.accessibilityLabel = "Accessibility Label"
let section = BrickSection(bricks: [dummyBrick])
brickView.setSection(section)
brickView.layoutSubviews()
let dummyCell = brickView.cellForItemAtIndexPath(NSIndexPath(forItem: 0, inSection: 1)) as? DummyBrickCell
XCTAssertEqual(dummyCell?.accessibilityHint, "Accessibility Hint")
XCTAssertEqual(dummyCell?.accessibilityLabel, "Accessibility Label")
}
}

0 comments on commit 4ef3aa0

Please sign in to comment.