Skip to content

Commit

Permalink
Add accessibilityIds for sent images
Browse files Browse the repository at this point in the history
MOB-2245
  • Loading branch information
Egor Egorov authored and igorkravchenko committed Jan 26, 2024
1 parent 73c91fb commit 3a7a8d5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
9 changes: 9 additions & 0 deletions GliaWidgets/Sources/Download/FileDownload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ class FileDownload {
case downloading(progress: ObservableValue<Double>)
case downloaded(LocalFile)
case error(Error)

var accessibilityString: String {
switch self {
case .none: return "none"
case .downloading: return "downloading"
case .downloaded: return "downloaded"
case .error: return "error"
}
}
}

let state = ObservableValue<State>(with: .none)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class ChatImageFileContentView: ChatFileContentView {
default:
imageView.image = nil
}

updateAccessibilityIdentifier(with: download)
}

private func setImage(from file: LocalFile) {
Expand All @@ -86,4 +88,10 @@ class ChatImageFileContentView: ChatFileContentView {
private func setImage(_ image: UIImage?) {
imageView.image = image
}

private func updateAccessibilityIdentifier(with download: FileDownload) {
accessibilityIdentifier = download.file.name.map {
"chat_message_image_\($0)_\(download.state.value.accessibilityString)"
}
}
}
22 changes: 20 additions & 2 deletions GliaWidgetsTests/Sources/FileDownloadTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class FileDownloadTests: XCTestCase {
let generalFileUrl = try XCTUnwrap(
URL(string: "https://mock.mock.mock.moc")
)

enum Fetch: Equatable {
case engagement
case secureMessaging
}

let env = FetchFile.Environment(
fetchFile: { _, _, _ in },
downloadSecureFile: { _, _, _ in .mock }
Expand All @@ -41,4 +41,22 @@ class FileDownloadTests: XCTestCase {
XCTAssertEqual(evaluateFile(.init(url: secureMessagingFileUrl)), .secureMessaging)
XCTAssertEqual(evaluateFile(.init(url: generalFileUrl)), .engagement)
}

func testAccessibilityStrings() {
let strings = [
"none",
"downloading",
"downloaded",
"error"
]

let states: [FileDownload.State] = [
.none,
.downloading(progress: .init(with: 0)),
.downloaded(.mock()),
.error(.network)
]

XCTAssertEqual(states.map(\.accessibilityString), strings)
}
}

0 comments on commit 3a7a8d5

Please sign in to comment.