IOS-1363 WIP: Quoted char > IOS-1363
authorAdam Kowalski <adam@pep-project.org>
Wed, 11 Mar 2020 19:08:34 +0100
branchIOS-1363
changeset 12212376d13d6b73c
parent 12207 3e2e3a3b3ae1
child 12213 f631bb6e6e2f
IOS-1363 WIP: Quoted char >
pEpForiOS/HTMLParser/Axt/HtmlToTextSaxParser.swift
pEpForiOS/Util/ReplyUtil.swift
pEpForiOSTests/Util/ReplyUtilTests.swift
     1.1 --- a/pEpForiOS/HTMLParser/Axt/HtmlToTextSaxParser.swift	Wed Mar 11 17:59:41 2020 +0100
     1.2 +++ b/pEpForiOS/HTMLParser/Axt/HtmlToTextSaxParser.swift	Wed Mar 11 19:08:34 2020 +0100
     1.3 @@ -40,12 +40,12 @@
     1.4      func parser(_ parser: AXHTMLParser, didStartElement elementName: String,
     1.5                  attributes attributeDict: [AnyHashable : Any] = [:]) {
     1.6          tagStack.append(elementName)
     1.7 +    }
     1.8 +
     1.9 +    func parser(_ parser: AXHTMLParser, didEndElement elementName: String) {
    1.10          if elementName == "br" || elementName == "p" || elementName == "div" {
    1.11              add(string: "\n")
    1.12          }
    1.13 -    }
    1.14 -
    1.15 -    func parser(_ parser: AXHTMLParser, didEndElement elementName: String) {
    1.16          tagStack.removeLast()
    1.17      }
    1.18  
     2.1 --- a/pEpForiOS/Util/ReplyUtil.swift	Wed Mar 11 17:59:41 2020 +0100
     2.2 +++ b/pEpForiOS/Util/ReplyUtil.swift	Wed Mar 11 19:08:34 2020 +0100
     2.3 @@ -33,7 +33,8 @@
     2.4      /// - Returns: text with citation header and "send by pEp" footer
     2.5      static func citedMessageText(textToCite: String, fromMessage msg: Message) -> String {
     2.6          let citation = citationHeaderForMessage(msg)
     2.7 -        return "\n\n\(footer())\n\n\(citation)\n\n\(textToCite)"
     2.8 +        let quoteChar = ">"
     2.9 +        return "\n\n\(footer())\n\n\(citation)\n\n\(quoteChar) \(textToCite)"
    2.10      }
    2.11  
    2.12      /// Adds citation header with data of a given message to a given text.
    2.13 @@ -49,7 +50,8 @@
    2.14          let defaultFont = UIFont.preferredFont(forTextStyle: .body)
    2.15          var result = NSAttributedString(string: "\n\n\(footer())\n\n\(citation)\n\n",
    2.16              attributes: [NSAttributedString.Key(rawValue: "NSFont"): defaultFont])
    2.17 -        result = result + textToCite
    2.18 +        let quoteChar = ">"
    2.19 +        result = result + quoteChar + " " + textToCite
    2.20          return result
    2.21      }
    2.22  
     3.1 --- a/pEpForiOSTests/Util/ReplyUtilTests.swift	Wed Mar 11 17:59:41 2020 +0100
     3.2 +++ b/pEpForiOSTests/Util/ReplyUtilTests.swift	Wed Mar 11 19:08:34 2020 +0100
     3.3 @@ -27,6 +27,7 @@
     3.4          }
     3.5          XCTAssertEqual(ReplyUtil.replySubject(message: msg), expectedReplySubject)
     3.6      }
     3.7 +    // Create new ticket for this bug?
     3.8      func testReplyNonSubject() {
     3.9          let msg = getMockMessage()
    3.10          msg.shortMessage = nil
    3.11 @@ -38,6 +39,7 @@
    3.12          // XCTAssertEqual failed: ("") is not equal to ("Re:  ")
    3.13      }
    3.14  
    3.15 +    // Create new ticket for this bug?
    3.16      func testForwardSubject() {
    3.17          let msg = getMockMessage()
    3.18          msg.shortMessage = Constant.crazySpaces + Constant.subject
    3.19 @@ -49,6 +51,7 @@
    3.20          // XCTAssertEqual failed: ("Fwd:       This is a subject") is not equal to ("Fwd: ")
    3.21      }
    3.22  
    3.23 +    // Create new ticket for this bug?
    3.24      func testForwardNonSubject() {
    3.25          let msg = getMockMessage()
    3.26          msg.shortMessage = nil
    3.27 @@ -84,10 +87,11 @@
    3.28          msg.sent = sentDate // ~ January 12, 1970 at 2:46:40 PM GMT+1
    3.29          msg.longMessageFormatted = Constant.longMessageHtmlFormatted
    3.30          let dateString = getDateFormattedString(date: sentDate)
    3.31 -        let exp = "\n\n\(String.pepSignature)\n\nSomeone wrote on \(dateString):\n\n> Test"
    3.32 +        let exp = "\n\n\(String.pepSignature)\n\nSomeone wrote on \(dateString):\n\n> Test\n> Test"
    3.33          let sth = ReplyUtil.quotedMessageText(message: msg, replyAll: false)
    3.34          XCTAssertEqual(sth, exp)
    3.35      }
    3.36 +
    3.37      func testQuotedMessageTextNotEmptySentDateIsUnknown() {
    3.38          let identity = Identity(address: "what@example.com",
    3.39                                  userID: "userID",
    3.40 @@ -98,12 +102,12 @@
    3.41          let msg = Message(uuid: "001", uid: 1, parentFolder: folder)
    3.42          msg.sent = nil
    3.43          msg.longMessageFormatted = Constant.longMessageHtmlFormatted
    3.44 -        let exp = "\n\n\(String.pepSignature)\n\nSomeone wrote:\n\n> Test"
    3.45 +        let exp = "\n\n\(String.pepSignature)\n\nSomeone wrote:\n\n> Test\n> Test"
    3.46          let sth = ReplyUtil.quotedMessageText(message: msg, replyAll: false)
    3.47          XCTAssertEqual(sth, exp)
    3.48      }
    3.49 -    // Failed because current implementation ReplyUtil.citedMessageText is wrong
    3.50 -    // We expect cited message not message without '>' characters
    3.51 +
    3.52 +    // Refer to IOS-1363
    3.53      func testCitedMessageTextNotEmptySentDateIsUnknown() {
    3.54          let identity = Identity(address: "what@example.com",
    3.55                                  userID: "userID",
    3.56 @@ -118,8 +122,9 @@
    3.57          let sth = ReplyUtil.citedMessageText(textToCite: "Test", fromMessage: msg)
    3.58          XCTAssertEqual(sth, exp,
    3.59                         showDifference(string1: sth, string2: exp))
    3.60 -        // Unexpected differences: Test != > Te
    3.61      }
    3.62 +
    3.63 +    // Refer to IOS-1363
    3.64      // Failed because current implementation ReplyUtil.citedMessageText is wrong
    3.65      // We expect cited message not message without '>' characters
    3.66      func testCitedHtmlMessageTextNotEmptySentDateIsUnknown() {
    3.67 @@ -133,13 +138,10 @@
    3.68          msg.sent = nil
    3.69          let bodyHtml = Constant.longMessageHtmlFormatted
    3.70          msg.longMessageFormatted = bodyHtml
    3.71 -        let exp = NSAttributedString(string: "\n\n\(String.pepSignature)\n\nSomeone wrote:\n\n\n> Test")
    3.72 +        let exp = NSAttributedString(string: "\n\n\(String.pepSignature)\n\nSomeone wrote:\n\n> Test\nTest\n")
    3.73          let sth = ReplyUtil.citedMessageText(textToCite: bodyHtml.htmlToAttributedString(attachmentDelegate: nil), fromMessage: msg)
    3.74 -
    3.75 -        // WIP: only temporary - message text will be removed
    3.76          XCTAssertEqual(sth.string, exp.string,
    3.77                         showDifference(string1: sth.string, string2: exp.string))
    3.78 -        // Unexpected differences: Test != > Te
    3.79      }
    3.80  }
    3.81  
    3.82 @@ -152,7 +154,7 @@
    3.83          static let expectedReplyPrefix = "Re: " // TODO: - Re: not localized!
    3.84          static let expectedForwardPrefix = NSLocalizedString("Fwd: ",
    3.85                                                               comment: "The 'Fwd:' that gets appended to the subject line")
    3.86 -        static let longMessageHtmlFormatted = "<html><body><p>Test</p></body></html>"
    3.87 +        static let longMessageHtmlFormatted = "<html><body><p>Test</p><p>Test</p></body></html>"
    3.88          static let crazySpaces = "     "
    3.89      }
    3.90      private func getDateFormattedString(date: Date) -> String {