Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for accessibility #1205

Merged
merged 1 commit into from
Nov 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Tests/ASDisplayViewAccessibilityTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,47 @@ - (void)testAccessibilityElementsAccessors
XCTAssertEqual([node.view indexOfAccessibilityElement:node.view.accessibilityElements.firstObject], 0);*/
}

- (void)testThatSubnodeAccessibilityLabelAggregationWorks {
// Setup nodes
ASDisplayNode *node = nil;
ASDisplayNode *innerNode1 = nil;
ASDisplayNode *innerNode2 = nil;
node = [[ASDisplayNode alloc] init];
innerNode1 = [[ASDisplayNode alloc] init];
innerNode2 = [[ASDisplayNode alloc] init];

// Initialize nodes with relevant accessibility data
node.isAccessibilityContainer = YES;
innerNode1.accessibilityLabel = @"hello";
innerNode2.accessibilityLabel = @"world";

// Attach the subnodes to the parent node, then ensure their accessibility labels have been'
// aggregated to the parent's accessibility label
[node addSubnode:innerNode1];
[node addSubnode:innerNode2];
XCTAssertEqualObjects([node.view.accessibilityElements.firstObject accessibilityLabel],
@"hello, world", @"Subnode accessibility label aggregation broken %@",
[node.view.accessibilityElements.firstObject accessibilityLabel]);
}

- (void)testThatContainerAccessibilityLabelOverrideStopsAggregation {
// Setup nodes
ASDisplayNode *node = nil;
ASDisplayNode *innerNode = nil;
node = [[ASDisplayNode alloc] init];
innerNode = [[ASDisplayNode alloc] init];

// Initialize nodes with relevant accessibility data
node.isAccessibilityContainer = YES;
node.accessibilityLabel = @"hello";
innerNode.accessibilityLabel = @"world";

// Attach the subnode to the parent node, then ensure the parent's accessibility label does not
// get aggregated with the subnode's label
[node addSubnode:innerNode];
XCTAssertEqualObjects([node.view.accessibilityElements.firstObject accessibilityLabel], @"hello",
@"Container accessibility label override broken %@",
[node.view.accessibilityElements.firstObject accessibilityLabel]);
}

@end