diff --git a/GliaWidgets/Sources/Download/FileDownload.swift b/GliaWidgets/Sources/Download/FileDownload.swift index 11cfbfcb0..a39ab4adb 100644 --- a/GliaWidgets/Sources/Download/FileDownload.swift +++ b/GliaWidgets/Sources/Download/FileDownload.swift @@ -25,6 +25,15 @@ class FileDownload { case downloading(progress: ObservableValue) 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(with: .none) diff --git a/GliaWidgets/Sources/View/Chat/Message/Content/File/Image/ChatImageFileContentView.swift b/GliaWidgets/Sources/View/Chat/Message/Content/File/Image/ChatImageFileContentView.swift index 654e22053..940f57b31 100644 --- a/GliaWidgets/Sources/View/Chat/Message/Content/File/Image/ChatImageFileContentView.swift +++ b/GliaWidgets/Sources/View/Chat/Message/Content/File/Image/ChatImageFileContentView.swift @@ -74,6 +74,8 @@ class ChatImageFileContentView: ChatFileContentView { default: imageView.image = nil } + + updateAccessibilityIdentifier(with: download) } private func setImage(from file: LocalFile) { @@ -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)" + } + } } diff --git a/GliaWidgetsTests/Sources/FileDownloadTests.swift b/GliaWidgetsTests/Sources/FileDownloadTests.swift index cd4f2ba72..0c0ef0635 100644 --- a/GliaWidgetsTests/Sources/FileDownloadTests.swift +++ b/GliaWidgetsTests/Sources/FileDownloadTests.swift @@ -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 } @@ -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) + } }