summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Sora/Views/FavoritesView.swift4
-rw-r--r--Sora/Views/Post/Grid/PostGridView.swift4
-rw-r--r--SoraTests/ViewDerivedDataTests.swift86
3 files changed, 90 insertions, 4 deletions
diff --git a/Sora/Views/FavoritesView.swift b/Sora/Views/FavoritesView.swift
index 3f12639..7aa6841 100644
--- a/Sora/Views/FavoritesView.swift
+++ b/Sora/Views/FavoritesView.swift
@@ -660,14 +660,14 @@ struct FavoritesView: View { // swiftlint:disable:this type_body_length
.joined(separator: ", ")
if tagSummary.isEmpty {
- return "Favorite post \(favorite.postId)"
+ return String(localized: "Favorite post \(favorite.postId)")
}
return tagSummary
}
private func favoriteAccessibilityValue(for favorite: SettingsFavoritePost) -> String {
- "Rating \(favorite.rating.rawValue.uppercased()). Provider \(favorite.provider.rawValue)."
+ String(localized: "Rating \(favorite.rating.rawValue). Provider \(favorite.provider.rawValue).")
}
}
diff --git a/Sora/Views/Post/Grid/PostGridView.swift b/Sora/Views/Post/Grid/PostGridView.swift
index 37c207e..23f7c00 100644
--- a/Sora/Views/Post/Grid/PostGridView.swift
+++ b/Sora/Views/Post/Grid/PostGridView.swift
@@ -549,14 +549,14 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
.joined(separator: ", ")
if tagSummary.isEmpty {
- return "Post \(post.id)"
+ return String(localized: "Post \(post.id)")
}
return tagSummary
}
private func postAccessibilityValue(for post: BooruPost) -> String {
- "Rating \(post.rating.rawValue.uppercased()). Score \(post.score)."
+ String(localized: "Rating \(post.rating.rawValue). Score \(post.score).")
}
// MARK: - Local Search Methods
diff --git a/SoraTests/ViewDerivedDataTests.swift b/SoraTests/ViewDerivedDataTests.swift
index 26410f8..6a27667 100644
--- a/SoraTests/ViewDerivedDataTests.swift
+++ b/SoraTests/ViewDerivedDataTests.swift
@@ -361,6 +361,92 @@ final class ViewDerivedDataTests: XCTestCase { // swiftlint:disable:this type_b
)
}
+ func testFavoritesAccessibilityFallbackAndValueUseLocalizedHumanStrings() throws {
+ let source = try loadSource(at: "Sora/Views/FavoritesView.swift")
+ let labelFunctionSource = try extractFunction(
+ named: "private func favoriteAccessibilityLabel(",
+ from: source
+ )
+ let valueFunctionSource = try extractFunction(
+ named: "private func favoriteAccessibilityValue(",
+ from: source
+ )
+ let fallbackLabelLocalizationCount = tokenCount(
+ matching: #"String\(localized:\s*"Favorite post"#,
+ in: labelFunctionSource
+ )
+ let accessibilityValueLocalizationCount = tokenCount(
+ matching: #"String\(localized:\s*"Rating"#,
+ in: valueFunctionSource
+ )
+ let uppercasedRatingCount = tokenCount(
+ matching: #"favorite\.rating\.rawValue\.uppercased\(\)"#,
+ in: valueFunctionSource
+ )
+
+ // swiftlint:disable:next prefer_nimble
+ XCTAssertGreaterThan(
+ fallbackLabelLocalizationCount,
+ 0,
+ "Favorite accessibility fallback label should use localized copy."
+ )
+ // swiftlint:disable:next prefer_nimble
+ XCTAssertGreaterThan(
+ accessibilityValueLocalizationCount,
+ 0,
+ "Favorite accessibility value should use localized copy."
+ )
+ // swiftlint:disable:next prefer_nimble
+ XCTAssertEqual(
+ uppercasedRatingCount,
+ 0,
+ "Favorite accessibility value should not uppercase rating text."
+ )
+ }
+
+ func testPostGridAccessibilityFallbackAndValueUseLocalizedHumanStrings() throws {
+ let source = try loadSource(at: "Sora/Views/Post/Grid/PostGridView.swift")
+ let labelFunctionSource = try extractFunction(
+ named: "private func postAccessibilityLabel(",
+ from: source
+ )
+ let valueFunctionSource = try extractFunction(
+ named: "private func postAccessibilityValue(",
+ from: source
+ )
+ let fallbackLabelLocalizationCount = tokenCount(
+ matching: #"String\(localized:\s*"Post"#,
+ in: labelFunctionSource
+ )
+ let accessibilityValueLocalizationCount = tokenCount(
+ matching: #"String\(localized:\s*"Rating"#,
+ in: valueFunctionSource
+ )
+ let uppercasedRatingCount = tokenCount(
+ matching: #"post\.rating\.rawValue\.uppercased\(\)"#,
+ in: valueFunctionSource
+ )
+
+ // swiftlint:disable:next prefer_nimble
+ XCTAssertGreaterThan(
+ fallbackLabelLocalizationCount,
+ 0,
+ "Post accessibility fallback label should use localized copy."
+ )
+ // swiftlint:disable:next prefer_nimble
+ XCTAssertGreaterThan(
+ accessibilityValueLocalizationCount,
+ 0,
+ "Post accessibility value should use localized copy."
+ )
+ // swiftlint:disable:next prefer_nimble
+ XCTAssertEqual(
+ uppercasedRatingCount,
+ 0,
+ "Post accessibility value should not uppercase rating text."
+ )
+ }
+
func testFavoritesDeleteActionUsesDestructiveRole() throws {
let source = try loadSource(at: "Sora/Views/FavoritesView.swift")
let functionSource = try extractFunction(