diff --git a/Sources/Beagle/BeagleTests/Renderer/ViewConfiguratorTests.swift b/Sources/Beagle/BeagleTests/Renderer/ViewConfiguratorTests.swift index be34219..f06af39 100644 --- a/Sources/Beagle/BeagleTests/Renderer/ViewConfiguratorTests.swift +++ b/Sources/Beagle/BeagleTests/Renderer/ViewConfiguratorTests.swift @@ -66,4 +66,25 @@ class ViewConfiguratorTests: XCTestCase { XCTAssertNotEqual(view.layer.borderWidth, CGFloat(borderWidthValue)) XCTAssertNotEqual(view.layer.borderColor, UIColor(hex: borderColorHex)?.cgColor) } + + func testApplyAccessibility() { + // Given + let button = UIButton() + button.accessibilityTraits = .button + let buttonHeader = UIButton() + var accessibility = Accessibility(accessibilityLabel: "accessibilityLabel", accessible: true) + + // When + ViewConfigurator.applyAccessibility(accessibility, to: button) + accessibility.isHeader = true + ViewConfigurator.applyAccessibility(accessibility, to: buttonHeader) + + // Then + XCTAssertEqual(button.accessibilityLabel, accessibility.accessibilityLabel) + XCTAssertTrue(button.isAccessibilityElement) + XCTAssertEqual(button.accessibilityTraits, .button) + XCTAssertEqual(buttonHeader.accessibilityLabel, accessibility.accessibilityLabel) + XCTAssertTrue(buttonHeader.isAccessibilityElement) + XCTAssertEqual(buttonHeader.accessibilityTraits, .header) + } } diff --git a/Sources/Beagle/Sources/Renderer/ViewConfigurator.swift b/Sources/Beagle/Sources/Renderer/ViewConfigurator.swift index 4a4abf5..2faa4a3 100644 --- a/Sources/Beagle/Sources/Renderer/ViewConfigurator.swift +++ b/Sources/Beagle/Sources/Renderer/ViewConfigurator.swift @@ -1,5 +1,5 @@ /* - * Copyright 2020 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA + * Copyright 2020, 2022 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -100,8 +100,8 @@ class ViewConfigurator: ViewConfiguratorProtocol { } object?.isAccessibilityElement = accessibility.accessible - if let isHeader = accessibility.isHeader { - object?.accessibilityTraits = isHeader ? .header : .none + if let isHeader = accessibility.isHeader, isHeader { + object?.accessibilityTraits = .header } } }