Fix reposts banner to be localizable

Changelog-Fixed: Fixed reposts banner to be localizable
Signed-off-by: Terry Yiu <git@tyiu.xyz>
This commit is contained in:
2025-02-23 16:17:37 -05:00
parent 4324b185fe
commit a87ba73160
5 changed files with 97 additions and 18 deletions

View File

@@ -0,0 +1,37 @@
//
// RepostedTests.swift
// damusTests
//
// Created by Terry Yiu on 2/23/25.
//
import XCTest
@testable import damus
final class RepostedTests: XCTestCase {
func testPeopleRepostedText() throws {
let enUsLocale = Locale(identifier: "en-US")
let damusState = test_damus_state
let pubkey = test_pubkey
// reposts must be greater than 0. Empty string is returned as a fallback if not.
XCTAssertEqual(people_reposted_text(profiles: damusState.profiles, pubkey: pubkey, reposts: -1, locale: enUsLocale), "")
XCTAssertEqual(people_reposted_text(profiles: damusState.profiles, pubkey: pubkey, reposts: 0, locale: enUsLocale), "")
// Verify the English pluralization variations.
XCTAssertEqual(people_reposted_text(profiles: damusState.profiles, pubkey: pubkey, reposts: 1, locale: enUsLocale), "17ldvg64:nq5mhr77 reposted")
XCTAssertEqual(people_reposted_text(profiles: damusState.profiles, pubkey: pubkey, reposts: 2, locale: enUsLocale), "17ldvg64:nq5mhr77 and 1 other reposted")
XCTAssertEqual(people_reposted_text(profiles: damusState.profiles, pubkey: pubkey, reposts: 3, locale: enUsLocale), "17ldvg64:nq5mhr77 and 2 others reposted")
// Sanity check that the non-English translations are likely not malformed.
Bundle.main.localizations.map { Locale(identifier: $0) }.forEach {
// -1...11 covers a lot (but not all) pluralization rules for different languages.
// However, it is good enough for a sanity check.
for reposts in -1...11 {
XCTAssertNoThrow(people_reposted_text(profiles: damusState.profiles, pubkey: pubkey, reposts: reposts, locale: $0))
}
}
}
}