pEpForiOSTests/UI/Compose/Cells/BodyCell/BodyCellViewModelTest.swift
author Dirk Zimmermann <dz@pep.security>
Wed, 23 Sep 2020 16:50:50 +0200
branchIOS-2259
changeset 15205 f2d94a86ef56
parent 13013 b2243c1de656
child 15206 4044ef5b3584
permissions -rw-r--r--
IOS-2259 Remove failing test
andreas@7068
     1
//
andreas@7068
     2
//  BodyCellViewModelTest.swift
andreas@7068
     3
//  pEpForiOSTests
andreas@7068
     4
//
andreas@7068
     5
//  Created by Andreas Buff on 08.11.18.
andreas@7068
     6
//  Copyright © 2018 p≡p Security S.A. All rights reserved.
andreas@7068
     7
//
andreas@7068
     8
andreas@7068
     9
import XCTest
andreas@7068
    10
andreas@7068
    11
@testable import pEpForiOS
andreas@7068
    12
import MessageModel
dz@13009
    13
import pEpIOSToolbox
andreas@7068
    14
andreas@7084
    15
class BodyCellViewModelTest: XCTestCase {
andreas@7071
    16
    var vm: BodyCellViewModel!
andreas@7088
    17
    private var testDelegate: TestDelegate?
andreas@7088
    18
    private var testResultDelegate: TestResultDelegate?
andreas@7071
    19
andreas@7071
    20
    // MARK: - inititalText
andreas@7071
    21
andreas@7071
    22
    func testInititalText_plain() {
andreas@7071
    23
        let intitialPlain = "intitial text"
andreas@7082
    24
        setupAssertionDelegates(initialPlaintext: intitialPlain,
andreas@7082
    25
                                initialAttributedText: nil,
andreas@7082
    26
                                initialInlinedAttachments: nil)
andreas@7071
    27
        let (text, _) = vm.inititalText()
andreas@7071
    28
        guard let testee = text else {
andreas@7071
    29
            XCTFail()
andreas@7071
    30
            return
andreas@7071
    31
        }
andreas@7071
    32
        XCTAssertEqual(testee, intitialPlain)
andreas@7071
    33
    }
andreas@7071
    34
andreas@7071
    35
    func testInititalText_html() {
andreas@7071
    36
        let intitialHtml = NSAttributedString(string: "intitial text")
andreas@7071
    37
        setupAssertionDelegates(initialPlaintext: nil,
andreas@7071
    38
                                initialAttributedText: intitialHtml,
andreas@7074
    39
                                initialInlinedAttachments: nil)
andreas@7071
    40
        let (_, html) = vm.inititalText()
andreas@7071
    41
        guard let testee = html else {
andreas@7071
    42
            XCTFail()
andreas@7071
    43
            return
andreas@7071
    44
        }
andreas@7071
    45
        XCTAssertEqual(testee, intitialHtml)
andreas@7071
    46
    }
andreas@7071
    47
andreas@7071
    48
    func testInititalText_both() {
andreas@7071
    49
        let intitialPlain = "intitial text"
andreas@7071
    50
        let initialHtml = NSAttributedString(string: "intitial text")
andreas@7071
    51
        setupAssertionDelegates(initialPlaintext: intitialPlain,
andreas@7071
    52
                                initialAttributedText: initialHtml,
andreas@7074
    53
                                initialInlinedAttachments: nil)
andreas@7071
    54
        let (text, html) = vm.inititalText()
andreas@7071
    55
        guard let testee = text else {
andreas@7071
    56
            XCTFail()
andreas@7071
    57
            return
andreas@7071
    58
        }
andreas@7071
    59
        guard let testeeHtml = html else {
andreas@7071
    60
            XCTFail()
andreas@7071
    61
            return
andreas@7071
    62
        }
andreas@7071
    63
        XCTAssertEqual(testee, intitialPlain)
andreas@7071
    64
        XCTAssertEqual(testeeHtml, initialHtml)
andreas@7071
    65
    }
andreas@7071
    66
andreas@7071
    67
    func testInititalText_noHtml() {
andreas@7071
    68
        let intitialPlain = "intitial text"
andreas@7082
    69
        setupAssertionDelegates(initialPlaintext: intitialPlain,
andreas@7082
    70
                                initialAttributedText: nil,
andreas@7082
    71
                                initialInlinedAttachments: nil)
andreas@7071
    72
        let (_, html) = vm.inititalText()
andreas@7071
    73
        XCTAssertNil(html)
andreas@7071
    74
    }
andreas@7071
    75
andreas@7071
    76
    func testInititalText_signatureSet() {
andreas@7071
    77
        let intitialHtml = NSAttributedString(string: "intitial text")
andreas@7071
    78
        setupAssertionDelegates(initialPlaintext: nil,
andreas@7071
    79
                                initialAttributedText: intitialHtml,
andreas@7074
    80
                                initialInlinedAttachments: nil)
andreas@7071
    81
        let (text, _) = vm.inititalText()
andreas@7071
    82
        XCTAssertEqual(text, .pepSignature)
andreas@7071
    83
    }
andreas@7071
    84
andreas@7071
    85
    func testInititalText_emptyInit_signatureSet() {
andreas@7071
    86
        setupAssertionDelegates(initialPlaintext: nil,
andreas@7071
    87
                                initialAttributedText: nil,
andreas@7074
    88
                                initialInlinedAttachments: nil)
andreas@7071
    89
        let (text, _) = vm.inititalText()
andreas@7071
    90
        XCTAssertEqual(text, .pepSignature)
andreas@7071
    91
    }
andreas@7071
    92
andreas@7074
    93
    // MARK: - Initial Inlined Attachents
andreas@7074
    94
andreas@7074
    95
    func testInitialAttachments() {
andreas@7077
    96
        let inlinedAttachments = createTestAttachments(numAttachments: 1)
andreas@7074
    97
        setupAssertionDelegates(initialPlaintext: nil,
andreas@7074
    98
                                initialAttributedText: nil,
andreas@7074
    99
                                initialInlinedAttachments: inlinedAttachments,
andreas@7074
   100
                                expectInsertCalled: nil,
andreas@7074
   101
                                inserted: nil,
andreas@7074
   102
                                expUserWantsToAddMediaCalled: nil,
andreas@7074
   103
                                expUserWantsToAddDocumentCalled: nil,
andreas@7082
   104
                                expInlinedAttachmentsCalled: expInlinedAttachmentChanged(mustBeCalled: false),
andreas@7074
   105
                                inlined: nil,
andreas@7074
   106
                                expBodyChangedCalled: nil,
andreas@7074
   107
                                exectedPlain: nil,
andreas@7074
   108
                                exectedHtml: nil)
andreas@7074
   109
        waitForExpectations(timeout: UnitTestUtils.waitTime)
andreas@7074
   110
    }
andreas@7074
   111
andreas@7074
   112
    // MARK: - handleTextChange
andreas@7074
   113
andreas@7074
   114
    func testHandleTextChange() {
andreas@7074
   115
        let newPlainText = "testPlainText"
andreas@7074
   116
        let newAttributedContent = "testAttributedText"
andreas@7074
   117
        let newAttributedText = NSAttributedString(string: newAttributedContent)
andreas@7074
   118
andreas@7074
   119
        let attributedTextWins = newAttributedContent
andreas@7074
   120
        let expectedPlainText = attributedTextWins
andreas@7074
   121
        let expectedHtml = htmlVersion(of: newAttributedContent)
andreas@7074
   122
andreas@7074
   123
        setupAssertionDelegates(initialPlaintext: nil,
andreas@7074
   124
                                initialAttributedText: nil,
andreas@7074
   125
                                initialInlinedAttachments: nil,
andreas@7074
   126
                                expectInsertCalled: expInsertTextCalled(mustBeCalled: false),
andreas@7074
   127
                                inserted: nil,
andreas@7074
   128
                                expUserWantsToAddMediaCalled: expUserWantsToAddMediaCalled(mustBeCalled: false),
andreas@7077
   129
                                expUserWantsToAddDocumentCalled: expUserWantsToAddDocumentCalled(mustBeCalled: false),
andreas@7074
   130
                                expInlinedAttachmentsCalled: expInlinedAttachmentChanged(mustBeCalled: false),
andreas@7074
   131
                                inlined: nil,
andreas@7074
   132
                                expBodyChangedCalled: expBodyChangedCalled(mustBeCalled: true),
andreas@7074
   133
                                exectedPlain: expectedPlainText,
andreas@7074
   134
                                exectedHtml: expectedHtml)
andreas@7074
   135
        vm.handleTextChange(newText: newPlainText, newAttributedText: newAttributedText)
andreas@7074
   136
        waitForExpectations(timeout: UnitTestUtils.waitTime)
andreas@7074
   137
    }
andreas@7074
   138
andreas@7074
   139
    func testHandleTextChange_initialTextSet() {
andreas@7074
   140
        let initText = "initText"
andreas@7074
   141
        let initAttributedText = NSAttributedString(string: "initAttributedText")
andreas@7074
   142
andreas@7074
   143
        let newPlainText = "testPlainText"
andreas@7074
   144
        let newAttributedContent = "testAttributedText"
andreas@7074
   145
        let newAttributedText = NSAttributedString(string: newAttributedContent)
andreas@7074
   146
andreas@7074
   147
        let attributedTextWins = newAttributedContent
andreas@7074
   148
andreas@7074
   149
        let expectedPlainText = attributedTextWins
andreas@7074
   150
        let expectedHtml = htmlVersion(of: newAttributedContent)
andreas@7074
   151
andreas@7074
   152
        setupAssertionDelegates(initialPlaintext: initText,
andreas@7074
   153
                                initialAttributedText: initAttributedText,
andreas@7074
   154
                                initialInlinedAttachments: nil,
andreas@7074
   155
                                expectInsertCalled: expInsertTextCalled(mustBeCalled: false),
andreas@7074
   156
                                inserted: nil,
andreas@7074
   157
                                expUserWantsToAddMediaCalled: expUserWantsToAddMediaCalled(mustBeCalled: false),
andreas@7077
   158
                                expUserWantsToAddDocumentCalled: expUserWantsToAddDocumentCalled(mustBeCalled: false),
andreas@7074
   159
                                expInlinedAttachmentsCalled: expInlinedAttachmentChanged(mustBeCalled: false),
andreas@7074
   160
                                inlined: nil,
andreas@7074
   161
                                expBodyChangedCalled: expBodyChangedCalled(mustBeCalled: true),
andreas@7074
   162
                                exectedPlain: expectedPlainText,
andreas@7074
   163
                                exectedHtml: expectedHtml)
andreas@7074
   164
        vm.handleTextChange(newText: newPlainText, newAttributedText: newAttributedText)
andreas@7074
   165
        waitForExpectations(timeout: UnitTestUtils.waitTime)
andreas@7074
   166
    }
andreas@7074
   167
andreas@7074
   168
    func testHandleTextChange_notCalled() {
andreas@7074
   169
        setupAssertionDelegates(initialPlaintext: nil,
andreas@7074
   170
                                initialAttributedText: nil,
andreas@7074
   171
                                initialInlinedAttachments: nil,
andreas@7074
   172
                                expectInsertCalled: expInsertTextCalled(mustBeCalled: false),
andreas@7074
   173
                                inserted: nil,
andreas@7074
   174
                                expUserWantsToAddMediaCalled: expUserWantsToAddMediaCalled(mustBeCalled: false),
andreas@7077
   175
                                expUserWantsToAddDocumentCalled: expUserWantsToAddDocumentCalled(mustBeCalled: false),
andreas@7074
   176
                                expInlinedAttachmentsCalled: expInlinedAttachmentChanged(mustBeCalled: false),
andreas@7074
   177
                                inlined: nil,
andreas@7074
   178
                                expBodyChangedCalled: expBodyChangedCalled(mustBeCalled: false),
andreas@7074
   179
                                exectedPlain: nil,
andreas@7074
   180
                                exectedHtml: nil)
andreas@7074
   181
        // We do not call handleTextChange, so no callback should be called.
andreas@7074
   182
        waitForExpectations(timeout: UnitTestUtils.waitTime)
andreas@7074
   183
    }
andreas@7074
   184
andreas@7075
   185
    // MARK: - inline(attachment:
andreas@7074
   186
andreas@7075
   187
    func testInlineAttachment_called() {
andreas@7077
   188
        let attachment = createTestAttachment(addImage: true)
andreas@7075
   189
        setupAssertionDelegates(initialPlaintext: nil,
andreas@7075
   190
                                initialAttributedText: nil,
andreas@7075
   191
                                initialInlinedAttachments: nil,
andreas@7075
   192
                                expectInsertCalled: expInsertTextCalled(mustBeCalled: true),
andreas@7075
   193
                                inserted: nil,
andreas@7075
   194
                                expUserWantsToAddMediaCalled: expUserWantsToAddMediaCalled(mustBeCalled: false),
andreas@7077
   195
                                expUserWantsToAddDocumentCalled: expUserWantsToAddDocumentCalled(mustBeCalled: false),
andreas@7075
   196
                                expInlinedAttachmentsCalled: expInlinedAttachmentChanged(mustBeCalled: true),
andreas@7075
   197
                                inlined: [attachment],
andreas@7075
   198
                                expBodyChangedCalled: expBodyChangedCalled(mustBeCalled: false),
andreas@7075
   199
                                exectedPlain: nil,
andreas@7075
   200
                                exectedHtml: nil)
andreas@7075
   201
        let nonZeroValue: CGFloat = 300.0
andreas@7075
   202
        vm.maxTextattachmentWidth = nonZeroValue
andreas@7075
   203
        vm.inline(attachment: attachment)
andreas@7075
   204
        waitForExpectations(timeout: UnitTestUtils.waitTime)
andreas@7075
   205
    }
andreas@7075
   206
andreas@7075
   207
    func testInlineAttachment_notCalled() {
andreas@7075
   208
        setupAssertionDelegates(initialPlaintext: nil,
andreas@7075
   209
                                initialAttributedText: nil,
andreas@7075
   210
                                initialInlinedAttachments: nil,
andreas@7075
   211
                                expectInsertCalled: expInsertTextCalled(mustBeCalled: false),
andreas@7075
   212
                                inserted: nil,
andreas@7075
   213
                                expUserWantsToAddMediaCalled: expUserWantsToAddMediaCalled(mustBeCalled: false),
andreas@7077
   214
                                expUserWantsToAddDocumentCalled: expUserWantsToAddDocumentCalled(mustBeCalled: false),
andreas@7075
   215
                                expInlinedAttachmentsCalled: expInlinedAttachmentChanged(mustBeCalled: false),
andreas@7075
   216
                                inlined: nil,
andreas@7075
   217
                                expBodyChangedCalled: expBodyChangedCalled(mustBeCalled: false),
andreas@7075
   218
                                exectedPlain: nil,
andreas@7075
   219
                                exectedHtml: nil)
andreas@7075
   220
        let nonZeroValue: CGFloat = 300.0
andreas@7075
   221
        vm.maxTextattachmentWidth = nonZeroValue
andreas@7075
   222
        waitForExpectations(timeout: UnitTestUtils.waitTime)
andreas@7075
   223
    }
andreas@7068
   224
andreas@7076
   225
    // MARK: - shouldReplaceText(in range:of text:with replaceText:)
andreas@7076
   226
andreas@7077
   227
    func testShouldReplaceText_noAttachment_replacetextEmpty() {
andreas@7076
   228
        let testText = NSAttributedString(string: "Test text")
andreas@7077
   229
        let testRange = NSRange(location: 0, length: "Test".count)
andreas@7077
   230
        let testReplaceText = ""
andreas@7076
   231
andreas@7076
   232
        setupAssertionDelegates(initialPlaintext: nil,
andreas@7076
   233
                                initialAttributedText: nil,
andreas@7076
   234
                                initialInlinedAttachments: nil,
andreas@7076
   235
                                expectInsertCalled: expInsertTextCalled(mustBeCalled: false),
andreas@7076
   236
                                inserted: nil,
andreas@7076
   237
                                expUserWantsToAddMediaCalled: expUserWantsToAddMediaCalled(mustBeCalled: false),
andreas@7077
   238
                                expUserWantsToAddDocumentCalled: expUserWantsToAddDocumentCalled(mustBeCalled: false),
andreas@7076
   239
                                expInlinedAttachmentsCalled: expInlinedAttachmentChanged(mustBeCalled: false),
andreas@7076
   240
                                inlined: nil,
andreas@7076
   241
                                expBodyChangedCalled: expBodyChangedCalled(mustBeCalled: false),
andreas@7076
   242
                                exectedPlain: nil,
andreas@7076
   243
                                exectedHtml: nil)
andreas@7077
   244
        let shouldReplace = vm.shouldReplaceText(in: testRange, of: testText, with: testReplaceText)
andreas@7077
   245
        XCTAssertTrue(shouldReplace, "Should alway be true")
andreas@7076
   246
        waitForExpectations(timeout: UnitTestUtils.waitTime)
andreas@7076
   247
    }
andreas@7076
   248
andreas@7077
   249
    func testShouldReplaceText_noAttachment_replacetextNonEmpty() {
andreas@7077
   250
        let testText = NSAttributedString(string: "Test text")
andreas@7077
   251
        let testRange = NSRange(location: 0, length: "Test".count)
andreas@7077
   252
        let testReplaceText = "Replace"
andreas@7077
   253
andreas@7077
   254
        setupAssertionDelegates(initialPlaintext: nil,
andreas@7077
   255
                                initialAttributedText: nil,
andreas@7077
   256
                                initialInlinedAttachments: nil,
andreas@7077
   257
                                expectInsertCalled: expInsertTextCalled(mustBeCalled: false),
andreas@7077
   258
                                inserted: nil,
andreas@7077
   259
                                expUserWantsToAddMediaCalled: expUserWantsToAddMediaCalled(mustBeCalled: false),
andreas@7077
   260
                                expUserWantsToAddDocumentCalled: expUserWantsToAddDocumentCalled(mustBeCalled: false),
andreas@7077
   261
                                expInlinedAttachmentsCalled: expInlinedAttachmentChanged(mustBeCalled: false),
andreas@7077
   262
                                inlined: nil,
andreas@7077
   263
                                expBodyChangedCalled: expBodyChangedCalled(mustBeCalled: false),
andreas@7077
   264
                                exectedPlain: nil,
andreas@7077
   265
                                exectedHtml: nil)
andreas@7077
   266
        let shouldReplace = vm.shouldReplaceText(in: testRange, of: testText, with: testReplaceText)
andreas@7077
   267
        XCTAssertTrue(shouldReplace, "Should alway be true")
andreas@7077
   268
        waitForExpectations(timeout: UnitTestUtils.waitTime)
andreas@7077
   269
    }
andreas@7077
   270
andreas@7077
   271
    func testShouldReplaceText_noAttachment_replacetextNewLine() {
andreas@7077
   272
        let testText = NSAttributedString(string: "Test text")
andreas@7077
   273
        let testRange = NSRange(location: 0, length: "Test".count)
andreas@7077
   274
        let testReplaceText = "\n"
andreas@7077
   275
andreas@7077
   276
        setupAssertionDelegates(initialPlaintext: nil,
andreas@7077
   277
                                initialAttributedText: nil,
andreas@7077
   278
                                initialInlinedAttachments: nil,
andreas@7077
   279
                                expectInsertCalled: expInsertTextCalled(mustBeCalled: false),
andreas@7077
   280
                                inserted: nil,
andreas@7077
   281
                                expUserWantsToAddMediaCalled: expUserWantsToAddMediaCalled(mustBeCalled: false),
andreas@7077
   282
                                expUserWantsToAddDocumentCalled: expUserWantsToAddDocumentCalled(mustBeCalled: false),
andreas@7077
   283
                                expInlinedAttachmentsCalled: expInlinedAttachmentChanged(mustBeCalled: false),
andreas@7077
   284
                                inlined: nil,
andreas@7077
   285
                                expBodyChangedCalled: expBodyChangedCalled(mustBeCalled: false),
andreas@7077
   286
                                exectedPlain: nil,
andreas@7077
   287
                                exectedHtml: nil)
andreas@7077
   288
        let shouldReplace = vm.shouldReplaceText(in: testRange, of: testText, with: testReplaceText)
andreas@7077
   289
        XCTAssertTrue(shouldReplace, "Should alway be true")
andreas@7077
   290
        waitForExpectations(timeout: UnitTestUtils.waitTime)
andreas@7077
   291
    }
andreas@7077
   292
andreas@7077
   293
    func testShouldReplaceText_attachment_removeNone() {
andreas@7077
   294
        let textBuilder = NSAttributedString(string: "Test text")
andreas@7077
   295
        let replaceText = ""
andreas@7077
   296
andreas@7077
   297
        let insertRange = NSRange(location: "Test".count, length: 1)
andreas@7077
   298
        let testAttachment = createTestAttachment(addImage: true)
andreas@7077
   299
        let testText = insertTextattachment(for: testAttachment, in: insertRange, of: textBuilder)
andreas@7077
   300
        let testRange = NSRange(location: 0, length: "Test".count)
andreas@7077
   301
        XCTAssertTrue(testText.textAttachments(range: testRange).count == 0)
andreas@7077
   302
andreas@7077
   303
        setupAssertionDelegates(initialPlaintext: nil,
andreas@7077
   304
                                initialAttributedText: nil,
andreas@7077
   305
                                initialInlinedAttachments: [testAttachment],
andreas@7077
   306
                                expectInsertCalled: expInsertTextCalled(mustBeCalled: false),
andreas@7077
   307
                                inserted: nil,
andreas@7077
   308
                                expUserWantsToAddMediaCalled: expUserWantsToAddMediaCalled(mustBeCalled: false),
andreas@7077
   309
                                expUserWantsToAddDocumentCalled: expUserWantsToAddDocumentCalled(mustBeCalled: false),
andreas@7077
   310
                                expInlinedAttachmentsCalled: expInlinedAttachmentChanged(mustBeCalled: false),
andreas@7077
   311
                                inlined: nil,
andreas@7077
   312
                                expBodyChangedCalled: expBodyChangedCalled(mustBeCalled: false),
andreas@7077
   313
                                exectedPlain: nil,
andreas@7077
   314
                                exectedHtml: nil)
andreas@7077
   315
        let shouldReplace = vm.shouldReplaceText(in: testRange, of: testText, with: replaceText)
andreas@7077
   316
        XCTAssertTrue(shouldReplace, "Should alway be true")
andreas@7077
   317
        waitForExpectations(timeout: UnitTestUtils.waitTime)
andreas@7077
   318
    }
andreas@7077
   319
andreas@7077
   320
    func testShouldReplaceText_attachment_removeAll() {
andreas@7077
   321
        var textBuilder = NSAttributedString(string: "Test text")
andreas@7077
   322
        let replaceText = ""
andreas@7077
   323
        let replaceRange = NSRange(location: 0, length: "Test".count)
andreas@7077
   324
andreas@7077
   325
        let testAttachment1 = createTestAttachment(addImage: true)
andreas@7077
   326
        textBuilder = insertTextattachment(for: testAttachment1, in: replaceRange, of: textBuilder)
andreas@7077
   327
        let testAttachment2 = createTestAttachment(addImage: true)
andreas@7077
   328
        let testText = insertTextattachment(for: testAttachment2, in: replaceRange, of: textBuilder)
andreas@7077
   329
        let attachmentRange = NSRange(location: 0, length: testText.length)
andreas@7077
   330
        XCTAssertTrue(testText.textAttachments(range: attachmentRange).count == 1)
andreas@7077
   331
andreas@7077
   332
        let expectNoAttachmentLeft = [Attachment]()
andreas@7077
   333
andreas@7077
   334
        setupAssertionDelegates(initialPlaintext: nil,
andreas@7077
   335
                                initialAttributedText: nil,
andreas@7077
   336
                                initialInlinedAttachments: nil,
andreas@7077
   337
                                expectInsertCalled: expInsertTextCalled(mustBeCalled: false),
andreas@7077
   338
                                inserted: nil,
andreas@7077
   339
                                expUserWantsToAddMediaCalled: expUserWantsToAddMediaCalled(mustBeCalled: false),
andreas@7077
   340
                                expUserWantsToAddDocumentCalled: expUserWantsToAddDocumentCalled(mustBeCalled: false),
andreas@7077
   341
                                expInlinedAttachmentsCalled: expInlinedAttachmentChanged(mustBeCalled: true),
andreas@7077
   342
                                inlined: expectNoAttachmentLeft,
andreas@7077
   343
                                expBodyChangedCalled: expBodyChangedCalled(mustBeCalled: false),
andreas@7077
   344
                                exectedPlain: nil,
andreas@7077
   345
                                exectedHtml: nil)
andreas@7077
   346
        let shouldReplace = vm.shouldReplaceText(in: attachmentRange, of: testText, with: replaceText)
andreas@7077
   347
        XCTAssertTrue(shouldReplace, "Should alway be true")
andreas@7077
   348
        waitForExpectations(timeout: UnitTestUtils.waitTime)
andreas@7077
   349
    }
andreas@7077
   350
andreas@7077
   351
    func testShouldReplaceText_attachment_removeOne() {
andreas@7077
   352
        var textBuilder = NSAttributedString(string: "Test text")
andreas@7077
   353
        let replaceText = ""
andreas@7077
   354
        let replaceRange = NSRange(location: 0, length: 0)
andreas@7077
   355
andreas@7077
   356
        let testAttachment1 = createTestAttachment(fileName: "1", addImage: true)
andreas@7077
   357
        textBuilder = insertTextattachment(for: testAttachment1, in: replaceRange, of: textBuilder)
andreas@7077
   358
        let testAttachment2 = createTestAttachment(fileName: "2", addImage: true)
andreas@7077
   359
        let testText = insertTextattachment(for: testAttachment2, in: replaceRange, of: textBuilder)
andreas@7077
   360
        let attachmentToRemoveRange = NSRange(location: 0, length: 1)
andreas@7077
   361
andreas@7077
   362
        let expectedAttachmentsLeft = [testAttachment1]
andreas@7077
   363
        XCTAssertTrue(testText.textAttachments(range: attachmentToRemoveRange).count == 1)
andreas@7077
   364
andreas@7077
   365
        setupAssertionDelegates(initialPlaintext: nil,
andreas@7077
   366
                                initialAttributedText: nil,
andreas@7077
   367
                                initialInlinedAttachments: [testAttachment1, testAttachment2],
andreas@7077
   368
                                expectInsertCalled: nil,
andreas@7077
   369
                                inserted: nil,
andreas@7077
   370
                                expUserWantsToAddMediaCalled: expUserWantsToAddMediaCalled(mustBeCalled: false),
andreas@7077
   371
                                expUserWantsToAddDocumentCalled: expUserWantsToAddDocumentCalled(mustBeCalled: false),
andreas@7077
   372
                                expInlinedAttachmentsCalled: expInlinedAttachmentChanged(mustBeCalled: true),
andreas@7077
   373
                                inlined: expectedAttachmentsLeft,
andreas@7077
   374
                                expBodyChangedCalled: expBodyChangedCalled(mustBeCalled: false),
andreas@7077
   375
                                exectedPlain: nil,
andreas@7077
   376
                                exectedHtml: nil)
andreas@7077
   377
        let shouldReplace = vm.shouldReplaceText(in: attachmentToRemoveRange,
andreas@7077
   378
                                                 of: testText,
andreas@7077
   379
                                                 with: replaceText)
andreas@7077
   380
        XCTAssertTrue(shouldReplace, "Should alway be true")
andreas@7077
   381
        waitForExpectations(timeout: UnitTestUtils.waitTime)
andreas@7077
   382
    }
andreas@7077
   383
alejandro@9541
   384
    func testShouldReplaceText_attachment_multipleRemove() {
alejandro@9541
   385
        let attachmentsToRemoveCount = 10
alejandro@9541
   386
        shouldReplaceText_attachment(remove: attachmentsToRemoveCount)
agp@9524
   387
    }
agp@9524
   388
    func shouldReplaceText_attachment (remove: Int) {
agp@9524
   389
        var textBuilder = NSAttributedString(string: "Test text")
agp@9524
   390
        let range = NSRange(location: 0, length: 0)
agp@9524
   391
        var initialAttachments = [Attachment]()
agp@9524
   392
agp@9524
   393
        for i in 0..<remove {
agp@9524
   394
            let testAttachment = createTestAttachment(fileName: String(i), addImage: true)
agp@9524
   395
            textBuilder = insertTextattachment(for: testAttachment, in: range, of: textBuilder)
agp@9524
   396
            initialAttachments.append(testAttachment)
agp@9524
   397
        }
agp@9524
   398
agp@9524
   399
        let attachmentToRemoveRange = NSRange(location: 0, length: textBuilder.length)
agp@9524
   400
        let expectedAttachmentsLeft = [Attachment]()
agp@9524
   401
agp@9524
   402
        setupAssertionDelegates(initialPlaintext: nil,
agp@9524
   403
                                initialAttributedText: nil,
agp@9524
   404
                                initialInlinedAttachments: initialAttachments,
agp@9524
   405
                                expectInsertCalled: nil,
agp@9524
   406
                                inserted: nil,
agp@9524
   407
                                expUserWantsToAddMediaCalled: expUserWantsToAddMediaCalled(mustBeCalled: false),
agp@9524
   408
                                expUserWantsToAddDocumentCalled: expUserWantsToAddDocumentCalled(mustBeCalled: false),
agp@9524
   409
                                expInlinedAttachmentsCalled: expInlinedAttachmentChanged(mustBeCalled: true),
agp@9524
   410
                                inlined: expectedAttachmentsLeft,
agp@9524
   411
                                expBodyChangedCalled: expBodyChangedCalled(mustBeCalled: false),
agp@9524
   412
                                exectedPlain: nil,
agp@9524
   413
                                exectedHtml: nil)
agp@9524
   414
        let shouldReplace = vm.shouldReplaceText(in: attachmentToRemoveRange,
agp@9524
   415
                                                 of: textBuilder,
agp@9524
   416
                                                 with: "")
agp@9524
   417
        XCTAssertTrue(shouldReplace, "Should alway be true")
agp@9524
   418
        waitForExpectations(timeout: UnitTestUtils.waitTime)
agp@9524
   419
    }
agp@9524
   420
andreas@7078
   421
    // MARK: handleUserClickedSelectMedia
andreas@7078
   422
andreas@7078
   423
    func testHandleUserClickedSelectMedia() {
andreas@7078
   424
        setupAssertionDelegates(initialPlaintext: nil,
andreas@7078
   425
                                initialAttributedText: nil,
andreas@7078
   426
                                initialInlinedAttachments: nil,
andreas@7078
   427
                                expectInsertCalled: expInsertTextCalled(mustBeCalled: false),
andreas@7078
   428
                                inserted: nil,
andreas@7078
   429
                                expUserWantsToAddMediaCalled: expUserWantsToAddMediaCalled(mustBeCalled: true),
andreas@7078
   430
                                expUserWantsToAddDocumentCalled: expUserWantsToAddDocumentCalled(mustBeCalled: false),
andreas@7078
   431
                                expInlinedAttachmentsCalled: expInlinedAttachmentChanged(mustBeCalled: false),
andreas@7078
   432
                                inlined: nil,
andreas@7078
   433
                                expBodyChangedCalled: expBodyChangedCalled(mustBeCalled: false),
andreas@7078
   434
                                exectedPlain: nil,
andreas@7078
   435
                                exectedHtml: nil)
andreas@7078
   436
       vm.handleUserClickedSelectMedia()
andreas@7078
   437
        waitForExpectations(timeout: UnitTestUtils.waitTime)
andreas@7078
   438
    }
andreas@7078
   439
andreas@7078
   440
    // MARK: handleUserClickedSelectDocument
andreas@7078
   441
andreas@7078
   442
    func testHandleUserClickedSelectDocument() {
andreas@7078
   443
        setupAssertionDelegates(initialPlaintext: nil,
andreas@7078
   444
                                initialAttributedText: nil,
andreas@7078
   445
                                initialInlinedAttachments: nil,
andreas@7078
   446
                                expectInsertCalled: expInsertTextCalled(mustBeCalled: false),
andreas@7078
   447
                                inserted: nil,
andreas@7078
   448
                                expUserWantsToAddMediaCalled: expUserWantsToAddMediaCalled(mustBeCalled: false),
andreas@7078
   449
                                expUserWantsToAddDocumentCalled: expUserWantsToAddDocumentCalled(mustBeCalled: true),
andreas@7078
   450
                                expInlinedAttachmentsCalled: expInlinedAttachmentChanged(mustBeCalled: false),
andreas@7078
   451
                                inlined: nil,
andreas@7078
   452
                                expBodyChangedCalled: expBodyChangedCalled(mustBeCalled: false),
andreas@7078
   453
                                exectedPlain: nil,
andreas@7078
   454
                                exectedHtml: nil)
andreas@7078
   455
        vm.handleUserClickedSelectDocument()
andreas@7078
   456
        waitForExpectations(timeout: UnitTestUtils.waitTime)
andreas@7078
   457
    }
andreas@7077
   458
andreas@7079
   459
    // MARK: handleCursorPositionChange
andreas@7068
   460
andreas@7079
   461
    func testHandleCursorPositionChange_cursorBehindInlinedAttachment() {
andreas@7079
   462
        setupAssertionDelegates(initialPlaintext: nil,
andreas@7079
   463
                                initialAttributedText: nil,
andreas@7079
   464
                                initialInlinedAttachments: nil,
andreas@7079
   465
                                expectInsertCalled: expInsertTextCalled(mustBeCalled: false),
andreas@7079
   466
                                inserted: nil,
andreas@7079
   467
                                expUserWantsToAddMediaCalled: nil,
andreas@7079
   468
                                expUserWantsToAddDocumentCalled: nil,
andreas@7079
   469
                                expInlinedAttachmentsCalled: nil,
andreas@7079
   470
                                inlined: nil,
andreas@7079
   471
                                expBodyChangedCalled: expBodyChangedCalled(mustBeCalled: false),
andreas@7079
   472
                                exectedPlain: nil,
andreas@7079
   473
                                exectedHtml: nil)
andreas@7079
   474
        let testPosition = 1
andreas@7079
   475
        vm.handleCursorPositionChange(newPosition: testPosition)
andreas@7079
   476
        vm.handleUserClickedSelectMedia()
andreas@7079
   477
        let inlinedImage = 1
andreas@7079
   478
        let expectedPosition = testPosition + inlinedImage
andreas@7079
   479
        XCTAssertEqual(vm.cursorPosition, expectedPosition,
andreas@7079
   480
                       "cursor should be placed behind inlined image")
andreas@7079
   481
        waitForExpectations(timeout: UnitTestUtils.waitTime)
andreas@7079
   482
    }
andreas@7068
   483
andreas@7079
   484
    func testHandleCursorPositionChange_noChangeAddingAttachment() {
andreas@7079
   485
        setupAssertionDelegates(initialPlaintext: nil,
andreas@7079
   486
                                initialAttributedText: nil,
andreas@7079
   487
                                initialInlinedAttachments: nil,
andreas@7079
   488
                                expectInsertCalled: expInsertTextCalled(mustBeCalled: false),
andreas@7079
   489
                                inserted: nil,
andreas@7079
   490
                                expUserWantsToAddMediaCalled: nil,
andreas@7079
   491
                                expUserWantsToAddDocumentCalled: nil,
andreas@7079
   492
                                expInlinedAttachmentsCalled: nil,
andreas@7079
   493
                                inlined: nil,
andreas@7079
   494
                                expBodyChangedCalled: expBodyChangedCalled(mustBeCalled: false),
andreas@7079
   495
                                exectedPlain: nil,
andreas@7079
   496
                                exectedHtml: nil)
andreas@7079
   497
        let testPosition = 1
andreas@7079
   498
        vm.handleCursorPositionChange(newPosition: testPosition)
andreas@7079
   499
        vm.handleUserClickedSelectDocument()
andreas@7079
   500
        let expectedPosition = testPosition
andreas@7079
   501
        XCTAssertEqual(vm.cursorPosition, expectedPosition,
andreas@7079
   502
                       "cursor position does not change attaching an non-ilined image")
andreas@7079
   503
        waitForExpectations(timeout: UnitTestUtils.waitTime)
andreas@7079
   504
    }
andreas@7068
   505
andreas@7071
   506
    // MARK: - Helpers
andreas@7071
   507
andreas@7071
   508
    private func setupAssertionDelegates(
andreas@7074
   509
        initialPlaintext: String? = nil, initialAttributedText: NSAttributedString? = nil, initialInlinedAttachments: [Attachment]? = nil,
andreas@7071
   510
        expectInsertCalled: XCTestExpectation? = nil, inserted: NSAttributedString? = nil,
andreas@7071
   511
andreas@7071
   512
        expUserWantsToAddMediaCalled: XCTestExpectation? = nil,
andreas@7071
   513
        expUserWantsToAddDocumentCalled: XCTestExpectation? = nil,
andreas@7074
   514
        expInlinedAttachmentsCalled: XCTestExpectation? = nil, inlined: [Attachment]? = nil,
andreas@7071
   515
        expBodyChangedCalled: XCTestExpectation? = nil, exectedPlain: String? = nil, exectedHtml: String? = nil) {
andreas@7071
   516
        // Delegate
andreas@7088
   517
        testDelegate = TestDelegate(expectInsertCalled: expectInsertCalled, inserted: inserted)
andreas@7071
   518
andreas@7071
   519
        // Result Delegate
andreas@7071
   520
        let newTestResultDelegate =
andreas@7088
   521
            TestResultDelegate(
andreas@7071
   522
                expUserWantsToAddMediaCalled: expUserWantsToAddMediaCalled, expUserWantsToAddDocumentCalled: expUserWantsToAddDocumentCalled,
andreas@7074
   523
                expInlinedAttachmentsCalled: expInlinedAttachmentsCalled, inlined: inlined,
andreas@7071
   524
                expBodyChangedCalled: expBodyChangedCalled, exectedPlain: exectedPlain, exectedHtml: exectedHtml)
andreas@7071
   525
        testResultDelegate = newTestResultDelegate
andreas@7071
   526
        vm = BodyCellViewModel(resultDelegate: newTestResultDelegate,
andreas@7071
   527
                               initialPlaintext: initialPlaintext,
andreas@7071
   528
                               initialAttributedText: initialAttributedText,
andreas@7074
   529
                               inlinedAttachments: initialInlinedAttachments)
andreas@7071
   530
        vm.delegate = testDelegate
andreas@7077
   531
        let aNonNullValue: CGFloat = 300.0
andreas@7077
   532
        vm.maxTextattachmentWidth = aNonNullValue
andreas@7071
   533
    }
andreas@7071
   534
andreas@7077
   535
    private func createTestAttachment(data: Data? = nil,
andreas@7076
   536
                                mimeType: String = "test/mimeType",
andreas@7076
   537
                                fileName: String? = nil,
andreas@7076
   538
                                size: Int? = nil,
andreas@7076
   539
                                url: URL? = nil,
andreas@7076
   540
                                addImage: Bool = false,
andreas@7076
   541
                                assetUrl: URL? = nil,
andreas@7076
   542
                                contentDisposition: Attachment.ContentDispositionType = .inline) -> Attachment {
andreas@7077
   543
        guard let att = createTestAttachments(numAttachments: 1,
andreas@7076
   544
                                        data: data,
andreas@7076
   545
                                        mimeType: mimeType,
andreas@7076
   546
                                        fileName: fileName,
andreas@7076
   547
                                        size: size,
andreas@7076
   548
                                        url: url,
andreas@7076
   549
                                        addImage: addImage,
andreas@7076
   550
                                        assetUrl: assetUrl,
andreas@7076
   551
                                        contentDisposition: contentDisposition).first else {
andreas@7076
   552
            XCTFail()
andreas@7076
   553
            return Attachment(data: Data(), mimeType: "", contentDisposition: .other)
andreas@7076
   554
        }
andreas@7076
   555
        return att
andreas@7076
   556
    }
andreas@7076
   557
andreas@7077
   558
    private func createTestAttachments(numAttachments: Int = 1,
andreas@7074
   559
                                 data: Data? = nil,
andreas@7074
   560
                                 mimeType: String = "test/mimeType",
andreas@7074
   561
                                 fileName: String? = nil,
andreas@7074
   562
                                 size: Int? = nil,
andreas@7074
   563
                                 url: URL? = nil,
andreas@7075
   564
                                 addImage: Bool = false,
andreas@7074
   565
                                 assetUrl: URL? = nil,
andreas@7074
   566
                                 contentDisposition: Attachment.ContentDispositionType = .inline)
andreas@7074
   567
        -> [Attachment] {
andreas@7075
   568
            var attachments = [Attachment]()
andreas@7075
   569
            let imageFileName = "PorpoiseGalaxy_HubbleFraile_960.jpg" //IOS-1399: move to Utils
andreas@7075
   570
            guard
dz@13013
   571
                let imageData = MiscUtil.loadData(bundleClass: BodyCellViewModelTest.self,
dz@13013
   572
                                                  fileName: imageFileName),
andreas@7075
   573
                let image = UIImage(data: imageData) else {
andreas@7075
   574
                    XCTFail("No img")
andreas@7075
   575
                    return []
andreas@7075
   576
            }
andreas@7075
   577
andreas@7075
   578
            for i in 0..<numAttachments {
andreas@7075
   579
                attachments.append(Attachment(data: data,
andreas@7075
   580
                                              mimeType: mimeType,
andreas@7077
   581
                                              fileName: fileName == nil ? "\(i)" : fileName,
andreas@8047
   582
                                              image: addImage ? image : nil,
andreas@8047
   583
                                              assetUrl: assetUrl,
andreas@8047
   584
                                              contentDisposition: contentDisposition))
andreas@7075
   585
            }
andreas@7075
   586
            return attachments
andreas@7074
   587
    }
andreas@7074
   588
andreas@7074
   589
    private func htmlVersion(of string: String) -> String {
andreas@7074
   590
        return string.isEmpty ? string : "<p>" + string + "</p>" + "\n"
andreas@7074
   591
    }
andreas@7074
   592
andreas@7074
   593
    private func expInsertTextCalled(mustBeCalled: Bool) -> XCTestExpectation {
andreas@7074
   594
        return expectation(inverted: !mustBeCalled)
andreas@7074
   595
    }
andreas@7074
   596
andreas@7074
   597
    private func expUserWantsToAddMediaCalled(mustBeCalled: Bool) -> XCTestExpectation {
andreas@7074
   598
        return expectation(inverted: !mustBeCalled)
andreas@7074
   599
    }
andreas@7074
   600
andreas@7074
   601
    private func expUserWantsToAddDocumentCalled(mustBeCalled: Bool) -> XCTestExpectation {
andreas@7074
   602
        return expectation(inverted: !mustBeCalled)
andreas@7074
   603
    }
andreas@7074
   604
andreas@7074
   605
    private func expInlinedAttachmentChanged(mustBeCalled: Bool) -> XCTestExpectation {
andreas@7074
   606
        return expectation(inverted: !mustBeCalled)
andreas@7074
   607
    }
andreas@7074
   608
andreas@7074
   609
    private func expBodyChangedCalled(mustBeCalled: Bool) -> XCTestExpectation {
andreas@7074
   610
        return expectation(inverted: !mustBeCalled)
andreas@7074
   611
    }
andreas@7074
   612
andreas@7077
   613
    private func insertTextattachment(for attachment: Attachment,
andreas@7077
   614
                                      in range: NSRange,
andreas@7077
   615
                                      of string: NSAttributedString) -> NSAttributedString {
andreas@7077
   616
        let attachmentString = textAttachmentString(for: attachment)
andreas@7077
   617
        return insert(text: attachmentString, in: range, of: string)
andreas@7077
   618
    }
andreas@7077
   619
andreas@7077
   620
    private func textAttachmentString(for attachment: Attachment) -> NSAttributedString {
andreas@7077
   621
        guard let image = attachment.image else {
dz@7476
   622
            XCTFail("No image")
andreas@7077
   623
            return NSAttributedString()
andreas@7077
   624
        }
andreas@7077
   625
        attachment.contentDisposition = .inline
andreas@7077
   626
        let textAttachment = TextAttachment()
andreas@7077
   627
        textAttachment.image = image
andreas@7077
   628
        textAttachment.attachment = attachment
andreas@7077
   629
        let imageString = NSAttributedString(attachment: textAttachment)
andreas@7077
   630
        return imageString
andreas@7077
   631
    }
andreas@7077
   632
andreas@7077
   633
    private func insert(text insertText: NSAttributedString,
andreas@7077
   634
                        in range: NSRange,
andreas@7077
   635
                        of text: NSAttributedString) -> NSAttributedString {
andreas@7077
   636
        let attrText = NSMutableAttributedString(attributedString: text)
andreas@7077
   637
        attrText.replaceCharacters(in: range, with: insertText)
andreas@7077
   638
        return attrText
andreas@7077
   639
    }
andreas@7068
   640
andreas@7088
   641
    // MARK: BodyCellViewModelDelegate
andreas@7068
   642
andreas@7088
   643
    private class TestDelegate: BodyCellViewModelDelegate {
andreas@7088
   644
        //insert
andreas@7088
   645
        let expectInsertCalled: XCTestExpectation?
andreas@7088
   646
        let inserted: NSAttributedString?
andreas@7068
   647
andreas@7088
   648
        init(expectInsertCalled: XCTestExpectation?, inserted: NSAttributedString?) {
andreas@7088
   649
            self.expectInsertCalled = expectInsertCalled
andreas@7088
   650
            self.inserted = inserted
andreas@7088
   651
        }
andreas@7068
   652
andreas@7088
   653
        // BodyCellViewModelDelegate
andreas@7068
   654
andreas@7088
   655
        func insert(text: NSAttributedString) {
andreas@7088
   656
            guard let exp = expectInsertCalled else {
andreas@7088
   657
                // We ignore called or not
andreas@7088
   658
                return
andreas@7088
   659
            }
andreas@7088
   660
            exp.fulfill()
andreas@7088
   661
            if let expected = inserted {
andreas@7088
   662
                XCTAssertEqual(text, expected)
andreas@7068
   663
            }
andreas@7068
   664
        }
andreas@7068
   665
    }
andreas@7068
   666
andreas@7088
   667
    // MARK: BodyCellViewModelResultDelegate
andreas@7088
   668
andreas@7088
   669
    private class TestResultDelegate: BodyCellViewModelResultDelegate {
andreas@7088
   670
        // context menu
andreas@7088
   671
        let expUserWantsToAddMediaCalled: XCTestExpectation?
andreas@7088
   672
        let expUserWantsToAddDocumentCalled: XCTestExpectation?
andreas@7088
   673
        // inlined image
andreas@7088
   674
        let expInlinedAttachmentsCalled: XCTestExpectation?
andreas@7088
   675
        let inlined: [Attachment]?
andreas@7088
   676
        // content change
andreas@7088
   677
        let expBodyChangedCalled: XCTestExpectation?
andreas@7088
   678
        let exectedPlain: String?
andreas@7088
   679
        let exectedHtml: String?
andreas@7088
   680
andreas@7088
   681
        init(expUserWantsToAddMediaCalled: XCTestExpectation?,
andreas@7088
   682
             expUserWantsToAddDocumentCalled: XCTestExpectation?,
andreas@7088
   683
             expInlinedAttachmentsCalled: XCTestExpectation?, inlined: [Attachment]?,
andreas@7088
   684
             expBodyChangedCalled: XCTestExpectation?, exectedPlain: String?, exectedHtml: String?) {
andreas@7088
   685
            self.expUserWantsToAddMediaCalled = expUserWantsToAddMediaCalled
andreas@7088
   686
            self.expUserWantsToAddDocumentCalled = expUserWantsToAddDocumentCalled
andreas@7088
   687
            self.expInlinedAttachmentsCalled = expInlinedAttachmentsCalled
andreas@7088
   688
            self.inlined = inlined
andreas@7088
   689
            self.expBodyChangedCalled = expBodyChangedCalled
andreas@7088
   690
            self.exectedPlain = exectedPlain
andreas@7088
   691
            self.exectedHtml = exectedHtml
andreas@7071
   692
        }
andreas@7088
   693
andreas@7088
   694
        func bodyCellViewModelUserWantsToAddMedia(_ vm: BodyCellViewModel) {
andreas@7088
   695
            guard let exp = expUserWantsToAddMediaCalled else {
andreas@7088
   696
                // We ignore called or not
andreas@7088
   697
                return
andreas@7088
   698
            }
andreas@7088
   699
            exp.fulfill()
andreas@7071
   700
        }
andreas@7088
   701
andreas@7088
   702
        func bodyCellViewModelUserWantsToAddDocument(_ vm: BodyCellViewModel) {
andreas@7088
   703
            guard let exp = expUserWantsToAddDocumentCalled else {
andreas@7088
   704
                // We ignore called or not
andreas@7088
   705
                return
andreas@7088
   706
            }
andreas@7088
   707
            exp.fulfill()
andreas@7088
   708
        }
andreas@7088
   709
andreas@7088
   710
        func bodyCellViewModel(_ vm: BodyCellViewModel,
andreas@7088
   711
                               inlinedAttachmentsChanged inlinedAttachments: [Attachment]) {
andreas@7088
   712
            guard let exp = expInlinedAttachmentsCalled else {
andreas@7088
   713
                // We ignore called or not
andreas@7088
   714
                return
andreas@7088
   715
            }
andreas@7088
   716
            exp.fulfill()
andreas@7088
   717
            if let expected = inlined {
andreas@7088
   718
                XCTAssertEqual(inlinedAttachments.count, expected.count)
andreas@7088
   719
                for testee in inlinedAttachments {
andreas@7088
   720
                    XCTAssertTrue(expected.contains(testee))
andreas@7088
   721
                }
andreas@7088
   722
            }
andreas@7088
   723
        }
andreas@7088
   724
andreas@12745
   725
        func bodyCellViewModel(_ vm: BodyCellViewModel, bodyAttributedString: NSAttributedString) { //!!!: ADAM: commented due to the changes
andreas@12732
   726
//            guard let exp = expBodyChangedCalled else {
andreas@12732
   727
//                // We ignore called or not
andreas@12732
   728
//                return
andreas@12732
   729
//            }
andreas@12732
   730
//            exp.fulfill()
andreas@12732
   731
//            let expBody = bodyAttributedString.toHtml()
andreas@12732
   732
//            let expPlainText = expBody.plainText
andreas@12732
   733
//            if let expected1 = exectedPlain {
andreas@12732
   734
//                XCTAssertEqual(expPlainText, expected1)
andreas@12732
   735
//            }
andreas@12745
   736
        }
andreas@7068
   737
    }
andreas@7068
   738
}