comments EmailListViewModelTest. Test target does not build. refactor
authorbuff <andreas@pep-project.org>
Wed, 22 May 2019 18:38:29 +0200
branchrefactor
changeset 8736ec061f625c49
parent 8727 fc81e2e79970
child 8737 d23080a4695e
child 8741 927cc70c8347
child 8742 3ef320a3e08b
child 8745 7edfdf8eca4c
comments EmailListViewModelTest. Test target does not build.
pEpForiOSTests/Models/EmailListViewModelTest.swift
     1.1 --- a/pEpForiOSTests/Models/EmailListViewModelTest.swift	Wed May 22 14:51:22 2019 +0200
     1.2 +++ b/pEpForiOSTests/Models/EmailListViewModelTest.swift	Wed May 22 18:38:29 2019 +0200
     1.3 @@ -1,672 +1,672 @@
     1.4 -//!!!: is WIP (IOS-1495), ignore failing tests for now.
     1.5 -
     1.6 +////!!!: is WIP (IOS-1495), ignore failing tests for now.
     1.7  //
     1.8 -//  EmailListViewModelTest.swift
     1.9 -//  pEpForiOSTests
    1.10 +////
    1.11 +////  EmailListViewModelTest.swift
    1.12 +////  pEpForiOSTests
    1.13 +////
    1.14 +////  Created by Xavier Algarra on 22/08/2018.
    1.15 +////  Copyright © 2018 p≡p Security S.A. All rights reserved.
    1.16  //
    1.17 -//  Created by Xavier Algarra on 22/08/2018.
    1.18 -//  Copyright © 2018 p≡p Security S.A. All rights reserved.
    1.19 -
    1.20 -import XCTest
    1.21 -@testable import pEpForiOS
    1.22 -@testable import MessageModel
    1.23 -
    1.24 -class EmailListViewModelTest: CoreDataDrivenTestBase {
    1.25 -    var folder: Folder!
    1.26 -    var trashFolder: Folder!
    1.27 -    var emailListVM : EmailListViewModel!
    1.28 -    var masterViewController: TestMasterViewController!
    1.29 -
    1.30 -    /** this set up a view model with one account and one folder saved **/
    1.31 -    override func setUp() {
    1.32 -        super.setUp()
    1.33 -
    1.34 -        let acc = cdAccount.account()
    1.35 -
    1.36 -        folder = Folder(name: "inbox", parent: nil, account: acc, folderType: .inbox)
    1.37 -        folder.save()
    1.38 -        trashFolder = Folder(name: "trash",
    1.39 -                             parent: nil,
    1.40 -                             account: folder.account,
    1.41 -                             folderType: .trash)
    1.42 -        trashFolder.save()
    1.43 -    }
    1.44 -
    1.45 -    // MARK: - Test section
    1.46 -
    1.47 -    func testViewModelSetUp() {
    1.48 -        setupViewModel()
    1.49 -        emailListVM.startMonitoring()
    1.50 -    }
    1.51 -
    1.52 -    func testCleanInitialSetup() {
    1.53 -        setupViewModel()
    1.54 -        emailListVM.startMonitoring()
    1.55 -        XCTAssertEqual(emailListVM.rowCount, 0)
    1.56 -    }
    1.57 -
    1.58 -    func test10MessagesInInitialSetup() {
    1.59 -         TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder, setUids: true)
    1.60 -        setupViewModel()
    1.61 -        emailListVM.startMonitoring()
    1.62 -        XCTAssertEqual(emailListVM.rowCount, 10)
    1.63 -    }
    1.64 -
    1.65 -    func testGetFolderName() {
    1.66 -        setupViewModel()
    1.67 -        XCTAssertEqual(Folder.localizedName(realName: self.folder.realName), emailListVM.folderName)
    1.68 -    }
    1.69 -
    1.70 -    func testGetDestructiveAction() {
    1.71 -        TestUtil.createMessages(number: 1, engineProccesed: true, inFolder: folder)
    1.72 -        setupViewModel()
    1.73 -        emailListVM.startMonitoring()
    1.74 -        let destructiveAction = emailListVM.getDestructiveActtion(forMessageAt: 0)
    1.75 -
    1.76 -        XCTAssertEqual(destructiveAction, .trash)
    1.77 -    }
    1.78 -
    1.79 -    func testGetDestructiveActionInOutgoingFolderIsTrash() {
    1.80 -        _ = givenThereIsAMessageIn(folderType: .outbox)
    1.81 -        setupViewModel()
    1.82 -        emailListVM.startMonitoring()
    1.83 -        let destructiveAction = emailListVM.getDestructiveActtion(forMessageAt: 0)
    1.84 -
    1.85 -        XCTAssertEqual(destructiveAction, .trash)
    1.86 -    }
    1.87 -
    1.88 -    func testShouldShowToolbarEditButtonsIfItsNotOutboxFolder() {
    1.89 -        setupViewModel()
    1.90 -        emailListVM.startMonitoring()
    1.91 -        var showToolbarButtons = emailListVM.shouldShowToolbarEditButtons()
    1.92 -        XCTAssertTrue(showToolbarButtons)
    1.93 -
    1.94 -        givenThereIsA(folderType: .outbox)
    1.95 -        setupViewModel()
    1.96 -        emailListVM.startMonitoring()
    1.97 -        showToolbarButtons = emailListVM.shouldShowToolbarEditButtons()
    1.98 -        XCTAssertFalse(showToolbarButtons)
    1.99 -    }
   1.100 -
   1.101 -    func testDefaultFilterActiveIsUnread() {
   1.102 -        let messages = TestUtil.createMessages(number: 20, engineProccesed: true, inFolder: folder)
   1.103 -        messages.forEach { (msg) in
   1.104 -            msg.imapFlags.seen = true
   1.105 -        }
   1.106 -        messages[0].imapFlags.seen = false
   1.107 -        messages[2].imapFlags.seen = false
   1.108 -        messages[4].imapFlags.seen = false
   1.109 -        messages[6].imapFlags.seen = false
   1.110 -        messages[8].imapFlags.seen = false
   1.111 -
   1.112 -        setupViewModel()
   1.113 -        emailListVM.startMonitoring()
   1.114 -
   1.115 -        var unreadActive = emailListVM.unreadFilterEnabled()
   1.116 -        XCTAssertFalse(unreadActive)
   1.117 -
   1.118 -        XCTAssertEqual(20, emailListVM.rowCount)
   1.119 -        emailListVM.isFilterEnabled = true
   1.120 -        XCTAssertEqual(5, emailListVM.rowCount)
   1.121 -        setUpViewModelExpectations(expectationDidDeleteDataAt: true)
   1.122 -        let imap = ImapFlags()
   1.123 -        imap.seen = true
   1.124 -        messages[0].imapFlags = imap
   1.125 -        waitForExpectations(timeout: TestUtil.waitTime)
   1.126 -        XCTAssertEqual(4, emailListVM.rowCount)
   1.127 -        unreadActive = emailListVM.unreadFilterEnabled()
   1.128 -        XCTAssertTrue(unreadActive)
   1.129 -        emailListVM.isFilterEnabled = false
   1.130 -        XCTAssertEqual(20, emailListVM.rowCount)
   1.131 -    }
   1.132 -
   1.133 -    func testGetFlagAndMoreAction() {
   1.134 -        let messages = TestUtil.createMessages(number: 1, engineProccesed: true, inFolder: folder)
   1.135 -        setupViewModel()
   1.136 -        emailListVM.startMonitoring()
   1.137 -        var flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   1.138 -        let moreAction = emailListVM.getMoreAction(forMessageAt: 0)
   1.139 -
   1.140 -        XCTAssertEqual(flagAction, .flag)
   1.141 -        XCTAssertEqual(moreAction, .more)
   1.142 -
   1.143 -        messages[0].imapFlags.flagged = true
   1.144 -        messages[0].save()
   1.145 -
   1.146 -        flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   1.147 -
   1.148 -        XCTAssertEqual(flagAction, .unflag)
   1.149 -    }
   1.150 -
   1.151 -    func testGetFlagAndMoreActionInOutgoingFolderIsNil() {
   1.152 -        givenThereIsAMessageIn(folderType: .outbox)
   1.153 -        setupViewModel()
   1.154 -        emailListVM.startMonitoring()
   1.155 -
   1.156 -        let flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   1.157 -        let moreAction = emailListVM.getMoreAction(forMessageAt: 0)
   1.158 -
   1.159 -        XCTAssertEqual(flagAction, nil)
   1.160 -        XCTAssertEqual(moreAction, nil)
   1.161 -    }
   1.162 -
   1.163 -    func testGetFlagAndMoreActionInDraftFolderIsNil() {
   1.164 -        givenThereIsAMessageIn(folderType: .drafts)
   1.165 -        setupViewModel()
   1.166 -        emailListVM.startMonitoring()
   1.167 -        let flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   1.168 -        let moreAction = emailListVM.getMoreAction(forMessageAt: 0)
   1.169 -
   1.170 -        XCTAssertEqual(flagAction, nil)
   1.171 -        XCTAssertEqual(moreAction, nil)
   1.172 -    }
   1.173 -
   1.174 -    func testAccountExists() {
   1.175 -        setupViewModel()
   1.176 -        emailListVM.startMonitoring()
   1.177 -        var noAccounts = emailListVM.showLoginView
   1.178 -
   1.179 -        XCTAssertFalse(noAccounts)
   1.180 -
   1.181 -        cdAccount.delete()
   1.182 -        setupViewModel()
   1.183 -        noAccounts = emailListVM.showLoginView
   1.184 -
   1.185 -        XCTAssertTrue(noAccounts)
   1.186 -    }
   1.187 -
   1.188 -    // MARK: - Search section
   1.189 -
   1.190 -    func testSetSearchFilterWith0results() {
   1.191 -        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   1.192 -        setupViewModel()
   1.193 -        emailListVM.startMonitoring()
   1.194 -        emailListVM.setSearch(forSearchText: "blabla@blabla.com")
   1.195 -        XCTAssertEqual(emailListVM.rowCount, 0)
   1.196 -    }
   1.197 -
   1.198 -    func testRemoveSearchFilterAfter0Results() {
   1.199 -        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   1.200 -        setupViewModel()
   1.201 -        emailListVM.startMonitoring()
   1.202 -        XCTAssertEqual(emailListVM.rowCount, 10)
   1.203 -        emailListVM.setSearch(forSearchText: "blabla@blabla.com")
   1.204 -        XCTAssertEqual(emailListVM.rowCount, 0)
   1.205 -        emailListVM.removeSearch()
   1.206 -        XCTAssertEqual(emailListVM.rowCount, 10)
   1.207 -    }
   1.208 -
   1.209 -    func testSetSearchFilterAddressWith3results() {
   1.210 -        let textToSearch = "searchTest@mail.com"
   1.211 -        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   1.212 -        TestUtil.createMessage(inFolder: folder,
   1.213 -                      from: Identity(address: textToSearch),
   1.214 -                      tos: [folder.account.user],
   1.215 -                      uid: 666).save()
   1.216 -        TestUtil.createMessage(inFolder: folder,
   1.217 -                      from: Identity(address: textToSearch),
   1.218 -                      tos: [folder.account.user],
   1.219 -                      uid: 667).save()
   1.220 -        TestUtil.createMessage(inFolder: folder,
   1.221 -                      from: Identity(address: textToSearch),
   1.222 -                      tos: [folder.account.user],
   1.223 -                      uid: 668).save()
   1.224 -        setupViewModel()
   1.225 -        emailListVM.startMonitoring()
   1.226 -        XCTAssertEqual(emailListVM.rowCount, 13)
   1.227 -        emailListVM.setSearch(forSearchText: textToSearch)
   1.228 -        XCTAssertEqual(emailListVM.rowCount, 3)
   1.229 -    }
   1.230 -
   1.231 -    func testSetSearchFilterShortMessageWith1results() {
   1.232 -        let textToSearch = "searchTest"
   1.233 -        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   1.234 -        TestUtil.createMessage(inFolder: folder,
   1.235 -                      from: Identity(address: "mail@mail.com"),
   1.236 -                      tos: [folder.account.user],
   1.237 -                      shortMessage: textToSearch,
   1.238 -                      uid: 666).save()
   1.239 -        setupViewModel()
   1.240 -        emailListVM.startMonitoring()
   1.241 -        XCTAssertEqual(emailListVM.rowCount, 11)
   1.242 -        emailListVM.setSearch(forSearchText: textToSearch)
   1.243 -        XCTAssertEqual(emailListVM.rowCount, 1)
   1.244 -    }
   1.245 -
   1.246 -    func testSetSearchMultipleSitesMatchInMessagesWith2results() {
   1.247 -        let textToSearch = "searchTest"
   1.248 -        let longText = "bla " + textToSearch + " bla"
   1.249 -        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   1.250 -        TestUtil.createMessage(inFolder: folder,
   1.251 -                      from: Identity(address: "mail@mail.com"),
   1.252 -                      shortMessage: textToSearch,
   1.253 -                      uid: 666).save()
   1.254 -        TestUtil.createMessage(inFolder: folder,
   1.255 -                      from: Identity(address: "mail@mail.com"),
   1.256 -                      tos: [folder.account.user],
   1.257 -                      longMessage: longText,
   1.258 -                      uid: 667).save()
   1.259 -        setupViewModel()
   1.260 -        emailListVM.startMonitoring()
   1.261 -        XCTAssertEqual(emailListVM.rowCount, 12)
   1.262 -        emailListVM.setSearch(forSearchText: textToSearch)
   1.263 -        XCTAssertEqual(emailListVM.rowCount, 2)
   1.264 -    }
   1.265 -
   1.266 -    // Threading feature is currently non-existing. Keep this code, might help later.
   1.267 -//    //thread view nos is totaly disabled that means always false
   1.268 -//    func testCheckIfSettingsChanged() {
   1.269 +//import XCTest
   1.270 +//@testable import pEpForiOS
   1.271 +//@testable import MessageModel
   1.272 +//
   1.273 +//class EmailListViewModelTest: CoreDataDrivenTestBase {
   1.274 +//    var folder: Folder!
   1.275 +//    var trashFolder: Folder!
   1.276 +//    var emailListVM : EmailListViewModel!
   1.277 +//    var masterViewController: TestMasterViewController!
   1.278 +//
   1.279 +//    /** this set up a view model with one account and one folder saved **/
   1.280 +//    override func setUp() {
   1.281 +//        super.setUp()
   1.282 +//
   1.283 +//        let acc = cdAccount.account()
   1.284 +//
   1.285 +//        folder = Folder(name: "inbox", parent: nil, account: acc, folderType: .inbox)
   1.286 +//        folder.save()
   1.287 +//        trashFolder = Folder(name: "trash",
   1.288 +//                             parent: nil,
   1.289 +//                             account: folder.account,
   1.290 +//                             folderType: .trash)
   1.291 +//        trashFolder.save()
   1.292 +//    }
   1.293 +//
   1.294 +//    // MARK: - Test section
   1.295 +//
   1.296 +//    func testViewModelSetUp() {
   1.297  //        setupViewModel()
   1.298  //        emailListVM.startMonitoring()
   1.299 -//        XCTAssertFalse(AppSettings.threadedViewEnabled)
   1.300 -//        AppSettings.threadedViewEnabled = true
   1.301 -//        XCTAssertFalse(emailListVM.checkIfSettingsChanged())
   1.302 -//    }
   1.303 -
   1.304 -    // MARK: - cell for row
   1.305 -/*
   1.306 -    func testIndexFromMessage() {
   1.307 -        let msgs = TestUtil.createMessages(number: 10, inFolder: folder)
   1.308 -        setupViewModel()
   1.309 -        emailListVM.startMonitoring()
   1.310 -        var index = emailListVM.index(of: msgs[0])
   1.311 -        XCTAssertEqual(index, 9)
   1.312 -        index = emailListVM.index(of: msgs[9])
   1.313 -        XCTAssertEqual(index, 0)
   1.314 -    }*/
   1.315 -
   1.316 -    func testViewModel() {
   1.317 -        let msg = TestUtil.createMessage(inFolder: folder, from: folder.account.user, uid: 1)
   1.318 -        msg.save()
   1.319 -        setupViewModel()
   1.320 -        emailListVM.startMonitoring()
   1.321 -        let index = emailListVM.index(of: msg)
   1.322 -        guard let ind = index else {
   1.323 -            XCTFail()
   1.324 -            return
   1.325 -        }
   1.326 -        let vm = emailListVM.viewModel(for: ind)
   1.327 -        XCTAssertEqual(vm?.message(), msg)
   1.328 -        XCTAssertEqual(vm?.subject, msg.shortMessage)
   1.329 -    }
   1.330 -
   1.331 -//    func testSetUpFilterViewModel() {
   1.332 -//        var filterEnabled = false
   1.333 -//        setupViewModel()
   1.334 -//        XCTAssertEqual(filterEnabled, emailListVM.isFilterEnabled)
   1.335 -//        filterEnabled = true
   1.336 -//        setUpViewModelExpectations(expectedUpdateView: true)
   1.337 -//        emailListVM.isFilterEnabled = filterEnabled
   1.338 -//        waitForExpectations(timeout: TestUtil.waitTime)
   1.339 -//        XCTAssertEqual(filterEnabled, emailListVM.isFilterEnabled)
   1.340 -//    }
   1.341 -
   1.342 -    func testNewMessageReceivedAndDisplayedInTheCorrectPosition() {
   1.343 -        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   1.344 -        setupViewModel()
   1.345 -        emailListVM.startMonitoring()
   1.346 -        XCTAssertEqual(emailListVM.rowCount, 10)
   1.347 -        setUpViewModelExpectations(expectationDidInsertDataAt: true)
   1.348 -        let msg = TestUtil.createMessage(inFolder: folder, from: folder.account.user)
   1.349 -        msg.save()
   1.350 -        waitForExpectations(timeout: TestUtil.waitTime)
   1.351 -        XCTAssertEqual(emailListVM.rowCount, 11)
   1.352 -        var index = emailListVM.index(of: msg)
   1.353 -        XCTAssertEqual(index, 0)
   1.354 -        let nonShownMsg = TestUtil.createMessage(inFolder: trashFolder, from: folder.account.user)
   1.355 -        nonShownMsg.save()
   1.356 -        XCTAssertEqual(emailListVM.rowCount, 11)
   1.357 -        index = emailListVM.index(of: msg)
   1.358 -        XCTAssertEqual(index, 0)
   1.359 -    }
   1.360 -
   1.361 -    func testNewMessageUpdateReceivedAndDisplayed() {
   1.362 -        let numMails = 10
   1.363 -        TestUtil.createMessages(number: numMails, engineProccesed: true, inFolder: folder)
   1.364 -        let msg = TestUtil.createMessage(inFolder: folder,
   1.365 -                                         from: folder.account.user,
   1.366 -                                         uid: numMails + 1)
   1.367 -        msg.imapFlags.flagged = false
   1.368 -        msg.save()
   1.369 -        XCTAssertFalse((msg.imapFlags.flagged))
   1.370 -        setupViewModel()
   1.371 -        emailListVM.startMonitoring()
   1.372 -        XCTAssertEqual(emailListVM.rowCount, 11)
   1.373 -        msg.imapFlags.flagged = true
   1.374 -        msg.save()
   1.375 -        waitForExpectations(timeout: TestUtil.waitTime)
   1.376 -        var index = emailListVM.index(of: msg)
   1.377 -        if let ind = index {
   1.378 -            let newMsg = emailListVM.message(representedByRowAt: IndexPath(row: ind, section: 0))
   1.379 -            XCTAssertTrue((newMsg?.imapFlags.flagged)!)
   1.380 -        } else {
   1.381 -            XCTFail()
   1.382 -        }
   1.383 -
   1.384 -        let nonShownMsg = TestUtil.createMessage(inFolder: trashFolder, from: folder.account.user)
   1.385 -        nonShownMsg.save()
   1.386 -        XCTAssertEqual(emailListVM.rowCount, 11)
   1.387 -        index = emailListVM.index(of: nonShownMsg)
   1.388 -        XCTAssertNil(index)
   1.389 -    }
   1.390 -
   1.391 -    func testNewMessageDeleteReceivedAndDisplayed() {
   1.392 -        let numMails = 10
   1.393 -        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   1.394 -        let msg = TestUtil.createMessage(inFolder: folder,
   1.395 -                                         from: folder.account.user,
   1.396 -                                         uid: numMails + 1)
   1.397 -        msg.imapFlags.flagged = false
   1.398 -        msg.save()
   1.399 -        XCTAssertFalse((msg.imapFlags.flagged))
   1.400 -        setupViewModel()
   1.401 -        emailListVM.startMonitoring()
   1.402 -        XCTAssertEqual(emailListVM.rowCount, 11)
   1.403 -        setUpViewModelExpectations(expectationDidDeleteDataAt: true)
   1.404 -        msg.delete()
   1.405 -        waitForExpectations(timeout: TestUtil.waitTime)
   1.406 -        var index = emailListVM.index(of: msg)
   1.407 -        XCTAssertNil(index)
   1.408 -        XCTAssertEqual(emailListVM.rowCount, 10)
   1.409 -
   1.410 -        let nonShownMsg = TestUtil.createMessage(inFolder: trashFolder, from: folder.account.user)
   1.411 -        nonShownMsg.save()
   1.412 -        nonShownMsg.delete()
   1.413 -        XCTAssertEqual(emailListVM.rowCount, 10)
   1.414 -        index = emailListVM.index(of: nonShownMsg)
   1.415 -        XCTAssertNil(index)
   1.416 -    }
   1.417 -
   1.418 -    func testgetMoveToFolderViewModel() {
   1.419 -        TestUtil.createMessages(number: 4, inFolder: folder)
   1.420 -        let index: [IndexPath] = [IndexPath(row: 0, section: 1),
   1.421 -                                  IndexPath(row: 0, section: 2)]
   1.422 -        setupViewModel()
   1.423 -        emailListVM.startMonitoring()
   1.424 -
   1.425 -        let accountvm = emailListVM.getMoveToFolderViewModel(forSelectedMessages: index)
   1.426 -
   1.427 -        let postMessages = accountvm!.items[0].messages
   1.428 -        XCTAssertEqual(index.count, postMessages.count)
   1.429 -    }
   1.430 -
   1.431 -    func testFlagUnflagMessageIsImmediate() {
   1.432 -        let message = givenThereIsAMessageIn(folderType: .inbox)
   1.433 -        let messageMoc = message?.cdMessage()?.managedObjectContext
   1.434 -        setupViewModel()
   1.435 -        emailListVM.startMonitoring()
   1.436 -
   1.437 -        let indexPath = IndexPath(row: 0, section: 0)
   1.438 -
   1.439 -        emailListVM.setFlagged(forIndexPath: indexPath)
   1.440 -        guard let isFlagged = emailListVM.viewModel(for: indexPath.row)?.isFlagged else {
   1.441 -            XCTFail()
   1.442 -            return
   1.443 -        }
   1.444 -
   1.445 -        emailListVM.unsetFlagged(forIndexPath: indexPath)
   1.446 -        guard let isNotFlagged = emailListVM.viewModel(for: indexPath.row)?.isFlagged else {
   1.447 -            XCTFail()
   1.448 -            return
   1.449 -        }
   1.450 -        let messageDidSaveExpectation = expectation(description: "message is saved")
   1.451 -        messageDidSaveExpectation.expectedFulfillmentCount = 8
   1.452 -
   1.453 -        NotificationCenter.default
   1.454 -            .addObserver(forName: Notification.Name.NSManagedObjectContextDidSave,
   1.455 -                         object: messageMoc,
   1.456 -                         queue: nil) { (notification) in
   1.457 -                            print("fulfill")
   1.458 -                            messageDidSaveExpectation.fulfill()
   1.459 -        }
   1.460 -
   1.461 -        let isImmediate = isFlagged != isNotFlagged
   1.462 -        XCTAssertTrue(isImmediate)
   1.463 -        wait(for: [messageDidSaveExpectation], timeout: UnitTestUtils.waitTime)
   1.464 -    }
   1.465 -
   1.466 -    // Mark: - setting up
   1.467 -
   1.468 -    fileprivate func setUpViewModel(masterViewController: TestMasterViewController) {
   1.469 -        self.emailListVM = EmailListViewModel(emailListViewModelDelegate: masterViewController, folderToShow: self.folder)
   1.470 -    }
   1.471 -
   1.472 -    fileprivate func setupViewModel() {
   1.473 -        createViewModelWithExpectations(expectedUpdateView: true)
   1.474 -    }
   1.475 -
   1.476 -    /*fileprivate func setSearchFilter(text: String) {
   1.477 -        setNewUpdateViewExpectation()
   1.478 -        emailListVM.setSearchFilter(forSearchText: text)
   1.479 -        waitForExpectations(timeout: TestUtil.waitTime)
   1.480 -    }
   1.481 -
   1.482 -    fileprivate func removeSearchFilter() {
   1.483 -        setNewUpdateViewExpectation()
   1.484 -        emailListVM.removeSearchFilter()
   1.485 -        waitForExpectations(timeout: TestUtil.waitTime)
   1.486 -    }*/
   1.487 -
   1.488 -    fileprivate func setNewUpdateViewExpectation() {
   1.489 -        let updateViewExpectation = expectation(description: "UpdateViewCalled")
   1.490 -        masterViewController.expectationUpdateViewCalled = updateViewExpectation
   1.491 -    }
   1.492 -
   1.493 -    fileprivate func createViewModelWithExpectations(expectedUpdateView: Bool) {
   1.494 -        let viewModelTestDelegate = TestMasterViewController()
   1.495 -        setUpViewModel(masterViewController: viewModelTestDelegate)
   1.496 -    }
   1.497 -
   1.498 -    fileprivate func setUpViewModelExpectations(expectedUpdateView: Bool = false,
   1.499 -                                                expectationDidInsertDataAt: Bool = false,
   1.500 -                                                expectationDidUpdateDataAt: Bool = false,
   1.501 -                                                expectationDidDeleteDataAt: Bool = false ) {
   1.502 -        var expectationUpdateViewCalled: XCTestExpectation?
   1.503 -        if expectedUpdateView {
   1.504 -            expectationUpdateViewCalled = expectation(description: "UpdateViewCalled")
   1.505 -        }
   1.506 -
   1.507 -        var excpectationDidInsertDataAtCalled: XCTestExpectation?
   1.508 -        if expectationDidInsertDataAt {
   1.509 -            excpectationDidInsertDataAtCalled =
   1.510 -                expectation(description: "excpectationDidInsertDataAtCalled")
   1.511 -        }
   1.512 -
   1.513 -        var excpectationDidUpdateDataAtCalled: XCTestExpectation?
   1.514 -        if expectationDidUpdateDataAt {
   1.515 -            excpectationDidUpdateDataAtCalled =
   1.516 -                expectation(description: "excpectationDidUpdateDataAtCalled")
   1.517 -        }
   1.518 -
   1.519 -        var excpectationDidDeleteDataAtCalled: XCTestExpectation?
   1.520 -        if expectationDidDeleteDataAt {
   1.521 -            excpectationDidDeleteDataAtCalled =
   1.522 -                expectation(description: "excpectationDidInsertDataAtCalled")
   1.523 -        }
   1.524 -
   1.525 -        emailListVM.emailListViewModelDelegate = TestMasterViewController(
   1.526 -            expectationUpdateView: expectationUpdateViewCalled,
   1.527 -            expectationDidInsertDataAt: excpectationDidInsertDataAtCalled,
   1.528 -            expectationDidUpdateDataAt: excpectationDidUpdateDataAtCalled,
   1.529 -            expectationDidRemoveDataAt: excpectationDidDeleteDataAtCalled)
   1.530 -    }
   1.531 -
   1.532 -    fileprivate func getSafeLastLookAt() -> Date {
   1.533 -        guard let safeLastLookedAt = folder?.lastLookedAt as Date? else {
   1.534 -            XCTFail()
   1.535 -            return Date()
   1.536 -        }
   1.537 -        return safeLastLookedAt
   1.538 -    }
   1.539 -
   1.540 -    private func givenThereIsA(folderType: FolderType) {
   1.541 -        folder = Folder(name: "-", parent: folder, account: account, folderType: folderType)
   1.542 -        folder.save()
   1.543 -    }
   1.544 -
   1.545 -    @discardableResult private func givenThereIsAMessageIn(folderType: FolderType) -> Message? {
   1.546 -        givenThereIsA(folderType: folderType)
   1.547 -        return TestUtil.createMessages(number: 1, engineProccesed: true, inFolder: folder).first
   1.548 -    }
   1.549 -}
   1.550 -
   1.551 -class TestMasterViewController: EmailListViewModelDelegate {
   1.552 -
   1.553 -    var expectationUpdateViewCalled: XCTestExpectation?
   1.554 -    var excpectationDidInsertDataAtCalled: XCTestExpectation?
   1.555 -    var expectationDidUpdateDataAtCalled: XCTestExpectation?
   1.556 -    var expectationDidRemoveDataAtCalled: XCTestExpectation?
   1.557 -    var expetationDidChangeSeenStateForDataAt: XCTestExpectation?
   1.558 -
   1.559 -    init(expectationUpdateView: XCTestExpectation? = nil,
   1.560 -         expectationDidInsertDataAt: XCTestExpectation? = nil,
   1.561 -         expectationDidUpdateDataAt: XCTestExpectation? = nil,
   1.562 -         expectationDidRemoveDataAt: XCTestExpectation? = nil) {
   1.563 -        self.expectationUpdateViewCalled = expectationUpdateView
   1.564 -        self.excpectationDidInsertDataAtCalled = expectationDidInsertDataAt
   1.565 -        self.expectationDidUpdateDataAtCalled = expectationDidUpdateDataAt
   1.566 -        self.expectationDidRemoveDataAtCalled = expectationDidRemoveDataAt
   1.567 -    }
   1.568 -
   1.569 -    func willReceiveUpdates(viewModel: EmailListViewModel) {
   1.570 -        //not yet defined
   1.571 -    }
   1.572 -
   1.573 -    func allUpdatesReceived(viewModel: EmailListViewModel) {
   1.574 -        //not yet defined
   1.575 -    }
   1.576 -
   1.577 -    func reloadData(viewModel: EmailListViewModel) {
   1.578 -        //not yet defined
   1.579 -    }
   1.580 -
   1.581 -
   1.582 -    func emailListViewModel(viewModel: EmailListViewModel,
   1.583 -                            didInsertDataAt indexPaths: [IndexPath]) {
   1.584 -        if let excpectationDidInsertDataAtCalled = excpectationDidInsertDataAtCalled {
   1.585 -            excpectationDidInsertDataAtCalled.fulfill()
   1.586 -        } else {
   1.587 -            XCTFail()
   1.588 -        }
   1.589 -    }
   1.590 -
   1.591 -    func emailListViewModel(viewModel: EmailListViewModel,
   1.592 -                            didUpdateDataAt indexPaths: [IndexPath]) {
   1.593 -        if let expectationDidUpdateDataAtCalled = expectationDidUpdateDataAtCalled {
   1.594 -            expectationDidUpdateDataAtCalled.fulfill()
   1.595 -        } else {
   1.596 -            //XCTFail()
   1.597 -        }
   1.598 -    }
   1.599 -
   1.600 -    func emailListViewModel(viewModel: EmailListViewModel,
   1.601 -                            didChangeSeenStateForDataAt indexPaths: [IndexPath]) {
   1.602 -        XCTFail("Currently unused in tests. Should not be called")
   1.603 -    }
   1.604 -
   1.605 -    func emailListViewModel(viewModel: EmailListViewModel,
   1.606 -                            didRemoveDataAt indexPaths: [IndexPath]) {
   1.607 -        if let expectationDidRemoveDataAtCalled = expectationDidRemoveDataAtCalled {
   1.608 -            expectationDidRemoveDataAtCalled.fulfill()
   1.609 -        } else {
   1.610 -            //XCTFail()
   1.611 -        }
   1.612 -    }
   1.613 -
   1.614 -    func emailListViewModel(viewModel: EmailListViewModel,
   1.615 -                            didMoveData atIndexPath: IndexPath,
   1.616 -                            toIndexPath: IndexPath) {
   1.617 -        XCTFail()
   1.618 -    }
   1.619 -
   1.620 -    func emailListViewModel(viewModel: EmailListViewModel,
   1.621 -                            didUpdateUndisplayedMessage message: Message) {
   1.622 -        XCTFail()
   1.623 -    }
   1.624 -
   1.625 -    func toolbarIs(enabled: Bool) {
   1.626 -        XCTFail()
   1.627 -    }
   1.628 -
   1.629 -    func showUnflagButton(enabled: Bool) {
   1.630 -        XCTFail()
   1.631 -    }
   1.632 -
   1.633 -    func showUnreadButton(enabled: Bool) {
   1.634 -        XCTFail()
   1.635 -    }
   1.636 -
   1.637 -    func updateView() {
   1.638 -        if let expectationUpdateViewCalled = expectationUpdateViewCalled {
   1.639 -            expectationUpdateViewCalled.fulfill()
   1.640 -        } else {
   1.641 -            XCTFail()
   1.642 -        }
   1.643 -    }
   1.644 -}
   1.645 -
   1.646 -//class TestServer: MessageQueryResults {
   1.647 -//    var results: [Message] = [Message]()
   1.648 -//
   1.649 -//    required init(withFolder folder: Folder) {
   1.650 -//        super.init(withDisplayableFolder: folder)
   1.651  //    }
   1.652  //
   1.653 -//
   1.654 -//    override var count: Int {
   1.655 -//        return results.count
   1.656 +//    func testCleanInitialSetup() {
   1.657 +//        setupViewModel()
   1.658 +//        emailListVM.startMonitoring()
   1.659 +//        XCTAssertEqual(emailListVM.rowCount, 0)
   1.660  //    }
   1.661  //
   1.662 -//    override subscript(index: Int) -> Message {
   1.663 -//        return results[index]
   1.664 +//    func test10MessagesInInitialSetup() {
   1.665 +//         TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder, setUids: true)
   1.666 +//        setupViewModel()
   1.667 +//        emailListVM.startMonitoring()
   1.668 +//        XCTAssertEqual(emailListVM.rowCount, 10)
   1.669  //    }
   1.670  //
   1.671 -//    override func startMonitoring() throws {
   1.672 -//
   1.673 +//    func testGetFolderName() {
   1.674 +//        setupViewModel()
   1.675 +//        XCTAssertEqual(Folder.localizedName(realName: self.folder.realName), emailListVM.folderName)
   1.676  //    }
   1.677  //
   1.678 -//    func insertData(message: Message) {
   1.679 -//        results.append(message)
   1.680 -//        let ip = IndexPath(row: results.firstIndex(of: message)!, section: 0)
   1.681 -//        delegate?.didInsert(indexPath: ip)
   1.682 +//    func testGetDestructiveAction() {
   1.683 +//        TestUtil.createMessages(number: 1, engineProccesed: true, inFolder: folder)
   1.684 +//        setupViewModel()
   1.685 +//        emailListVM.startMonitoring()
   1.686 +//        let destructiveAction = emailListVM.getDestructiveActtion(forMessageAt: 0)
   1.687 +//
   1.688 +//        XCTAssertEqual(destructiveAction, .trash)
   1.689  //    }
   1.690  //
   1.691 -//    func updateData(message: Message) {
   1.692 -//        let ip = IndexPath(row: results.firstIndex(of: message)!, section: 0)
   1.693 -//        delegate?.didUpdate(indexPath: ip)
   1.694 +//    func testGetDestructiveActionInOutgoingFolderIsTrash() {
   1.695 +//        _ = givenThereIsAMessageIn(folderType: .outbox)
   1.696 +//        setupViewModel()
   1.697 +//        emailListVM.startMonitoring()
   1.698 +//        let destructiveAction = emailListVM.getDestructiveActtion(forMessageAt: 0)
   1.699 +//
   1.700 +//        XCTAssertEqual(destructiveAction, .trash)
   1.701  //    }
   1.702  //
   1.703 -//    func deleteData(message: Message) {
   1.704 -//        let index = results.firstIndex(of: message)
   1.705 -//        results.remove(at: index!)
   1.706 -//        let ip = IndexPath(row: index!, section: 0)
   1.707 -//        delegate?.didDelete(indexPath: ip)
   1.708 +//    func testShouldShowToolbarEditButtonsIfItsNotOutboxFolder() {
   1.709 +//        setupViewModel()
   1.710 +//        emailListVM.startMonitoring()
   1.711 +//        var showToolbarButtons = emailListVM.shouldShowToolbarEditButtons()
   1.712 +//        XCTAssertTrue(showToolbarButtons)
   1.713 +//
   1.714 +//        givenThereIsA(folderType: .outbox)
   1.715 +//        setupViewModel()
   1.716 +//        emailListVM.startMonitoring()
   1.717 +//        showToolbarButtons = emailListVM.shouldShowToolbarEditButtons()
   1.718 +//        XCTAssertFalse(showToolbarButtons)
   1.719  //    }
   1.720  //
   1.721 -//    func insertMessagesWithoutDelegate(messages: [Message]) {
   1.722 -//        results.append(contentsOf: messages)
   1.723 +//    func testDefaultFilterActiveIsUnread() {
   1.724 +//        let messages = TestUtil.createMessages(number: 20, engineProccesed: true, inFolder: folder)
   1.725 +//        messages.forEach { (msg) in
   1.726 +//            msg.imapFlags.seen = true
   1.727 +//        }
   1.728 +//        messages[0].imapFlags.seen = false
   1.729 +//        messages[2].imapFlags.seen = false
   1.730 +//        messages[4].imapFlags.seen = false
   1.731 +//        messages[6].imapFlags.seen = false
   1.732 +//        messages[8].imapFlags.seen = false
   1.733 +//
   1.734 +//        setupViewModel()
   1.735 +//        emailListVM.startMonitoring()
   1.736 +//
   1.737 +//        var unreadActive = emailListVM.unreadFilterEnabled()
   1.738 +//        XCTAssertFalse(unreadActive)
   1.739 +//
   1.740 +//        XCTAssertEqual(20, emailListVM.rowCount)
   1.741 +//        emailListVM.isFilterEnabled = true
   1.742 +//        XCTAssertEqual(5, emailListVM.rowCount)
   1.743 +//        setUpViewModelExpectations(expectationDidDeleteDataAt: true)
   1.744 +//        let imap = ImapFlags()
   1.745 +//        imap.seen = true
   1.746 +//        messages[0].imapFlags = imap
   1.747 +//        waitForExpectations(timeout: TestUtil.waitTime)
   1.748 +//        XCTAssertEqual(4, emailListVM.rowCount)
   1.749 +//        unreadActive = emailListVM.unreadFilterEnabled()
   1.750 +//        XCTAssertTrue(unreadActive)
   1.751 +//        emailListVM.isFilterEnabled = false
   1.752 +//        XCTAssertEqual(20, emailListVM.rowCount)
   1.753 +//    }
   1.754 +//
   1.755 +//    func testGetFlagAndMoreAction() {
   1.756 +//        let messages = TestUtil.createMessages(number: 1, engineProccesed: true, inFolder: folder)
   1.757 +//        setupViewModel()
   1.758 +//        emailListVM.startMonitoring()
   1.759 +//        var flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   1.760 +//        let moreAction = emailListVM.getMoreAction(forMessageAt: 0)
   1.761 +//
   1.762 +//        XCTAssertEqual(flagAction, .flag)
   1.763 +//        XCTAssertEqual(moreAction, .more)
   1.764 +//
   1.765 +//        messages[0].imapFlags.flagged = true
   1.766 +//        messages[0].save()
   1.767 +//
   1.768 +//        flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   1.769 +//
   1.770 +//        XCTAssertEqual(flagAction, .unflag)
   1.771 +//    }
   1.772 +//
   1.773 +//    func testGetFlagAndMoreActionInOutgoingFolderIsNil() {
   1.774 +//        givenThereIsAMessageIn(folderType: .outbox)
   1.775 +//        setupViewModel()
   1.776 +//        emailListVM.startMonitoring()
   1.777 +//
   1.778 +//        let flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   1.779 +//        let moreAction = emailListVM.getMoreAction(forMessageAt: 0)
   1.780 +//
   1.781 +//        XCTAssertEqual(flagAction, nil)
   1.782 +//        XCTAssertEqual(moreAction, nil)
   1.783 +//    }
   1.784 +//
   1.785 +//    func testGetFlagAndMoreActionInDraftFolderIsNil() {
   1.786 +//        givenThereIsAMessageIn(folderType: .drafts)
   1.787 +//        setupViewModel()
   1.788 +//        emailListVM.startMonitoring()
   1.789 +//        let flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   1.790 +//        let moreAction = emailListVM.getMoreAction(forMessageAt: 0)
   1.791 +//
   1.792 +//        XCTAssertEqual(flagAction, nil)
   1.793 +//        XCTAssertEqual(moreAction, nil)
   1.794 +//    }
   1.795 +//
   1.796 +//    func testAccountExists() {
   1.797 +//        setupViewModel()
   1.798 +//        emailListVM.startMonitoring()
   1.799 +//        var noAccounts = emailListVM.showLoginView
   1.800 +//
   1.801 +//        XCTAssertFalse(noAccounts)
   1.802 +//
   1.803 +//        cdAccount.delete()
   1.804 +//        setupViewModel()
   1.805 +//        noAccounts = emailListVM.showLoginView
   1.806 +//
   1.807 +//        XCTAssertTrue(noAccounts)
   1.808 +//    }
   1.809 +//
   1.810 +//    // MARK: - Search section
   1.811 +//
   1.812 +//    func testSetSearchFilterWith0results() {
   1.813 +//        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   1.814 +//        setupViewModel()
   1.815 +//        emailListVM.startMonitoring()
   1.816 +//        emailListVM.setSearch(forSearchText: "blabla@blabla.com")
   1.817 +//        XCTAssertEqual(emailListVM.rowCount, 0)
   1.818 +//    }
   1.819 +//
   1.820 +//    func testRemoveSearchFilterAfter0Results() {
   1.821 +//        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   1.822 +//        setupViewModel()
   1.823 +//        emailListVM.startMonitoring()
   1.824 +//        XCTAssertEqual(emailListVM.rowCount, 10)
   1.825 +//        emailListVM.setSearch(forSearchText: "blabla@blabla.com")
   1.826 +//        XCTAssertEqual(emailListVM.rowCount, 0)
   1.827 +//        emailListVM.removeSearch()
   1.828 +//        XCTAssertEqual(emailListVM.rowCount, 10)
   1.829 +//    }
   1.830 +//
   1.831 +//    func testSetSearchFilterAddressWith3results() {
   1.832 +//        let textToSearch = "searchTest@mail.com"
   1.833 +//        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   1.834 +//        TestUtil.createMessage(inFolder: folder,
   1.835 +//                      from: Identity(address: textToSearch),
   1.836 +//                      tos: [folder.account.user],
   1.837 +//                      uid: 666).save()
   1.838 +//        TestUtil.createMessage(inFolder: folder,
   1.839 +//                      from: Identity(address: textToSearch),
   1.840 +//                      tos: [folder.account.user],
   1.841 +//                      uid: 667).save()
   1.842 +//        TestUtil.createMessage(inFolder: folder,
   1.843 +//                      from: Identity(address: textToSearch),
   1.844 +//                      tos: [folder.account.user],
   1.845 +//                      uid: 668).save()
   1.846 +//        setupViewModel()
   1.847 +//        emailListVM.startMonitoring()
   1.848 +//        XCTAssertEqual(emailListVM.rowCount, 13)
   1.849 +//        emailListVM.setSearch(forSearchText: textToSearch)
   1.850 +//        XCTAssertEqual(emailListVM.rowCount, 3)
   1.851 +//    }
   1.852 +//
   1.853 +//    func testSetSearchFilterShortMessageWith1results() {
   1.854 +//        let textToSearch = "searchTest"
   1.855 +//        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   1.856 +//        TestUtil.createMessage(inFolder: folder,
   1.857 +//                      from: Identity(address: "mail@mail.com"),
   1.858 +//                      tos: [folder.account.user],
   1.859 +//                      shortMessage: textToSearch,
   1.860 +//                      uid: 666).save()
   1.861 +//        setupViewModel()
   1.862 +//        emailListVM.startMonitoring()
   1.863 +//        XCTAssertEqual(emailListVM.rowCount, 11)
   1.864 +//        emailListVM.setSearch(forSearchText: textToSearch)
   1.865 +//        XCTAssertEqual(emailListVM.rowCount, 1)
   1.866 +//    }
   1.867 +//
   1.868 +//    func testSetSearchMultipleSitesMatchInMessagesWith2results() {
   1.869 +//        let textToSearch = "searchTest"
   1.870 +//        let longText = "bla " + textToSearch + " bla"
   1.871 +//        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   1.872 +//        TestUtil.createMessage(inFolder: folder,
   1.873 +//                      from: Identity(address: "mail@mail.com"),
   1.874 +//                      shortMessage: textToSearch,
   1.875 +//                      uid: 666).save()
   1.876 +//        TestUtil.createMessage(inFolder: folder,
   1.877 +//                      from: Identity(address: "mail@mail.com"),
   1.878 +//                      tos: [folder.account.user],
   1.879 +//                      longMessage: longText,
   1.880 +//                      uid: 667).save()
   1.881 +//        setupViewModel()
   1.882 +//        emailListVM.startMonitoring()
   1.883 +//        XCTAssertEqual(emailListVM.rowCount, 12)
   1.884 +//        emailListVM.setSearch(forSearchText: textToSearch)
   1.885 +//        XCTAssertEqual(emailListVM.rowCount, 2)
   1.886 +//    }
   1.887 +//
   1.888 +//    // Threading feature is currently non-existing. Keep this code, might help later.
   1.889 +////    //thread view nos is totaly disabled that means always false
   1.890 +////    func testCheckIfSettingsChanged() {
   1.891 +////        setupViewModel()
   1.892 +////        emailListVM.startMonitoring()
   1.893 +////        XCTAssertFalse(AppSettings.threadedViewEnabled)
   1.894 +////        AppSettings.threadedViewEnabled = true
   1.895 +////        XCTAssertFalse(emailListVM.checkIfSettingsChanged())
   1.896 +////    }
   1.897 +//
   1.898 +//    // MARK: - cell for row
   1.899 +///*
   1.900 +//    func testIndexFromMessage() {
   1.901 +//        let msgs = TestUtil.createMessages(number: 10, inFolder: folder)
   1.902 +//        setupViewModel()
   1.903 +//        emailListVM.startMonitoring()
   1.904 +//        var index = emailListVM.index(of: msgs[0])
   1.905 +//        XCTAssertEqual(index, 9)
   1.906 +//        index = emailListVM.index(of: msgs[9])
   1.907 +//        XCTAssertEqual(index, 0)
   1.908 +//    }*/
   1.909 +//
   1.910 +//    func testViewModel() {
   1.911 +//        let msg = TestUtil.createMessage(inFolder: folder, from: folder.account.user, uid: 1)
   1.912 +//        msg.save()
   1.913 +//        setupViewModel()
   1.914 +//        emailListVM.startMonitoring()
   1.915 +//        let index = emailListVM.index(of: msg)
   1.916 +//        guard let ind = index else {
   1.917 +//            XCTFail()
   1.918 +//            return
   1.919 +//        }
   1.920 +//        let vm = emailListVM.viewModel(for: ind)
   1.921 +//        XCTAssertEqual(vm?.message(), msg)
   1.922 +//        XCTAssertEqual(vm?.subject, msg.shortMessage)
   1.923 +//    }
   1.924 +//
   1.925 +////    func testSetUpFilterViewModel() {
   1.926 +////        var filterEnabled = false
   1.927 +////        setupViewModel()
   1.928 +////        XCTAssertEqual(filterEnabled, emailListVM.isFilterEnabled)
   1.929 +////        filterEnabled = true
   1.930 +////        setUpViewModelExpectations(expectedUpdateView: true)
   1.931 +////        emailListVM.isFilterEnabled = filterEnabled
   1.932 +////        waitForExpectations(timeout: TestUtil.waitTime)
   1.933 +////        XCTAssertEqual(filterEnabled, emailListVM.isFilterEnabled)
   1.934 +////    }
   1.935 +//
   1.936 +//    func testNewMessageReceivedAndDisplayedInTheCorrectPosition() {
   1.937 +//        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   1.938 +//        setupViewModel()
   1.939 +//        emailListVM.startMonitoring()
   1.940 +//        XCTAssertEqual(emailListVM.rowCount, 10)
   1.941 +//        setUpViewModelExpectations(expectationDidInsertDataAt: true)
   1.942 +//        let msg = TestUtil.createMessage(inFolder: folder, from: folder.account.user)
   1.943 +//        msg.save()
   1.944 +//        waitForExpectations(timeout: TestUtil.waitTime)
   1.945 +//        XCTAssertEqual(emailListVM.rowCount, 11)
   1.946 +//        var index = emailListVM.index(of: msg)
   1.947 +//        XCTAssertEqual(index, 0)
   1.948 +//        let nonShownMsg = TestUtil.createMessage(inFolder: trashFolder, from: folder.account.user)
   1.949 +//        nonShownMsg.save()
   1.950 +//        XCTAssertEqual(emailListVM.rowCount, 11)
   1.951 +//        index = emailListVM.index(of: msg)
   1.952 +//        XCTAssertEqual(index, 0)
   1.953 +//    }
   1.954 +//
   1.955 +//    func testNewMessageUpdateReceivedAndDisplayed() {
   1.956 +//        let numMails = 10
   1.957 +//        TestUtil.createMessages(number: numMails, engineProccesed: true, inFolder: folder)
   1.958 +//        let msg = TestUtil.createMessage(inFolder: folder,
   1.959 +//                                         from: folder.account.user,
   1.960 +//                                         uid: numMails + 1)
   1.961 +//        msg.imapFlags.flagged = false
   1.962 +//        msg.save()
   1.963 +//        XCTAssertFalse((msg.imapFlags.flagged))
   1.964 +//        setupViewModel()
   1.965 +//        emailListVM.startMonitoring()
   1.966 +//        XCTAssertEqual(emailListVM.rowCount, 11)
   1.967 +//        msg.imapFlags.flagged = true
   1.968 +//        msg.save()
   1.969 +//        waitForExpectations(timeout: TestUtil.waitTime)
   1.970 +//        var index = emailListVM.index(of: msg)
   1.971 +//        if let ind = index {
   1.972 +//            let newMsg = emailListVM.message(representedByRowAt: IndexPath(row: ind, section: 0))
   1.973 +//            XCTAssertTrue((newMsg?.imapFlags.flagged)!)
   1.974 +//        } else {
   1.975 +//            XCTFail()
   1.976 +//        }
   1.977 +//
   1.978 +//        let nonShownMsg = TestUtil.createMessage(inFolder: trashFolder, from: folder.account.user)
   1.979 +//        nonShownMsg.save()
   1.980 +//        XCTAssertEqual(emailListVM.rowCount, 11)
   1.981 +//        index = emailListVM.index(of: nonShownMsg)
   1.982 +//        XCTAssertNil(index)
   1.983 +//    }
   1.984 +//
   1.985 +//    func testNewMessageDeleteReceivedAndDisplayed() {
   1.986 +//        let numMails = 10
   1.987 +//        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   1.988 +//        let msg = TestUtil.createMessage(inFolder: folder,
   1.989 +//                                         from: folder.account.user,
   1.990 +//                                         uid: numMails + 1)
   1.991 +//        msg.imapFlags.flagged = false
   1.992 +//        msg.save()
   1.993 +//        XCTAssertFalse((msg.imapFlags.flagged))
   1.994 +//        setupViewModel()
   1.995 +//        emailListVM.startMonitoring()
   1.996 +//        XCTAssertEqual(emailListVM.rowCount, 11)
   1.997 +//        setUpViewModelExpectations(expectationDidDeleteDataAt: true)
   1.998 +//        msg.delete()
   1.999 +//        waitForExpectations(timeout: TestUtil.waitTime)
  1.1000 +//        var index = emailListVM.index(of: msg)
  1.1001 +//        XCTAssertNil(index)
  1.1002 +//        XCTAssertEqual(emailListVM.rowCount, 10)
  1.1003 +//
  1.1004 +//        let nonShownMsg = TestUtil.createMessage(inFolder: trashFolder, from: folder.account.user)
  1.1005 +//        nonShownMsg.save()
  1.1006 +//        nonShownMsg.delete()
  1.1007 +//        XCTAssertEqual(emailListVM.rowCount, 10)
  1.1008 +//        index = emailListVM.index(of: nonShownMsg)
  1.1009 +//        XCTAssertNil(index)
  1.1010 +//    }
  1.1011 +//
  1.1012 +//    func testgetMoveToFolderViewModel() {
  1.1013 +//        TestUtil.createMessages(number: 4, inFolder: folder)
  1.1014 +//        let index: [IndexPath] = [IndexPath(row: 0, section: 1),
  1.1015 +//                                  IndexPath(row: 0, section: 2)]
  1.1016 +//        setupViewModel()
  1.1017 +//        emailListVM.startMonitoring()
  1.1018 +//
  1.1019 +//        let accountvm = emailListVM.getMoveToFolderViewModel(forSelectedMessages: index)
  1.1020 +//
  1.1021 +//        let postMessages = accountvm!.items[0].messages
  1.1022 +//        XCTAssertEqual(index.count, postMessages.count)
  1.1023 +//    }
  1.1024 +//
  1.1025 +//    func testFlagUnflagMessageIsImmediate() {
  1.1026 +//        let message = givenThereIsAMessageIn(folderType: .inbox)
  1.1027 +//        let messageMoc = message?.cdMessage()?.managedObjectContext
  1.1028 +//        setupViewModel()
  1.1029 +//        emailListVM.startMonitoring()
  1.1030 +//
  1.1031 +//        let indexPath = IndexPath(row: 0, section: 0)
  1.1032 +//
  1.1033 +//        emailListVM.setFlagged(forIndexPath: indexPath)
  1.1034 +//        guard let isFlagged = emailListVM.viewModel(for: indexPath.row)?.isFlagged else {
  1.1035 +//            XCTFail()
  1.1036 +//            return
  1.1037 +//        }
  1.1038 +//
  1.1039 +//        emailListVM.unsetFlagged(forIndexPath: indexPath)
  1.1040 +//        guard let isNotFlagged = emailListVM.viewModel(for: indexPath.row)?.isFlagged else {
  1.1041 +//            XCTFail()
  1.1042 +//            return
  1.1043 +//        }
  1.1044 +//        let messageDidSaveExpectation = expectation(description: "message is saved")
  1.1045 +//        messageDidSaveExpectation.expectedFulfillmentCount = 8
  1.1046 +//
  1.1047 +//        NotificationCenter.default
  1.1048 +//            .addObserver(forName: Notification.Name.NSManagedObjectContextDidSave,
  1.1049 +//                         object: messageMoc,
  1.1050 +//                         queue: nil) { (notification) in
  1.1051 +//                            print("fulfill")
  1.1052 +//                            messageDidSaveExpectation.fulfill()
  1.1053 +//        }
  1.1054 +//
  1.1055 +//        let isImmediate = isFlagged != isNotFlagged
  1.1056 +//        XCTAssertTrue(isImmediate)
  1.1057 +//        wait(for: [messageDidSaveExpectation], timeout: UnitTestUtils.waitTime)
  1.1058 +//    }
  1.1059 +//
  1.1060 +//    // Mark: - setting up
  1.1061 +//
  1.1062 +//    fileprivate func setUpViewModel(masterViewController: TestMasterViewController) {
  1.1063 +//        self.emailListVM = EmailListViewModel(emailListViewModelDelegate: masterViewController, folderToShow: self.folder)
  1.1064 +//    }
  1.1065 +//
  1.1066 +//    fileprivate func setupViewModel() {
  1.1067 +//        createViewModelWithExpectations(expectedUpdateView: true)
  1.1068 +//    }
  1.1069 +//
  1.1070 +//    /*fileprivate func setSearchFilter(text: String) {
  1.1071 +//        setNewUpdateViewExpectation()
  1.1072 +//        emailListVM.setSearchFilter(forSearchText: text)
  1.1073 +//        waitForExpectations(timeout: TestUtil.waitTime)
  1.1074 +//    }
  1.1075 +//
  1.1076 +//    fileprivate func removeSearchFilter() {
  1.1077 +//        setNewUpdateViewExpectation()
  1.1078 +//        emailListVM.removeSearchFilter()
  1.1079 +//        waitForExpectations(timeout: TestUtil.waitTime)
  1.1080 +//    }*/
  1.1081 +//
  1.1082 +//    fileprivate func setNewUpdateViewExpectation() {
  1.1083 +//        let updateViewExpectation = expectation(description: "UpdateViewCalled")
  1.1084 +//        masterViewController.expectationUpdateViewCalled = updateViewExpectation
  1.1085 +//    }
  1.1086 +//
  1.1087 +//    fileprivate func createViewModelWithExpectations(expectedUpdateView: Bool) {
  1.1088 +//        let viewModelTestDelegate = TestMasterViewController()
  1.1089 +//        setUpViewModel(masterViewController: viewModelTestDelegate)
  1.1090 +//    }
  1.1091 +//
  1.1092 +//    fileprivate func setUpViewModelExpectations(expectedUpdateView: Bool = false,
  1.1093 +//                                                expectationDidInsertDataAt: Bool = false,
  1.1094 +//                                                expectationDidUpdateDataAt: Bool = false,
  1.1095 +//                                                expectationDidDeleteDataAt: Bool = false ) {
  1.1096 +//        var expectationUpdateViewCalled: XCTestExpectation?
  1.1097 +//        if expectedUpdateView {
  1.1098 +//            expectationUpdateViewCalled = expectation(description: "UpdateViewCalled")
  1.1099 +//        }
  1.1100 +//
  1.1101 +//        var excpectationDidInsertDataAtCalled: XCTestExpectation?
  1.1102 +//        if expectationDidInsertDataAt {
  1.1103 +//            excpectationDidInsertDataAtCalled =
  1.1104 +//                expectation(description: "excpectationDidInsertDataAtCalled")
  1.1105 +//        }
  1.1106 +//
  1.1107 +//        var excpectationDidUpdateDataAtCalled: XCTestExpectation?
  1.1108 +//        if expectationDidUpdateDataAt {
  1.1109 +//            excpectationDidUpdateDataAtCalled =
  1.1110 +//                expectation(description: "excpectationDidUpdateDataAtCalled")
  1.1111 +//        }
  1.1112 +//
  1.1113 +//        var excpectationDidDeleteDataAtCalled: XCTestExpectation?
  1.1114 +//        if expectationDidDeleteDataAt {
  1.1115 +//            excpectationDidDeleteDataAtCalled =
  1.1116 +//                expectation(description: "excpectationDidInsertDataAtCalled")
  1.1117 +//        }
  1.1118 +//
  1.1119 +//        emailListVM.emailListViewModelDelegate = TestMasterViewController(
  1.1120 +//            expectationUpdateView: expectationUpdateViewCalled,
  1.1121 +//            expectationDidInsertDataAt: excpectationDidInsertDataAtCalled,
  1.1122 +//            expectationDidUpdateDataAt: excpectationDidUpdateDataAtCalled,
  1.1123 +//            expectationDidRemoveDataAt: excpectationDidDeleteDataAtCalled)
  1.1124 +//    }
  1.1125 +//
  1.1126 +//    fileprivate func getSafeLastLookAt() -> Date {
  1.1127 +//        guard let safeLastLookedAt = folder?.lastLookedAt as Date? else {
  1.1128 +//            XCTFail()
  1.1129 +//            return Date()
  1.1130 +//        }
  1.1131 +//        return safeLastLookedAt
  1.1132 +//    }
  1.1133 +//
  1.1134 +//    private func givenThereIsA(folderType: FolderType) {
  1.1135 +//        folder = Folder(name: "-", parent: folder, account: account, folderType: folderType)
  1.1136 +//        folder.save()
  1.1137 +//    }
  1.1138 +//
  1.1139 +//    @discardableResult private func givenThereIsAMessageIn(folderType: FolderType) -> Message? {
  1.1140 +//        givenThereIsA(folderType: folderType)
  1.1141 +//        return TestUtil.createMessages(number: 1, engineProccesed: true, inFolder: folder).first
  1.1142  //    }
  1.1143  //}
  1.1144 -
  1.1145 -class TestDetailsViewController {
  1.1146 -    var emailDisplayDelegate : EmailDisplayDelegate
  1.1147 -    init(emailDisplayDelegate: EmailDisplayDelegate) {
  1.1148 -        self.emailDisplayDelegate = emailDisplayDelegate
  1.1149 -    }
  1.1150 -
  1.1151 -    func emailDisplayDidChangeMarkSeen(message: Message) {
  1.1152 -        self.emailDisplayDelegate.emailDisplayDidChangeMarkSeen(message: message)
  1.1153 -    }
  1.1154 -
  1.1155 -    func emailDisplayDidDelete(message: Message) {
  1.1156 -        self.emailDisplayDelegate.emailDisplayDidDelete(message: message)
  1.1157 -    }
  1.1158 -
  1.1159 -    func emailDisplayDidFlag(message: Message) {
  1.1160 -        self.emailDisplayDelegate.emailDisplayDidFlag(message: message)
  1.1161 -    }
  1.1162 -
  1.1163 -    func emailDisplayDidUnflag(message: Message) {
  1.1164 -        self.emailDisplayDelegate.emailDisplayDidUnflag(message: message)
  1.1165 -    }
  1.1166 -}
  1.1167 +//
  1.1168 +//class TestMasterViewController: EmailListViewModelDelegate {
  1.1169 +//
  1.1170 +//    var expectationUpdateViewCalled: XCTestExpectation?
  1.1171 +//    var excpectationDidInsertDataAtCalled: XCTestExpectation?
  1.1172 +//    var expectationDidUpdateDataAtCalled: XCTestExpectation?
  1.1173 +//    var expectationDidRemoveDataAtCalled: XCTestExpectation?
  1.1174 +//    var expetationDidChangeSeenStateForDataAt: XCTestExpectation?
  1.1175 +//
  1.1176 +//    init(expectationUpdateView: XCTestExpectation? = nil,
  1.1177 +//         expectationDidInsertDataAt: XCTestExpectation? = nil,
  1.1178 +//         expectationDidUpdateDataAt: XCTestExpectation? = nil,
  1.1179 +//         expectationDidRemoveDataAt: XCTestExpectation? = nil) {
  1.1180 +//        self.expectationUpdateViewCalled = expectationUpdateView
  1.1181 +//        self.excpectationDidInsertDataAtCalled = expectationDidInsertDataAt
  1.1182 +//        self.expectationDidUpdateDataAtCalled = expectationDidUpdateDataAt
  1.1183 +//        self.expectationDidRemoveDataAtCalled = expectationDidRemoveDataAt
  1.1184 +//    }
  1.1185 +//
  1.1186 +//    func willReceiveUpdates(viewModel: EmailListViewModel) {
  1.1187 +//        //not yet defined
  1.1188 +//    }
  1.1189 +//
  1.1190 +//    func allUpdatesReceived(viewModel: EmailListViewModel) {
  1.1191 +//        //not yet defined
  1.1192 +//    }
  1.1193 +//
  1.1194 +//    func reloadData(viewModel: EmailListViewModel) {
  1.1195 +//        //not yet defined
  1.1196 +//    }
  1.1197 +//
  1.1198 +//
  1.1199 +//    func emailListViewModel(viewModel: EmailListViewModel,
  1.1200 +//                            didInsertDataAt indexPaths: [IndexPath]) {
  1.1201 +//        if let excpectationDidInsertDataAtCalled = excpectationDidInsertDataAtCalled {
  1.1202 +//            excpectationDidInsertDataAtCalled.fulfill()
  1.1203 +//        } else {
  1.1204 +//            XCTFail()
  1.1205 +//        }
  1.1206 +//    }
  1.1207 +//
  1.1208 +//    func emailListViewModel(viewModel: EmailListViewModel,
  1.1209 +//                            didUpdateDataAt indexPaths: [IndexPath]) {
  1.1210 +//        if let expectationDidUpdateDataAtCalled = expectationDidUpdateDataAtCalled {
  1.1211 +//            expectationDidUpdateDataAtCalled.fulfill()
  1.1212 +//        } else {
  1.1213 +//            //XCTFail()
  1.1214 +//        }
  1.1215 +//    }
  1.1216 +//
  1.1217 +//    func emailListViewModel(viewModel: EmailListViewModel,
  1.1218 +//                            didChangeSeenStateForDataAt indexPaths: [IndexPath]) {
  1.1219 +//        XCTFail("Currently unused in tests. Should not be called")
  1.1220 +//    }
  1.1221 +//
  1.1222 +//    func emailListViewModel(viewModel: EmailListViewModel,
  1.1223 +//                            didRemoveDataAt indexPaths: [IndexPath]) {
  1.1224 +//        if let expectationDidRemoveDataAtCalled = expectationDidRemoveDataAtCalled {
  1.1225 +//            expectationDidRemoveDataAtCalled.fulfill()
  1.1226 +//        } else {
  1.1227 +//            //XCTFail()
  1.1228 +//        }
  1.1229 +//    }
  1.1230 +//
  1.1231 +//    func emailListViewModel(viewModel: EmailListViewModel,
  1.1232 +//                            didMoveData atIndexPath: IndexPath,
  1.1233 +//                            toIndexPath: IndexPath) {
  1.1234 +//        XCTFail()
  1.1235 +//    }
  1.1236 +//
  1.1237 +//    func emailListViewModel(viewModel: EmailListViewModel,
  1.1238 +//                            didUpdateUndisplayedMessage message: Message) {
  1.1239 +//        XCTFail()
  1.1240 +//    }
  1.1241 +//
  1.1242 +//    func toolbarIs(enabled: Bool) {
  1.1243 +//        XCTFail()
  1.1244 +//    }
  1.1245 +//
  1.1246 +//    func showUnflagButton(enabled: Bool) {
  1.1247 +//        XCTFail()
  1.1248 +//    }
  1.1249 +//
  1.1250 +//    func showUnreadButton(enabled: Bool) {
  1.1251 +//        XCTFail()
  1.1252 +//    }
  1.1253 +//
  1.1254 +//    func updateView() {
  1.1255 +//        if let expectationUpdateViewCalled = expectationUpdateViewCalled {
  1.1256 +//            expectationUpdateViewCalled.fulfill()
  1.1257 +//        } else {
  1.1258 +//            XCTFail()
  1.1259 +//        }
  1.1260 +//    }
  1.1261 +//}
  1.1262 +//
  1.1263 +////class TestServer: MessageQueryResults {
  1.1264 +////    var results: [Message] = [Message]()
  1.1265 +////
  1.1266 +////    required init(withFolder folder: Folder) {
  1.1267 +////        super.init(withDisplayableFolder: folder)
  1.1268 +////    }
  1.1269 +////
  1.1270 +////
  1.1271 +////    override var count: Int {
  1.1272 +////        return results.count
  1.1273 +////    }
  1.1274 +////
  1.1275 +////    override subscript(index: Int) -> Message {
  1.1276 +////        return results[index]
  1.1277 +////    }
  1.1278 +////
  1.1279 +////    override func startMonitoring() throws {
  1.1280 +////
  1.1281 +////    }
  1.1282 +////
  1.1283 +////    func insertData(message: Message) {
  1.1284 +////        results.append(message)
  1.1285 +////        let ip = IndexPath(row: results.firstIndex(of: message)!, section: 0)
  1.1286 +////        delegate?.didInsert(indexPath: ip)
  1.1287 +////    }
  1.1288 +////
  1.1289 +////    func updateData(message: Message) {
  1.1290 +////        let ip = IndexPath(row: results.firstIndex(of: message)!, section: 0)
  1.1291 +////        delegate?.didUpdate(indexPath: ip)
  1.1292 +////    }
  1.1293 +////
  1.1294 +////    func deleteData(message: Message) {
  1.1295 +////        let index = results.firstIndex(of: message)
  1.1296 +////        results.remove(at: index!)
  1.1297 +////        let ip = IndexPath(row: index!, section: 0)
  1.1298 +////        delegate?.didDelete(indexPath: ip)
  1.1299 +////    }
  1.1300 +////
  1.1301 +////    func insertMessagesWithoutDelegate(messages: [Message]) {
  1.1302 +////        results.append(contentsOf: messages)
  1.1303 +////    }
  1.1304 +////}
  1.1305 +//
  1.1306 +//class TestDetailsViewController {
  1.1307 +//    var emailDisplayDelegate : EmailDisplayDelegate
  1.1308 +//    init(emailDisplayDelegate: EmailDisplayDelegate) {
  1.1309 +//        self.emailDisplayDelegate = emailDisplayDelegate
  1.1310 +//    }
  1.1311 +//
  1.1312 +//    func emailDisplayDidChangeMarkSeen(message: Message) {
  1.1313 +//        self.emailDisplayDelegate.emailDisplayDidChangeMarkSeen(message: message)
  1.1314 +//    }
  1.1315 +//
  1.1316 +//    func emailDisplayDidDelete(message: Message) {
  1.1317 +//        self.emailDisplayDelegate.emailDisplayDidDelete(message: message)
  1.1318 +//    }
  1.1319 +//
  1.1320 +//    func emailDisplayDidFlag(message: Message) {
  1.1321 +//        self.emailDisplayDelegate.emailDisplayDidFlag(message: message)
  1.1322 +//    }
  1.1323 +//
  1.1324 +//    func emailDisplayDidUnflag(message: Message) {
  1.1325 +//        self.emailDisplayDelegate.emailDisplayDidUnflag(message: message)
  1.1326 +//    }
  1.1327 +//}