damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

ReplyDescriptionTests.swift (3680B)


      1 //
      2 //  ReplyDescriptionTests.swift
      3 //  damusTests
      4 //
      5 //  Created by Terry Yiu on 2/21/23.
      6 //
      7 
      8 import XCTest
      9 @testable import damus
     10 
     11 /* Existing unit tests failing on Github
     12 final class ReplyDescriptionTests: XCTestCase {
     13 
     14     let enUsLocale = Locale(identifier: "en-US")
     15     let profiles = test_damus_state().profiles
     16     
     17     private func descriptionForEvent(withTags tags: [[String]]) -> String {
     18         var allTags = [["e", "123"]]
     19         allTags.append(contentsOf: tags)
     20         let replyingToOne = NostrEvent(
     21             content: "hello there https://jb55.com/s/Oct12-150217.png https://jb55.com/red-me.jpg cool",
     22             pubkey: "pk",
     23             tags: allTags,
     24             createdAt: Int64(Date().timeIntervalSince1970 - 100)
     25         )
     26         
     27         Bundle.main.localizations.map { Locale(identifier: $0) }.forEach {
     28             XCTAssertNoThrow(reply_desc(profiles: profiles, event: replyingToOne, locale: $0))
     29         }
     30         return reply_desc(profiles: profiles, event: replyingToOne, locale: enUsLocale)
     31     }
     32     
     33     // Test that English strings work properly with argument substitution and pluralization, and that other locales don't crash.
     34     func testReplyDesc() throws {
     35         let replyingToSelfEvent = test_event
     36         XCTAssertEqual(reply_desc(profiles: profiles, event: replyingToSelfEvent, locale: enUsLocale), "Replying to self")
     37         Bundle.main.localizations.map { Locale(identifier: $0) }.forEach {
     38             XCTAssertNoThrow(reply_desc(profiles: profiles, event: replyingToSelfEvent, locale: $0))
     39         }
     40         
     41         // replying to one
     42         XCTAssertEqual(descriptionForEvent(withTags: [["p", "123"]]),
     43                        "Replying to \(Profile.displayName(profile: nil, pubkey: "123").username)")
     44         
     45         // replying to two
     46         XCTAssertEqual(descriptionForEvent(withTags: [["p", "123"], ["p", "456"]]),
     47                        "Replying to \(Profile.displayName(profile: nil, pubkey: "456").username) & \(Profile.displayName(profile: nil, pubkey: "123").username)")
     48         
     49         // replying to two that are the same
     50         XCTAssertEqual(descriptionForEvent(withTags: [["p", "123"], ["p", "123"]]),
     51                        "Replying to \(Profile.displayName(profile: nil, pubkey: "123").username)")
     52         
     53         // replying to two and one other
     54         XCTAssertEqual(descriptionForEvent(withTags: [["p", "123"], ["p", "456"], ["p", "789"]]),
     55                        "Replying to \(Profile.displayName(profile: nil, pubkey: "789").username), \(Profile.displayName(profile: nil, pubkey: "456").username) & 1 other")
     56 
     57         for othersCount in 2...10 {
     58             var tags: [[String]] = [["e", "123"]]
     59             for i in 1...othersCount {
     60                 tags.append(["p", "\(i)"])
     61             }
     62             tags.append(["p", "456"])
     63             tags.append(["p", "789"])
     64 
     65             let replyingToTwoAndMultipleOthers = NostrEvent(
     66                 content: "hello there https://jb55.com/s/Oct12-150217.png https://jb55.com/red-me.jpg cool",
     67                 pubkey: "pk",
     68                 tags: tags,
     69                 createdAt: Int64(Date().timeIntervalSince1970 - 100)
     70             )
     71             XCTAssertEqual(reply_desc(profiles: profiles, event: replyingToTwoAndMultipleOthers, locale: enUsLocale), "Replying to \(Profile.displayName(profile: nil, pubkey: "789").username), \(Profile.displayName(profile: nil, pubkey: "456").username) & \(othersCount) others")
     72             Bundle.main.localizations.map { Locale(identifier: $0) }.forEach {
     73                 XCTAssertNoThrow(reply_desc(profiles: profiles, event: replyingToTwoAndMultipleOthers, locale: $0))
     74             }
     75         }
     76     }
     77 
     78 }
     79 */