merge default IOS-1697
authorAlejandro Gelos <alejandro@pep-project.org>
Wed, 10 Jul 2019 14:04:14 +0200
branchIOS-1697
changeset 93689a9f7f0f3a83
parent 9365 66865ea9b66a
parent 9363 5ec5d62c70ba
child 9369 790ade8bf401
merge default
     1.1 --- a/pEpForiOS/UI/EmailDisplayList/EmailListViewController.swift	Wed Jul 10 13:03:48 2019 +0200
     1.2 +++ b/pEpForiOS/UI/EmailDisplayList/EmailListViewController.swift	Wed Jul 10 14:04:14 2019 +0200
     1.3 @@ -621,12 +621,16 @@
     1.4                  Log.shared.errorAndCrash("No folder")
     1.5                  return
     1.6              }
     1.7 -            lastSelectedIndexPath = indexPath
     1.8 -            tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none)
     1.9 -            if model.shouldEditMessage(indexPath: indexPath) {
    1.10 -                showComposeView()
    1.11 +            if model.isSelectable(messageAt: indexPath) {
    1.12 +                lastSelectedIndexPath = indexPath
    1.13 +                tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none)
    1.14 +                if model.isEditable(messageAt: indexPath) {
    1.15 +                    showComposeView()
    1.16 +                } else {
    1.17 +                    showEmail(forCellAt: indexPath)
    1.18 +                }
    1.19              } else {
    1.20 -                showEmail(forCellAt: indexPath)
    1.21 +                tableView.deselectRow(at: indexPath, animated: true)
    1.22              }
    1.23          }
    1.24      }
    1.25 @@ -871,6 +875,7 @@
    1.26          let replyAction = createReplyAction()
    1.27  
    1.28          let replyAllAction = createReplyAllAction(forRowAt: indexPath)
    1.29 +        let readAction = createReadOrUnReadAction(forRowAt: indexPath)
    1.30  
    1.31          let forwardAction = createForwardAction()
    1.32          let moveToFolderAction = createMoveToFolderAction()
    1.33 @@ -884,6 +889,7 @@
    1.34  
    1.35          alertControler.addAction(forwardAction)
    1.36          alertControler.addAction(moveToFolderAction)
    1.37 +        alertControler.addAction(readAction)
    1.38  
    1.39          if let popoverPresentationController = alertControler.popoverPresentationController {
    1.40              popoverPresentationController.sourceView = tableView
    1.41 @@ -908,6 +914,34 @@
    1.42          }
    1.43      }
    1.44  
    1.45 +    private func createReadOrUnReadAction(forRowAt indexPath: IndexPath) -> UIAlertAction {
    1.46 +        let seenState = model?.viewModel(for: indexPath.row)?.isSeen ?? false
    1.47 +
    1.48 +        var title = ""
    1.49 +        if seenState {
    1.50 +            title = NSLocalizedString("Mark as unread", comment: "EmailList action title")
    1.51 +        } else {
    1.52 +            title = NSLocalizedString("Mark as Read", comment: "EmailList action title")
    1.53 +        }
    1.54 +
    1.55 +        return UIAlertAction(title: title, style: .default) { [weak self] action in
    1.56 +            guard let me = self else {
    1.57 +                Log.shared.errorAndCrash("Lost MySelf")
    1.58 +                return
    1.59 +            }
    1.60 +            guard let cell = me.tableView.cellForRow(at: indexPath) as? EmailListViewCell else {
    1.61 +                Log.shared.errorAndCrash(message: "Cell type is wrong")
    1.62 +                return
    1.63 +            }
    1.64 +            cell.isSeen = !seenState
    1.65 +            if seenState {
    1.66 +                me.model?.markSelectedAsUnread(indexPaths: [indexPath])
    1.67 +            } else {
    1.68 +                me.model?.markSelectedAsRead(indexPaths: [indexPath])
    1.69 +            }
    1.70 +        }
    1.71 +    }
    1.72 +
    1.73      func createCancelAction() -> UIAlertAction {
    1.74          let title = NSLocalizedString("Cancel", comment: "EmailList action title")
    1.75          return  UIAlertAction(title: title, style: .cancel) {
     2.1 --- a/pEpForiOS/UI/EmailDisplayList/EmailListViewModel.swift	Wed Jul 10 13:03:48 2019 +0200
     2.2 +++ b/pEpForiOS/UI/EmailDisplayList/EmailListViewModel.swift	Wed Jul 10 14:04:14 2019 +0200
     2.3 @@ -134,15 +134,24 @@
     2.4          return Folder.localizedName(realName: folderToShow.title)
     2.5      }
     2.6  
     2.7 -    func shouldEditMessage(indexPath: IndexPath) -> Bool {
     2.8 +    func isEditable(messageAt indexPath: IndexPath) -> Bool {
     2.9          let message = messageQueryResults[indexPath.row]
    2.10 -        if message.parent.folderType == .drafts || message.parent.folderType == .outbox {
    2.11 +        if message.parent.folderType == .drafts {
    2.12              return true
    2.13          } else {
    2.14              return false
    2.15          }
    2.16      }
    2.17  
    2.18 +    func isSelectable(messageAt indexPath: IndexPath) -> Bool {
    2.19 +        let message = messageQueryResults[indexPath.row]
    2.20 +        if message.parent.folderType == .outbox {
    2.21 +            return false
    2.22 +        } else {
    2.23 +            return true
    2.24 +        }
    2.25 +    }
    2.26 +
    2.27      // Threading feature is currently non-existing. Keep this code, might help later.
    2.28  //    //check if there are some important settings that have changed to force a reload
    2.29  //    func checkIfSettingsChanged() -> Bool {
     3.1 --- a/pEpForiOSTests/Models/EmailListViewModelTest.swift	Wed Jul 10 13:03:48 2019 +0200
     3.2 +++ b/pEpForiOSTests/Models/EmailListViewModelTest.swift	Wed Jul 10 14:04:14 2019 +0200
     3.3 @@ -1,672 +1,725 @@
     3.4 -////!!!: is WIP (IOS-1495), ignore failing tests for now.
     3.5 +//!!!: is WIP (IOS-1495), ignore failing tests for now.
     3.6 +
     3.7  //
     3.8 -////
     3.9 -////  EmailListViewModelTest.swift
    3.10 -////  pEpForiOSTests
    3.11 -////
    3.12 -////  Created by Xavier Algarra on 22/08/2018.
    3.13 -////  Copyright © 2018 p≡p Security S.A. All rights reserved.
    3.14 +//  EmailListViewModelTest.swift
    3.15 +//  pEpForiOSTests
    3.16  //
    3.17 -//import XCTest
    3.18 -//@testable import pEpForiOS
    3.19 -//@testable import MessageModel
    3.20 +//  Created by Xavier Algarra on 22/08/2018.
    3.21 +//  Copyright © 2018 p≡p Security S.A. All rights reserved.
    3.22 +
    3.23 +import XCTest
    3.24 +@testable import pEpForiOS
    3.25 +@testable import MessageModel
    3.26 +
    3.27 +class EmailListViewModelTest: CoreDataDrivenTestBase {
    3.28 +    var folder: Folder!
    3.29 +    var trashFolder: Folder!
    3.30 +    var outboxFolder: Folder!
    3.31 +    var draftsFolder: Folder!
    3.32 +    var emailListVM : EmailListViewModel!
    3.33 +    var masterViewController: TestMasterViewController!
    3.34 +
    3.35 +    /** this set up a view model with one account and one folder saved **/
    3.36 +    override func setUp() {
    3.37 +        super.setUp()
    3.38 +
    3.39 +        let acc = cdAccount.account()
    3.40 +
    3.41 +        folder = Folder(name: "inbox", parent: nil, account: acc, folderType: .inbox)
    3.42 +        trashFolder = Folder(name: "trash",
    3.43 +                             parent: nil,
    3.44 +                             account: folder.account,
    3.45 +                             folderType: .trash)
    3.46 +        outboxFolder = Folder(name: "outbox", parent: nil, account: acc, folderType: .outbox)
    3.47 +        draftsFolder = Folder(name: "drafts", parent: nil, account: acc, folderType: .drafts)
    3.48 +        moc.saveAndLogErrors()
    3.49 +    }
    3.50 +
    3.51 +    // MARK: - Test section
    3.52 +
    3.53 +    func testViewModelSetUp() {
    3.54 +        setupViewModel()
    3.55 +        emailListVM.startMonitoring()
    3.56 +    }
    3.57 +
    3.58 +    func testCleanInitialSetup() {
    3.59 +        setupViewModel()
    3.60 +        emailListVM.startMonitoring()
    3.61 +        XCTAssertEqual(emailListVM.rowCount, 0)
    3.62 +    }
    3.63 +
    3.64 +    func test10MessagesInInitialSetup() {
    3.65 +         TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder, setUids: true)
    3.66 +        setupViewModel()
    3.67 +        emailListVM.startMonitoring()
    3.68 +        XCTAssertEqual(emailListVM.rowCount, 10)
    3.69 +    }
    3.70 +
    3.71 +    func testGetFolderName() {
    3.72 +        setupViewModel()
    3.73 +        XCTAssertEqual(Folder.localizedName(realName: self.folder.realName), emailListVM.folderName)
    3.74 +    }
    3.75 +
    3.76 +    func testGetDestructiveAction() {
    3.77 +        TestUtil.createMessages(number: 1, engineProccesed: true, inFolder: folder)
    3.78 +        setupViewModel()
    3.79 +        emailListVM.startMonitoring()
    3.80 +        let destructiveAction = emailListVM.getDestructiveActtion(forMessageAt: 0)
    3.81 +
    3.82 +        XCTAssertEqual(destructiveAction, .trash)
    3.83 +    }
    3.84 +
    3.85 +    func testGetDestructiveActionInOutgoingFolderIsTrash() {
    3.86 +        _ = givenThereIsAMessageIn(folderType: .outbox)
    3.87 +        setupViewModel()
    3.88 +        emailListVM.startMonitoring()
    3.89 +        let destructiveAction = emailListVM.getDestructiveActtion(forMessageAt: 0)
    3.90 +
    3.91 +        XCTAssertEqual(destructiveAction, .trash)
    3.92 +    }
    3.93 +
    3.94 +    func testShouldShowToolbarEditButtonsIfItsNotOutboxFolder() {
    3.95 +        setupViewModel()
    3.96 +        emailListVM.startMonitoring()
    3.97 +        var showToolbarButtons = emailListVM.shouldShowToolbarEditButtons()
    3.98 +        XCTAssertTrue(showToolbarButtons)
    3.99 +
   3.100 +        givenThereIsA(folderType: .outbox)
   3.101 +        setupViewModel()
   3.102 +        emailListVM.startMonitoring()
   3.103 +        showToolbarButtons = emailListVM.shouldShowToolbarEditButtons()
   3.104 +        XCTAssertFalse(showToolbarButtons)
   3.105 +    }
   3.106 +
   3.107 +    func testDefaultFilterActiveIsUnread() {
   3.108 +        let messages = TestUtil.createMessages(number: 20, engineProccesed: true, inFolder: folder)
   3.109 +        messages.forEach { (msg) in
   3.110 +            msg.imapFlags.seen = true
   3.111 +        }
   3.112 +        messages[0].imapFlags.seen = false
   3.113 +        messages[2].imapFlags.seen = false
   3.114 +        messages[4].imapFlags.seen = false
   3.115 +        messages[6].imapFlags.seen = false
   3.116 +        messages[8].imapFlags.seen = false
   3.117 +
   3.118 +        setupViewModel()
   3.119 +        emailListVM.startMonitoring()
   3.120 +
   3.121 +        var unreadActive = emailListVM.unreadFilterEnabled()
   3.122 +        XCTAssertFalse(unreadActive)
   3.123 +
   3.124 +        XCTAssertEqual(20, emailListVM.rowCount)
   3.125 +        emailListVM.isFilterEnabled = true
   3.126 +        XCTAssertEqual(5, emailListVM.rowCount)
   3.127 +        setUpViewModelExpectations(expectationDidDeleteDataAt: true)
   3.128 +        let imap = ImapFlags()
   3.129 +        imap.seen = true
   3.130 +        messages[0].imapFlags = imap
   3.131 +        waitForExpectations(timeout: TestUtil.waitTime)
   3.132 +        XCTAssertEqual(4, emailListVM.rowCount)
   3.133 +        unreadActive = emailListVM.unreadFilterEnabled()
   3.134 +        XCTAssertTrue(unreadActive)
   3.135 +        emailListVM.isFilterEnabled = false
   3.136 +        XCTAssertEqual(20, emailListVM.rowCount)
   3.137 +    }
   3.138 +
   3.139 +    func testGetFlagAndMoreAction() {
   3.140 +        let messages = TestUtil.createMessages(number: 1, engineProccesed: true, inFolder: folder)
   3.141 +        setupViewModel()
   3.142 +        emailListVM.startMonitoring()
   3.143 +        var flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   3.144 +        let moreAction = emailListVM.getMoreAction(forMessageAt: 0)
   3.145 +
   3.146 +        XCTAssertEqual(flagAction, .flag)
   3.147 +        XCTAssertEqual(moreAction, .more)
   3.148 +
   3.149 +        messages[0].imapFlags.flagged = true
   3.150 +        messages[0].save()
   3.151 +
   3.152 +        flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   3.153 +
   3.154 +        XCTAssertEqual(flagAction, .unflag)
   3.155 +    }
   3.156 +
   3.157 +    func testGetFlagAndMoreActionInOutgoingFolderIsNil() {
   3.158 +        givenThereIsAMessageIn(folderType: .outbox)
   3.159 +        setupViewModel()
   3.160 +        emailListVM.startMonitoring()
   3.161 +
   3.162 +        let flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   3.163 +        let moreAction = emailListVM.getMoreAction(forMessageAt: 0)
   3.164 +
   3.165 +        XCTAssertEqual(flagAction, nil)
   3.166 +        XCTAssertEqual(moreAction, nil)
   3.167 +    }
   3.168 +
   3.169 +    func testGetFlagAndMoreActionInDraftFolderIsNil() {
   3.170 +        givenThereIsAMessageIn(folderType: .drafts)
   3.171 +        setupViewModel()
   3.172 +        emailListVM.startMonitoring()
   3.173 +        let flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   3.174 +        let moreAction = emailListVM.getMoreAction(forMessageAt: 0)
   3.175 +
   3.176 +        XCTAssertEqual(flagAction, nil)
   3.177 +        XCTAssertEqual(moreAction, nil)
   3.178 +    }
   3.179 +
   3.180 +    func testAccountExists() {
   3.181 +        setupViewModel()
   3.182 +        emailListVM.startMonitoring()
   3.183 +        var noAccounts = emailListVM.showLoginView
   3.184 +
   3.185 +        XCTAssertFalse(noAccounts)
   3.186 +
   3.187 +        cdAccount.delete()
   3.188 +        setupViewModel()
   3.189 +        noAccounts = emailListVM.showLoginView
   3.190 +
   3.191 +        XCTAssertTrue(noAccounts)
   3.192 +    }
   3.193 +
   3.194 +    // MARK: - Search section
   3.195 +
   3.196 +    func testSetSearchFilterWith0results() {
   3.197 +        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   3.198 +        setupViewModel()
   3.199 +        emailListVM.startMonitoring()
   3.200 +        emailListVM.setSearch(forSearchText: "blabla@blabla.com")
   3.201 +        XCTAssertEqual(emailListVM.rowCount, 0)
   3.202 +    }
   3.203 +
   3.204 +    func testRemoveSearchFilterAfter0Results() {
   3.205 +        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   3.206 +        setupViewModel()
   3.207 +        emailListVM.startMonitoring()
   3.208 +        XCTAssertEqual(emailListVM.rowCount, 10)
   3.209 +        emailListVM.setSearch(forSearchText: "blabla@blabla.com")
   3.210 +        XCTAssertEqual(emailListVM.rowCount, 0)
   3.211 +        emailListVM.removeSearch()
   3.212 +        XCTAssertEqual(emailListVM.rowCount, 10)
   3.213 +    }
   3.214 +
   3.215 +    func testSetSearchFilterAddressWith3results() {
   3.216 +        let textToSearch = "searchTest@mail.com"
   3.217 +        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   3.218 +        TestUtil.createMessage(inFolder: folder,
   3.219 +                      from: Identity(address: textToSearch),
   3.220 +                      tos: [folder.account.user],
   3.221 +                      uid: 666).save()
   3.222 +        TestUtil.createMessage(inFolder: folder,
   3.223 +                      from: Identity(address: textToSearch),
   3.224 +                      tos: [folder.account.user],
   3.225 +                      uid: 667).save()
   3.226 +        TestUtil.createMessage(inFolder: folder,
   3.227 +                      from: Identity(address: textToSearch),
   3.228 +                      tos: [folder.account.user],
   3.229 +                      uid: 668).save()
   3.230 +        setupViewModel()
   3.231 +        emailListVM.startMonitoring()
   3.232 +        XCTAssertEqual(emailListVM.rowCount, 13)
   3.233 +        emailListVM.setSearch(forSearchText: textToSearch)
   3.234 +        XCTAssertEqual(emailListVM.rowCount, 3)
   3.235 +    }
   3.236 +
   3.237 +    func testSetSearchFilterShortMessageWith1results() {
   3.238 +        let textToSearch = "searchTest"
   3.239 +        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   3.240 +        TestUtil.createMessage(inFolder: folder,
   3.241 +                      from: Identity(address: "mail@mail.com"),
   3.242 +                      tos: [folder.account.user],
   3.243 +                      shortMessage: textToSearch,
   3.244 +                      uid: 666).save()
   3.245 +        setupViewModel()
   3.246 +        emailListVM.startMonitoring()
   3.247 +        XCTAssertEqual(emailListVM.rowCount, 11)
   3.248 +        emailListVM.setSearch(forSearchText: textToSearch)
   3.249 +        XCTAssertEqual(emailListVM.rowCount, 1)
   3.250 +    }
   3.251 +
   3.252 +    func testSetSearchMultipleSitesMatchInMessagesWith2results() {
   3.253 +        let textToSearch = "searchTest"
   3.254 +        let longText = "bla " + textToSearch + " bla"
   3.255 +        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   3.256 +        TestUtil.createMessage(inFolder: folder,
   3.257 +                      from: Identity(address: "mail@mail.com"),
   3.258 +                      shortMessage: textToSearch,
   3.259 +                      uid: 666).save()
   3.260 +        TestUtil.createMessage(inFolder: folder,
   3.261 +                      from: Identity(address: "mail@mail.com"),
   3.262 +                      tos: [folder.account.user],
   3.263 +                      longMessage: longText,
   3.264 +                      uid: 667).save()
   3.265 +        setupViewModel()
   3.266 +        emailListVM.startMonitoring()
   3.267 +        XCTAssertEqual(emailListVM.rowCount, 12)
   3.268 +        emailListVM.setSearch(forSearchText: textToSearch)
   3.269 +        XCTAssertEqual(emailListVM.rowCount, 2)
   3.270 +    }
   3.271 +
   3.272 +    // Threading feature is currently non-existing. Keep this code, might help later.
   3.273 +//    //thread view nos is totaly disabled that means always false
   3.274 +//    func testCheckIfSettingsChanged() {
   3.275 +//        setupViewModel()
   3.276 +//        emailListVM.startMonitoring()
   3.277 +//        XCTAssertFalse(AppSettings.threadedViewEnabled)
   3.278 +//        AppSettings.threadedViewEnabled = true
   3.279 +//        XCTAssertFalse(emailListVM.checkIfSettingsChanged())
   3.280 +//    }
   3.281 +
   3.282 +    // MARK: - cell for row
   3.283 +/*
   3.284 +    func testIndexFromMessage() {
   3.285 +        let msgs = TestUtil.createMessages(number: 10, inFolder: folder)
   3.286 +        setupViewModel()
   3.287 +        emailListVM.startMonitoring()
   3.288 +        var index = emailListVM.index(of: msgs[0])
   3.289 +        XCTAssertEqual(index, 9)
   3.290 +        index = emailListVM.index(of: msgs[9])
   3.291 +        XCTAssertEqual(index, 0)
   3.292 +    }*/
   3.293 +
   3.294 +    func testViewModel() {
   3.295 +        let msg = TestUtil.createMessage(inFolder: folder, from: folder.account.user, uid: 1)
   3.296 +        msg.save()
   3.297 +        setupViewModel()
   3.298 +        emailListVM.startMonitoring()
   3.299 +        let index = emailListVM.index(of: msg)
   3.300 +        guard let ind = index else {
   3.301 +            XCTFail()
   3.302 +            return
   3.303 +        }
   3.304 +        let vm = emailListVM.viewModel(for: ind)
   3.305 +        XCTAssertEqual(vm?.message(), msg)
   3.306 +        XCTAssertEqual(vm?.subject, msg.shortMessage)
   3.307 +    }
   3.308 +
   3.309 +//    func testSetUpFilterViewModel() {
   3.310 +//        var filterEnabled = false
   3.311 +//        setupViewModel()
   3.312 +//        XCTAssertEqual(filterEnabled, emailListVM.isFilterEnabled)
   3.313 +//        filterEnabled = true
   3.314 +//        setUpViewModelExpectations(expectedUpdateView: true)
   3.315 +//        emailListVM.isFilterEnabled = filterEnabled
   3.316 +//        waitForExpectations(timeout: TestUtil.waitTime)
   3.317 +//        XCTAssertEqual(filterEnabled, emailListVM.isFilterEnabled)
   3.318 +//    }
   3.319 +
   3.320 +    func testNewMessageReceivedAndDisplayedInTheCorrectPosition() {
   3.321 +        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   3.322 +        setupViewModel()
   3.323 +        emailListVM.startMonitoring()
   3.324 +        XCTAssertEqual(emailListVM.rowCount, 10)
   3.325 +        setUpViewModelExpectations(expectationDidInsertDataAt: true)
   3.326 +        let msg = TestUtil.createMessage(inFolder: folder, from: folder.account.user)
   3.327 +        msg.save()
   3.328 +        waitForExpectations(timeout: TestUtil.waitTime)
   3.329 +        XCTAssertEqual(emailListVM.rowCount, 11)
   3.330 +        var index = emailListVM.index(of: msg)
   3.331 +        XCTAssertEqual(index, 0)
   3.332 +        let nonShownMsg = TestUtil.createMessage(inFolder: trashFolder, from: folder.account.user)
   3.333 +        nonShownMsg.save()
   3.334 +        XCTAssertEqual(emailListVM.rowCount, 11)
   3.335 +        index = emailListVM.index(of: msg)
   3.336 +        XCTAssertEqual(index, 0)
   3.337 +    }
   3.338 +
   3.339 +    func testNewMessageUpdateReceivedAndDisplayed() {
   3.340 +        let numMails = 10
   3.341 +        TestUtil.createMessages(number: numMails, engineProccesed: true, inFolder: folder)
   3.342 +        let msg = TestUtil.createMessage(inFolder: folder,
   3.343 +                                         from: folder.account.user,
   3.344 +                                         uid: numMails + 1)
   3.345 +        msg.imapFlags.flagged = false
   3.346 +        msg.save()
   3.347 +        XCTAssertFalse((msg.imapFlags.flagged))
   3.348 +        setupViewModel()
   3.349 +        emailListVM.startMonitoring()
   3.350 +        XCTAssertEqual(emailListVM.rowCount, 11)
   3.351 +        msg.imapFlags.flagged = true
   3.352 +        msg.save()
   3.353 +        waitForExpectations(timeout: TestUtil.waitTime)
   3.354 +        var index = emailListVM.index(of: msg)
   3.355 +        if let ind = index {
   3.356 +            let newMsg = emailListVM.message(representedByRowAt: IndexPath(row: ind, section: 0))
   3.357 +            XCTAssertTrue((newMsg?.imapFlags.flagged)!)
   3.358 +        } else {
   3.359 +            XCTFail()
   3.360 +        }
   3.361 +
   3.362 +        let nonShownMsg = TestUtil.createMessage(inFolder: trashFolder, from: folder.account.user)
   3.363 +        nonShownMsg.save()
   3.364 +        XCTAssertEqual(emailListVM.rowCount, 11)
   3.365 +        index = emailListVM.index(of: nonShownMsg)
   3.366 +        XCTAssertNil(index)
   3.367 +    }
   3.368 +
   3.369 +    func testNewMessageDeleteReceivedAndDisplayed() {
   3.370 +        let numMails = 10
   3.371 +        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   3.372 +        let msg = TestUtil.createMessage(inFolder: folder,
   3.373 +                                         from: folder.account.user,
   3.374 +                                         uid: numMails + 1)
   3.375 +        msg.imapFlags.flagged = false
   3.376 +        msg.save()
   3.377 +        XCTAssertFalse((msg.imapFlags.flagged))
   3.378 +        setupViewModel()
   3.379 +        emailListVM.startMonitoring()
   3.380 +        XCTAssertEqual(emailListVM.rowCount, 11)
   3.381 +        setUpViewModelExpectations(expectationDidDeleteDataAt: true)
   3.382 +        msg.delete()
   3.383 +        waitForExpectations(timeout: TestUtil.waitTime)
   3.384 +        var index = emailListVM.index(of: msg)
   3.385 +        XCTAssertNil(index)
   3.386 +        XCTAssertEqual(emailListVM.rowCount, 10)
   3.387 +
   3.388 +        let nonShownMsg = TestUtil.createMessage(inFolder: trashFolder, from: folder.account.user)
   3.389 +        nonShownMsg.save()
   3.390 +        nonShownMsg.delete()
   3.391 +        XCTAssertEqual(emailListVM.rowCount, 10)
   3.392 +        index = emailListVM.index(of: nonShownMsg)
   3.393 +        XCTAssertNil(index)
   3.394 +    }
   3.395 +
   3.396 +    func testgetMoveToFolderViewModel() {
   3.397 +        TestUtil.createMessages(number: 4, inFolder: folder)
   3.398 +        let index: [IndexPath] = [IndexPath(row: 0, section: 1),
   3.399 +                                  IndexPath(row: 0, section: 2)]
   3.400 +        setupViewModel()
   3.401 +        emailListVM.startMonitoring()
   3.402 +
   3.403 +        let accountvm = emailListVM.getMoveToFolderViewModel(forSelectedMessages: index)
   3.404 +
   3.405 +        let postMessages = accountvm!.items[0].messages
   3.406 +        XCTAssertEqual(index.count, postMessages.count)
   3.407 +    }
   3.408 +
   3.409 +    func testFlagUnflagMessageIsImmediate() {
   3.410 +        let message = givenThereIsAMessageIn(folderType: .inbox)
   3.411 +        let messageMoc = message?.cdMessage()?.managedObjectContext
   3.412 +        setupViewModel()
   3.413 +        emailListVM.startMonitoring()
   3.414 +
   3.415 +        let indexPath = IndexPath(row: 0, section: 0)
   3.416 +
   3.417 +        emailListVM.setFlagged(forIndexPath: [indexPath])
   3.418 +        guard let isFlagged = emailListVM.viewModel(for: indexPath.row)?.isFlagged else {
   3.419 +            XCTFail()
   3.420 +            return
   3.421 +        }
   3.422 +
   3.423 +        emailListVM.unsetFlagged(forIndexPath: [indexPath])
   3.424 +        guard let isNotFlagged = emailListVM.viewModel(for: indexPath.row)?.isFlagged else {
   3.425 +            XCTFail()
   3.426 +            return
   3.427 +        }
   3.428 +        let messageDidSaveExpectation = expectation(description: "message is saved")
   3.429 +        messageDidSaveExpectation.expectedFulfillmentCount = 8
   3.430 +
   3.431 +        NotificationCenter.default
   3.432 +            .addObserver(forName: Notification.Name.NSManagedObjectContextDidSave,
   3.433 +                         object: messageMoc,
   3.434 +                         queue: nil) { (notification) in
   3.435 +                            print("fulfill")
   3.436 +                            messageDidSaveExpectation.fulfill()
   3.437 +        }
   3.438 +
   3.439 +        let isImmediate = isFlagged != isNotFlagged
   3.440 +        XCTAssertTrue(isImmediate)
   3.441 +        wait(for: [messageDidSaveExpectation], timeout: UnitTestUtils.waitTime)
   3.442 +    }
   3.443 +
   3.444 +    func testMessageInOutboxAreNonEditableAndNonSelectable() {
   3.445 +        TestUtil.createMessage(uid: 1, inFolder: outboxFolder)
   3.446 +        moc.saveAndLogErrors()
   3.447 +        setupViewModel(forfolder: outboxFolder)
   3.448 +        emailListVM.startMonitoring()
   3.449 +        XCTAssertEqual(1, emailListVM.rowCount)
   3.450 +        let notEditable = emailListVM.isEditable(messageAt: IndexPath(row: 0, section: 0))
   3.451 +        XCTAssertFalse(notEditable)
   3.452 +        let notSelectable = emailListVM.isSelectable(messageAt: IndexPath(row: 0, section: 0))
   3.453 +        XCTAssertFalse(notSelectable)
   3.454 +    }
   3.455 +
   3.456 +    func testMessageInInboxAreOnlySelectable() {
   3.457 +        TestUtil.createMessage(uid: 1, inFolder: folder)
   3.458 +        moc.saveAndLogErrors()
   3.459 +        setupViewModel()
   3.460 +        emailListVM.startMonitoring()
   3.461 +        XCTAssertEqual(1, emailListVM.rowCount)
   3.462 +        let isEditable = emailListVM.isEditable(messageAt: IndexPath(row: 0, section: 0))
   3.463 +        XCTAssertFalse(isEditable)
   3.464 +        let isSelectable = emailListVM.isSelectable(messageAt: IndexPath(row: 0, section: 0))
   3.465 +        XCTAssertTrue(isSelectable)
   3.466 +    }
   3.467 +
   3.468 +    func testMessageInDraftsAreEditableAndSelectable() {
   3.469 +        TestUtil.createMessage(uid: 1, inFolder: draftsFolder)
   3.470 +        moc.saveAndLogErrors()
   3.471 +        setupViewModel(forfolder: draftsFolder)
   3.472 +        emailListVM.startMonitoring()
   3.473 +        XCTAssertEqual(1, emailListVM.rowCount)
   3.474 +        let isEditable = emailListVM.isEditable(messageAt: IndexPath(row: 0, section: 0))
   3.475 +        XCTAssertTrue(isEditable)
   3.476 +        let isSelectable = emailListVM.isSelectable(messageAt: IndexPath(row: 0, section: 0))
   3.477 +        XCTAssertTrue(isSelectable)
   3.478 +    }
   3.479 +
   3.480 +    // Mark: - setting up
   3.481 +
   3.482 +    fileprivate func setUpViewModel(forFolder folder: Folder, masterViewController: TestMasterViewController) {
   3.483 +        self.emailListVM = EmailListViewModel(emailListViewModelDelegate: masterViewController, folderToShow: folder)
   3.484 +    }
   3.485 +
   3.486 +    fileprivate func setupViewModel(forfolder internalFolder: Folder? = nil) {
   3.487 +        let folderToUse: Folder
   3.488 +        if internalFolder == nil {
   3.489 +            folderToUse = folder
   3.490 +        } else {
   3.491 +            folderToUse = internalFolder!
   3.492 +        }
   3.493 +        createViewModelWithExpectations(forFolder: folderToUse, expectedUpdateView: true)
   3.494 +    }
   3.495 +
   3.496 +    /*fileprivate func setSearchFilter(text: String) {
   3.497 +        setNewUpdateViewExpectation()
   3.498 +        emailListVM.setSearchFilter(forSearchText: text)
   3.499 +        waitForExpectations(timeout: TestUtil.waitTime)
   3.500 +    }
   3.501 +
   3.502 +    fileprivate func removeSearchFilter() {
   3.503 +        setNewUpdateViewExpectation()
   3.504 +        emailListVM.removeSearchFilter()
   3.505 +        waitForExpectations(timeout: TestUtil.waitTime)
   3.506 +    }*/
   3.507 +
   3.508 +    fileprivate func setNewUpdateViewExpectation() {
   3.509 +        let updateViewExpectation = expectation(description: "UpdateViewCalled")
   3.510 +        masterViewController.expectationUpdateViewCalled = updateViewExpectation
   3.511 +    }
   3.512 +
   3.513 +    fileprivate func createViewModelWithExpectations(forFolder folder: Folder, expectedUpdateView: Bool) {
   3.514 +        let viewModelTestDelegate = TestMasterViewController()
   3.515 +        setUpViewModel(forFolder: folder, masterViewController: viewModelTestDelegate)
   3.516 +    }
   3.517 +
   3.518 +    fileprivate func setUpViewModelExpectations(expectedUpdateView: Bool = false,
   3.519 +                                                expectationDidInsertDataAt: Bool = false,
   3.520 +                                                expectationDidUpdateDataAt: Bool = false,
   3.521 +                                                expectationDidDeleteDataAt: Bool = false ) {
   3.522 +        var expectationUpdateViewCalled: XCTestExpectation?
   3.523 +        if expectedUpdateView {
   3.524 +            expectationUpdateViewCalled = expectation(description: "UpdateViewCalled")
   3.525 +        }
   3.526 +
   3.527 +        var excpectationDidInsertDataAtCalled: XCTestExpectation?
   3.528 +        if expectationDidInsertDataAt {
   3.529 +            excpectationDidInsertDataAtCalled =
   3.530 +                expectation(description: "excpectationDidInsertDataAtCalled")
   3.531 +        }
   3.532 +
   3.533 +        var excpectationDidUpdateDataAtCalled: XCTestExpectation?
   3.534 +        if expectationDidUpdateDataAt {
   3.535 +            excpectationDidUpdateDataAtCalled =
   3.536 +                expectation(description: "excpectationDidUpdateDataAtCalled")
   3.537 +        }
   3.538 +
   3.539 +        var excpectationDidDeleteDataAtCalled: XCTestExpectation?
   3.540 +        if expectationDidDeleteDataAt {
   3.541 +            excpectationDidDeleteDataAtCalled =
   3.542 +                expectation(description: "excpectationDidInsertDataAtCalled")
   3.543 +        }
   3.544 +
   3.545 +        emailListVM.emailListViewModelDelegate = TestMasterViewController(
   3.546 +            expectationUpdateView: expectationUpdateViewCalled,
   3.547 +            expectationDidInsertDataAt: excpectationDidInsertDataAtCalled,
   3.548 +            expectationDidUpdateDataAt: excpectationDidUpdateDataAtCalled,
   3.549 +            expectationDidRemoveDataAt: excpectationDidDeleteDataAtCalled)
   3.550 +    }
   3.551 +
   3.552 +    fileprivate func getSafeLastLookAt() -> Date {
   3.553 +        guard let safeLastLookedAt = folder?.lastLookedAt as Date? else {
   3.554 +            XCTFail()
   3.555 +            return Date()
   3.556 +        }
   3.557 +        return safeLastLookedAt
   3.558 +    }
   3.559 +
   3.560 +    private func givenThereIsA(folderType: FolderType) {
   3.561 +        folder = Folder(name: "-", parent: folder, account: account, folderType: folderType)
   3.562 +        folder.save()
   3.563 +    }
   3.564 +
   3.565 +    @discardableResult private func givenThereIsAMessageIn(folderType: FolderType) -> Message? {
   3.566 +        givenThereIsA(folderType: folderType)
   3.567 +        return TestUtil.createMessages(number: 1, engineProccesed: true, inFolder: folder).first
   3.568 +    }
   3.569 +}
   3.570 +
   3.571 +class TestMasterViewController: EmailListViewModelDelegate {
   3.572 +
   3.573 +    var expectationUpdateViewCalled: XCTestExpectation?
   3.574 +    var excpectationDidInsertDataAtCalled: XCTestExpectation?
   3.575 +    var expectationDidUpdateDataAtCalled: XCTestExpectation?
   3.576 +    var expectationDidRemoveDataAtCalled: XCTestExpectation?
   3.577 +    var expetationDidChangeSeenStateForDataAt: XCTestExpectation?
   3.578 +
   3.579 +    init(expectationUpdateView: XCTestExpectation? = nil,
   3.580 +         expectationDidInsertDataAt: XCTestExpectation? = nil,
   3.581 +         expectationDidUpdateDataAt: XCTestExpectation? = nil,
   3.582 +         expectationDidRemoveDataAt: XCTestExpectation? = nil) {
   3.583 +        self.expectationUpdateViewCalled = expectationUpdateView
   3.584 +        self.excpectationDidInsertDataAtCalled = expectationDidInsertDataAt
   3.585 +        self.expectationDidUpdateDataAtCalled = expectationDidUpdateDataAt
   3.586 +        self.expectationDidRemoveDataAtCalled = expectationDidRemoveDataAt
   3.587 +    }
   3.588 +
   3.589 +    func willReceiveUpdates(viewModel: EmailListViewModel) {
   3.590 +        //not yet defined
   3.591 +        XCTFail()
   3.592 +    }
   3.593 +
   3.594 +    func allUpdatesReceived(viewModel: EmailListViewModel) {
   3.595 +        //not yet defined
   3.596 +        XCTFail()
   3.597 +    }
   3.598 +
   3.599 +    func reloadData(viewModel: EmailListViewModel) {
   3.600 +        //not yet defined
   3.601 +        XCTFail()
   3.602 +    }
   3.603 +
   3.604 +
   3.605 +    func emailListViewModel(viewModel: EmailListViewModel,
   3.606 +                            didInsertDataAt indexPaths: [IndexPath]) {
   3.607 +        if let excpectationDidInsertDataAtCalled = excpectationDidInsertDataAtCalled {
   3.608 +            excpectationDidInsertDataAtCalled.fulfill()
   3.609 +        } else {
   3.610 +            XCTFail()
   3.611 +        }
   3.612 +    }
   3.613 +
   3.614 +    func emailListViewModel(viewModel: EmailListViewModel,
   3.615 +                            didUpdateDataAt indexPaths: [IndexPath]) {
   3.616 +        if let expectationDidUpdateDataAtCalled = expectationDidUpdateDataAtCalled {
   3.617 +            expectationDidUpdateDataAtCalled.fulfill()
   3.618 +        } else {
   3.619 +            XCTFail()
   3.620 +        }
   3.621 +    }
   3.622 +
   3.623 +    func emailListViewModel(viewModel: EmailListViewModel,
   3.624 +                            didChangeSeenStateForDataAt indexPaths: [IndexPath]) {
   3.625 +        XCTFail("Currently unused in tests. Should not be called")
   3.626 +    }
   3.627 +
   3.628 +    func emailListViewModel(viewModel: EmailListViewModel,
   3.629 +                            didRemoveDataAt indexPaths: [IndexPath]) {
   3.630 +        if let expectationDidRemoveDataAtCalled = expectationDidRemoveDataAtCalled {
   3.631 +            expectationDidRemoveDataAtCalled.fulfill()
   3.632 +        } else {
   3.633 +            XCTFail()
   3.634 +        }
   3.635 +    }
   3.636 +
   3.637 +    func emailListViewModel(viewModel: EmailListViewModel,
   3.638 +                            didMoveData atIndexPath: IndexPath,
   3.639 +                            toIndexPath: IndexPath) {
   3.640 +        XCTFail()
   3.641 +    }
   3.642 +//not exist anymore
   3.643 +    func emailListViewModel(viewModel: EmailListViewModel,
   3.644 +                            didUpdateUndisplayedMessage message: Message) {
   3.645 +        XCTFail()
   3.646 +    }
   3.647 +
   3.648 +    func toolbarIs(enabled: Bool) {
   3.649 +        XCTFail()
   3.650 +    }
   3.651 +
   3.652 +    func showUnflagButton(enabled: Bool) {
   3.653 +        XCTFail()
   3.654 +    }
   3.655 +
   3.656 +    func showUnreadButton(enabled: Bool) {
   3.657 +        XCTFail()
   3.658 +    }
   3.659 +
   3.660 +    func checkIfSplitNeedsUpdate(indexpath: [IndexPath]) {
   3.661 +        XCTFail()
   3.662 +    }
   3.663 +
   3.664 +    //not exist anymore
   3.665 +    func updateView() {
   3.666 +        if let expectationUpdateViewCalled = expectationUpdateViewCalled {
   3.667 +            expectationUpdateViewCalled.fulfill()
   3.668 +        } else {
   3.669 +            XCTFail()
   3.670 +        }
   3.671 +    }
   3.672 +}
   3.673 +
   3.674 +//class TestServer: MessageQueryResults {
   3.675 +//    var results: [Message] = [Message]()
   3.676  //
   3.677 -//class EmailListViewModelTest: CoreDataDrivenTestBase {
   3.678 -//    var folder: Folder!
   3.679 -//    var trashFolder: Folder!
   3.680 -//    var emailListVM : EmailListViewModel!
   3.681 -//    var masterViewController: TestMasterViewController!
   3.682 -//
   3.683 -//    /** this set up a view model with one account and one folder saved **/
   3.684 -//    override func setUp() {
   3.685 -//        super.setUp()
   3.686 -//
   3.687 -//        let acc = cdAccount.account()
   3.688 -//
   3.689 -//        folder = Folder(name: "inbox", parent: nil, account: acc, folderType: .inbox)
   3.690 -//        folder.save()
   3.691 -//        trashFolder = Folder(name: "trash",
   3.692 -//                             parent: nil,
   3.693 -//                             account: folder.account,
   3.694 -//                             folderType: .trash)
   3.695 -//        trashFolder.save()
   3.696 +//    required init(withFolder folder: Folder) {
   3.697 +//        super.init(withDisplayableFolder: folder)
   3.698  //    }
   3.699  //
   3.700 -//    // MARK: - Test section
   3.701  //
   3.702 -//    func testViewModelSetUp() {
   3.703 -//        setupViewModel()
   3.704 -//        emailListVM.startMonitoring()
   3.705 +//    override var count: Int {
   3.706 +//        return results.count
   3.707  //    }
   3.708  //
   3.709 -//    func testCleanInitialSetup() {
   3.710 -//        setupViewModel()
   3.711 -//        emailListVM.startMonitoring()
   3.712 -//        XCTAssertEqual(emailListVM.rowCount, 0)
   3.713 +//    override subscript(index: Int) -> Message {
   3.714 +//        return results[index]
   3.715  //    }
   3.716  //
   3.717 -//    func test10MessagesInInitialSetup() {
   3.718 -//         TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder, setUids: true)
   3.719 -//        setupViewModel()
   3.720 -//        emailListVM.startMonitoring()
   3.721 -//        XCTAssertEqual(emailListVM.rowCount, 10)
   3.722 +//    override func startMonitoring() throws {
   3.723 +//
   3.724  //    }
   3.725  //
   3.726 -//    func testGetFolderName() {
   3.727 -//        setupViewModel()
   3.728 -//        XCTAssertEqual(Folder.localizedName(realName: self.folder.realName), emailListVM.folderName)
   3.729 +//    func insertData(message: Message) {
   3.730 +//        results.append(message)
   3.731 +//        let ip = IndexPath(row: results.firstIndex(of: message)!, section: 0)
   3.732 +//        delegate?.didInsert(indexPath: ip)
   3.733  //    }
   3.734  //
   3.735 -//    func testGetDestructiveAction() {
   3.736 -//        TestUtil.createMessages(number: 1, engineProccesed: true, inFolder: folder)
   3.737 -//        setupViewModel()
   3.738 -//        emailListVM.startMonitoring()
   3.739 -//        let destructiveAction = emailListVM.getDestructiveActtion(forMessageAt: 0)
   3.740 -//
   3.741 -//        XCTAssertEqual(destructiveAction, .trash)
   3.742 +//    func updateData(message: Message) {
   3.743 +//        let ip = IndexPath(row: results.firstIndex(of: message)!, section: 0)
   3.744 +//        delegate?.didUpdate(indexPath: ip)
   3.745  //    }
   3.746  //
   3.747 -//    func testGetDestructiveActionInOutgoingFolderIsTrash() {
   3.748 -//        _ = givenThereIsAMessageIn(folderType: .outbox)
   3.749 -//        setupViewModel()
   3.750 -//        emailListVM.startMonitoring()
   3.751 -//        let destructiveAction = emailListVM.getDestructiveActtion(forMessageAt: 0)
   3.752 -//
   3.753 -//        XCTAssertEqual(destructiveAction, .trash)
   3.754 +//    func deleteData(message: Message) {
   3.755 +//        let index = results.firstIndex(of: message)
   3.756 +//        results.remove(at: index!)
   3.757 +//        let ip = IndexPath(row: index!, section: 0)
   3.758 +//        delegate?.didDelete(indexPath: ip)
   3.759  //    }
   3.760  //
   3.761 -//    func testShouldShowToolbarEditButtonsIfItsNotOutboxFolder() {
   3.762 -//        setupViewModel()
   3.763 -//        emailListVM.startMonitoring()
   3.764 -//        var showToolbarButtons = emailListVM.shouldShowToolbarEditButtons()
   3.765 -//        XCTAssertTrue(showToolbarButtons)
   3.766 -//
   3.767 -//        givenThereIsA(folderType: .outbox)
   3.768 -//        setupViewModel()
   3.769 -//        emailListVM.startMonitoring()
   3.770 -//        showToolbarButtons = emailListVM.shouldShowToolbarEditButtons()
   3.771 -//        XCTAssertFalse(showToolbarButtons)
   3.772 -//    }
   3.773 -//
   3.774 -//    func testDefaultFilterActiveIsUnread() {
   3.775 -//        let messages = TestUtil.createMessages(number: 20, engineProccesed: true, inFolder: folder)
   3.776 -//        messages.forEach { (msg) in
   3.777 -//            msg.imapFlags.seen = true
   3.778 -//        }
   3.779 -//        messages[0].imapFlags.seen = false
   3.780 -//        messages[2].imapFlags.seen = false
   3.781 -//        messages[4].imapFlags.seen = false
   3.782 -//        messages[6].imapFlags.seen = false
   3.783 -//        messages[8].imapFlags.seen = false
   3.784 -//
   3.785 -//        setupViewModel()
   3.786 -//        emailListVM.startMonitoring()
   3.787 -//
   3.788 -//        var unreadActive = emailListVM.unreadFilterEnabled()
   3.789 -//        XCTAssertFalse(unreadActive)
   3.790 -//
   3.791 -//        XCTAssertEqual(20, emailListVM.rowCount)
   3.792 -//        emailListVM.isFilterEnabled = true
   3.793 -//        XCTAssertEqual(5, emailListVM.rowCount)
   3.794 -//        setUpViewModelExpectations(expectationDidDeleteDataAt: true)
   3.795 -//        let imap = ImapFlags()
   3.796 -//        imap.seen = true
   3.797 -//        messages[0].imapFlags = imap
   3.798 -//        waitForExpectations(timeout: TestUtil.waitTime)
   3.799 -//        XCTAssertEqual(4, emailListVM.rowCount)
   3.800 -//        unreadActive = emailListVM.unreadFilterEnabled()
   3.801 -//        XCTAssertTrue(unreadActive)
   3.802 -//        emailListVM.isFilterEnabled = false
   3.803 -//        XCTAssertEqual(20, emailListVM.rowCount)
   3.804 -//    }
   3.805 -//
   3.806 -//    func testGetFlagAndMoreAction() {
   3.807 -//        let messages = TestUtil.createMessages(number: 1, engineProccesed: true, inFolder: folder)
   3.808 -//        setupViewModel()
   3.809 -//        emailListVM.startMonitoring()
   3.810 -//        var flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   3.811 -//        let moreAction = emailListVM.getMoreAction(forMessageAt: 0)
   3.812 -//
   3.813 -//        XCTAssertEqual(flagAction, .flag)
   3.814 -//        XCTAssertEqual(moreAction, .more)
   3.815 -//
   3.816 -//        messages[0].imapFlags.flagged = true
   3.817 -//        messages[0].save()
   3.818 -//
   3.819 -//        flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   3.820 -//
   3.821 -//        XCTAssertEqual(flagAction, .unflag)
   3.822 -//    }
   3.823 -//
   3.824 -//    func testGetFlagAndMoreActionInOutgoingFolderIsNil() {
   3.825 -//        givenThereIsAMessageIn(folderType: .outbox)
   3.826 -//        setupViewModel()
   3.827 -//        emailListVM.startMonitoring()
   3.828 -//
   3.829 -//        let flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   3.830 -//        let moreAction = emailListVM.getMoreAction(forMessageAt: 0)
   3.831 -//
   3.832 -//        XCTAssertEqual(flagAction, nil)
   3.833 -//        XCTAssertEqual(moreAction, nil)
   3.834 -//    }
   3.835 -//
   3.836 -//    func testGetFlagAndMoreActionInDraftFolderIsNil() {
   3.837 -//        givenThereIsAMessageIn(folderType: .drafts)
   3.838 -//        setupViewModel()
   3.839 -//        emailListVM.startMonitoring()
   3.840 -//        let flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   3.841 -//        let moreAction = emailListVM.getMoreAction(forMessageAt: 0)
   3.842 -//
   3.843 -//        XCTAssertEqual(flagAction, nil)
   3.844 -//        XCTAssertEqual(moreAction, nil)
   3.845 -//    }
   3.846 -//
   3.847 -//    func testAccountExists() {
   3.848 -//        setupViewModel()
   3.849 -//        emailListVM.startMonitoring()
   3.850 -//        var noAccounts = emailListVM.showLoginView
   3.851 -//
   3.852 -//        XCTAssertFalse(noAccounts)
   3.853 -//
   3.854 -//        cdAccount.delete()
   3.855 -//        setupViewModel()
   3.856 -//        noAccounts = emailListVM.showLoginView
   3.857 -//
   3.858 -//        XCTAssertTrue(noAccounts)
   3.859 -//    }
   3.860 -//
   3.861 -//    // MARK: - Search section
   3.862 -//
   3.863 -//    func testSetSearchFilterWith0results() {
   3.864 -//        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   3.865 -//        setupViewModel()
   3.866 -//        emailListVM.startMonitoring()
   3.867 -//        emailListVM.setSearch(forSearchText: "blabla@blabla.com")
   3.868 -//        XCTAssertEqual(emailListVM.rowCount, 0)
   3.869 -//    }
   3.870 -//
   3.871 -//    func testRemoveSearchFilterAfter0Results() {
   3.872 -//        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   3.873 -//        setupViewModel()
   3.874 -//        emailListVM.startMonitoring()
   3.875 -//        XCTAssertEqual(emailListVM.rowCount, 10)
   3.876 -//        emailListVM.setSearch(forSearchText: "blabla@blabla.com")
   3.877 -//        XCTAssertEqual(emailListVM.rowCount, 0)
   3.878 -//        emailListVM.removeSearch()
   3.879 -//        XCTAssertEqual(emailListVM.rowCount, 10)
   3.880 -//    }
   3.881 -//
   3.882 -//    func testSetSearchFilterAddressWith3results() {
   3.883 -//        let textToSearch = "searchTest@mail.com"
   3.884 -//        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   3.885 -//        TestUtil.createMessage(inFolder: folder,
   3.886 -//                      from: Identity(address: textToSearch),
   3.887 -//                      tos: [folder.account.user],
   3.888 -//                      uid: 666).save()
   3.889 -//        TestUtil.createMessage(inFolder: folder,
   3.890 -//                      from: Identity(address: textToSearch),
   3.891 -//                      tos: [folder.account.user],
   3.892 -//                      uid: 667).save()
   3.893 -//        TestUtil.createMessage(inFolder: folder,
   3.894 -//                      from: Identity(address: textToSearch),
   3.895 -//                      tos: [folder.account.user],
   3.896 -//                      uid: 668).save()
   3.897 -//        setupViewModel()
   3.898 -//        emailListVM.startMonitoring()
   3.899 -//        XCTAssertEqual(emailListVM.rowCount, 13)
   3.900 -//        emailListVM.setSearch(forSearchText: textToSearch)
   3.901 -//        XCTAssertEqual(emailListVM.rowCount, 3)
   3.902 -//    }
   3.903 -//
   3.904 -//    func testSetSearchFilterShortMessageWith1results() {
   3.905 -//        let textToSearch = "searchTest"
   3.906 -//        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   3.907 -//        TestUtil.createMessage(inFolder: folder,
   3.908 -//                      from: Identity(address: "mail@mail.com"),
   3.909 -//                      tos: [folder.account.user],
   3.910 -//                      shortMessage: textToSearch,
   3.911 -//                      uid: 666).save()
   3.912 -//        setupViewModel()
   3.913 -//        emailListVM.startMonitoring()
   3.914 -//        XCTAssertEqual(emailListVM.rowCount, 11)
   3.915 -//        emailListVM.setSearch(forSearchText: textToSearch)
   3.916 -//        XCTAssertEqual(emailListVM.rowCount, 1)
   3.917 -//    }
   3.918 -//
   3.919 -//    func testSetSearchMultipleSitesMatchInMessagesWith2results() {
   3.920 -//        let textToSearch = "searchTest"
   3.921 -//        let longText = "bla " + textToSearch + " bla"
   3.922 -//        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   3.923 -//        TestUtil.createMessage(inFolder: folder,
   3.924 -//                      from: Identity(address: "mail@mail.com"),
   3.925 -//                      shortMessage: textToSearch,
   3.926 -//                      uid: 666).save()
   3.927 -//        TestUtil.createMessage(inFolder: folder,
   3.928 -//                      from: Identity(address: "mail@mail.com"),
   3.929 -//                      tos: [folder.account.user],
   3.930 -//                      longMessage: longText,
   3.931 -//                      uid: 667).save()
   3.932 -//        setupViewModel()
   3.933 -//        emailListVM.startMonitoring()
   3.934 -//        XCTAssertEqual(emailListVM.rowCount, 12)
   3.935 -//        emailListVM.setSearch(forSearchText: textToSearch)
   3.936 -//        XCTAssertEqual(emailListVM.rowCount, 2)
   3.937 -//    }
   3.938 -//
   3.939 -//    // Threading feature is currently non-existing. Keep this code, might help later.
   3.940 -////    //thread view nos is totaly disabled that means always false
   3.941 -////    func testCheckIfSettingsChanged() {
   3.942 -////        setupViewModel()
   3.943 -////        emailListVM.startMonitoring()
   3.944 -////        XCTAssertFalse(AppSettings.threadedViewEnabled)
   3.945 -////        AppSettings.threadedViewEnabled = true
   3.946 -////        XCTAssertFalse(emailListVM.checkIfSettingsChanged())
   3.947 -////    }
   3.948 -//
   3.949 -//    // MARK: - cell for row
   3.950 -///*
   3.951 -//    func testIndexFromMessage() {
   3.952 -//        let msgs = TestUtil.createMessages(number: 10, inFolder: folder)
   3.953 -//        setupViewModel()
   3.954 -//        emailListVM.startMonitoring()
   3.955 -//        var index = emailListVM.index(of: msgs[0])
   3.956 -//        XCTAssertEqual(index, 9)
   3.957 -//        index = emailListVM.index(of: msgs[9])
   3.958 -//        XCTAssertEqual(index, 0)
   3.959 -//    }*/
   3.960 -//
   3.961 -//    func testViewModel() {
   3.962 -//        let msg = TestUtil.createMessage(inFolder: folder, from: folder.account.user, uid: 1)
   3.963 -//        msg.save()
   3.964 -//        setupViewModel()
   3.965 -//        emailListVM.startMonitoring()
   3.966 -//        let index = emailListVM.index(of: msg)
   3.967 -//        guard let ind = index else {
   3.968 -//            XCTFail()
   3.969 -//            return
   3.970 -//        }
   3.971 -//        let vm = emailListVM.viewModel(for: ind)
   3.972 -//        XCTAssertEqual(vm?.message(), msg)
   3.973 -//        XCTAssertEqual(vm?.subject, msg.shortMessage)
   3.974 -//    }
   3.975 -//
   3.976 -////    func testSetUpFilterViewModel() {
   3.977 -////        var filterEnabled = false
   3.978 -////        setupViewModel()
   3.979 -////        XCTAssertEqual(filterEnabled, emailListVM.isFilterEnabled)
   3.980 -////        filterEnabled = true
   3.981 -////        setUpViewModelExpectations(expectedUpdateView: true)
   3.982 -////        emailListVM.isFilterEnabled = filterEnabled
   3.983 -////        waitForExpectations(timeout: TestUtil.waitTime)
   3.984 -////        XCTAssertEqual(filterEnabled, emailListVM.isFilterEnabled)
   3.985 -////    }
   3.986 -//
   3.987 -//    func testNewMessageReceivedAndDisplayedInTheCorrectPosition() {
   3.988 -//        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
   3.989 -//        setupViewModel()
   3.990 -//        emailListVM.startMonitoring()
   3.991 -//        XCTAssertEqual(emailListVM.rowCount, 10)
   3.992 -//        setUpViewModelExpectations(expectationDidInsertDataAt: true)
   3.993 -//        let msg = TestUtil.createMessage(inFolder: folder, from: folder.account.user)
   3.994 -//        msg.save()
   3.995 -//        waitForExpectations(timeout: TestUtil.waitTime)
   3.996 -//        XCTAssertEqual(emailListVM.rowCount, 11)
   3.997 -//        var index = emailListVM.index(of: msg)
   3.998 -//        XCTAssertEqual(index, 0)
   3.999 -//        let nonShownMsg = TestUtil.createMessage(inFolder: trashFolder, from: folder.account.user)
  3.1000 -//        nonShownMsg.save()
  3.1001 -//        XCTAssertEqual(emailListVM.rowCount, 11)
  3.1002 -//        index = emailListVM.index(of: msg)
  3.1003 -//        XCTAssertEqual(index, 0)
  3.1004 -//    }
  3.1005 -//
  3.1006 -//    func testNewMessageUpdateReceivedAndDisplayed() {
  3.1007 -//        let numMails = 10
  3.1008 -//        TestUtil.createMessages(number: numMails, engineProccesed: true, inFolder: folder)
  3.1009 -//        let msg = TestUtil.createMessage(inFolder: folder,
  3.1010 -//                                         from: folder.account.user,
  3.1011 -//                                         uid: numMails + 1)
  3.1012 -//        msg.imapFlags.flagged = false
  3.1013 -//        msg.save()
  3.1014 -//        XCTAssertFalse((msg.imapFlags.flagged))
  3.1015 -//        setupViewModel()
  3.1016 -//        emailListVM.startMonitoring()
  3.1017 -//        XCTAssertEqual(emailListVM.rowCount, 11)
  3.1018 -//        msg.imapFlags.flagged = true
  3.1019 -//        msg.save()
  3.1020 -//        waitForExpectations(timeout: TestUtil.waitTime)
  3.1021 -//        var index = emailListVM.index(of: msg)
  3.1022 -//        if let ind = index {
  3.1023 -//            let newMsg = emailListVM.message(representedByRowAt: IndexPath(row: ind, section: 0))
  3.1024 -//            XCTAssertTrue((newMsg?.imapFlags.flagged)!)
  3.1025 -//        } else {
  3.1026 -//            XCTFail()
  3.1027 -//        }
  3.1028 -//
  3.1029 -//        let nonShownMsg = TestUtil.createMessage(inFolder: trashFolder, from: folder.account.user)
  3.1030 -//        nonShownMsg.save()
  3.1031 -//        XCTAssertEqual(emailListVM.rowCount, 11)
  3.1032 -//        index = emailListVM.index(of: nonShownMsg)
  3.1033 -//        XCTAssertNil(index)
  3.1034 -//    }
  3.1035 -//
  3.1036 -//    func testNewMessageDeleteReceivedAndDisplayed() {
  3.1037 -//        let numMails = 10
  3.1038 -//        TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
  3.1039 -//        let msg = TestUtil.createMessage(inFolder: folder,
  3.1040 -//                                         from: folder.account.user,
  3.1041 -//                                         uid: numMails + 1)
  3.1042 -//        msg.imapFlags.flagged = false
  3.1043 -//        msg.save()
  3.1044 -//        XCTAssertFalse((msg.imapFlags.flagged))
  3.1045 -//        setupViewModel()
  3.1046 -//        emailListVM.startMonitoring()
  3.1047 -//        XCTAssertEqual(emailListVM.rowCount, 11)
  3.1048 -//        setUpViewModelExpectations(expectationDidDeleteDataAt: true)
  3.1049 -//        msg.delete()
  3.1050 -//        waitForExpectations(timeout: TestUtil.waitTime)
  3.1051 -//        var index = emailListVM.index(of: msg)
  3.1052 -//        XCTAssertNil(index)
  3.1053 -//        XCTAssertEqual(emailListVM.rowCount, 10)
  3.1054 -//
  3.1055 -//        let nonShownMsg = TestUtil.createMessage(inFolder: trashFolder, from: folder.account.user)
  3.1056 -//        nonShownMsg.save()
  3.1057 -//        nonShownMsg.delete()
  3.1058 -//        XCTAssertEqual(emailListVM.rowCount, 10)
  3.1059 -//        index = emailListVM.index(of: nonShownMsg)
  3.1060 -//        XCTAssertNil(index)
  3.1061 -//    }
  3.1062 -//
  3.1063 -//    func testgetMoveToFolderViewModel() {
  3.1064 -//        TestUtil.createMessages(number: 4, inFolder: folder)
  3.1065 -//        let index: [IndexPath] = [IndexPath(row: 0, section: 1),
  3.1066 -//                                  IndexPath(row: 0, section: 2)]
  3.1067 -//        setupViewModel()
  3.1068 -//        emailListVM.startMonitoring()
  3.1069 -//
  3.1070 -//        let accountvm = emailListVM.getMoveToFolderViewModel(forSelectedMessages: index)
  3.1071 -//
  3.1072 -//        let postMessages = accountvm!.items[0].messages
  3.1073 -//        XCTAssertEqual(index.count, postMessages.count)
  3.1074 -//    }
  3.1075 -//
  3.1076 -//    func testFlagUnflagMessageIsImmediate() {
  3.1077 -//        let message = givenThereIsAMessageIn(folderType: .inbox)
  3.1078 -//        let messageMoc = message?.cdMessage()?.managedObjectContext
  3.1079 -//        setupViewModel()
  3.1080 -//        emailListVM.startMonitoring()
  3.1081 -//
  3.1082 -//        let indexPath = IndexPath(row: 0, section: 0)
  3.1083 -//
  3.1084 -//        emailListVM.setFlagged(forIndexPath: indexPath)
  3.1085 -//        guard let isFlagged = emailListVM.viewModel(for: indexPath.row)?.isFlagged else {
  3.1086 -//            XCTFail()
  3.1087 -//            return
  3.1088 -//        }
  3.1089 -//
  3.1090 -//        emailListVM.unsetFlagged(forIndexPath: indexPath)
  3.1091 -//        guard let isNotFlagged = emailListVM.viewModel(for: indexPath.row)?.isFlagged else {
  3.1092 -//            XCTFail()
  3.1093 -//            return
  3.1094 -//        }
  3.1095 -//        let messageDidSaveExpectation = expectation(description: "message is saved")
  3.1096 -//        messageDidSaveExpectation.expectedFulfillmentCount = 8
  3.1097 -//
  3.1098 -//        NotificationCenter.default
  3.1099 -//            .addObserver(forName: Notification.Name.NSManagedObjectContextDidSave,
  3.1100 -//                         object: messageMoc,
  3.1101 -//                         queue: nil) { (notification) in
  3.1102 -//                            print("fulfill")
  3.1103 -//                            messageDidSaveExpectation.fulfill()
  3.1104 -//        }
  3.1105 -//
  3.1106 -//        let isImmediate = isFlagged != isNotFlagged
  3.1107 -//        XCTAssertTrue(isImmediate)
  3.1108 -//        wait(for: [messageDidSaveExpectation], timeout: UnitTestUtils.waitTime)
  3.1109 -//    }
  3.1110 -//
  3.1111 -//    // Mark: - setting up
  3.1112 -//
  3.1113 -//    fileprivate func setUpViewModel(masterViewController: TestMasterViewController) {
  3.1114 -//        self.emailListVM = EmailListViewModel(emailListViewModelDelegate: masterViewController, folderToShow: self.folder)
  3.1115 -//    }
  3.1116 -//
  3.1117 -//    fileprivate func setupViewModel() {
  3.1118 -//        createViewModelWithExpectations(expectedUpdateView: true)
  3.1119 -//    }
  3.1120 -//
  3.1121 -//    /*fileprivate func setSearchFilter(text: String) {
  3.1122 -//        setNewUpdateViewExpectation()
  3.1123 -//        emailListVM.setSearchFilter(forSearchText: text)
  3.1124 -//        waitForExpectations(timeout: TestUtil.waitTime)
  3.1125 -//    }
  3.1126 -//
  3.1127 -//    fileprivate func removeSearchFilter() {
  3.1128 -//        setNewUpdateViewExpectation()
  3.1129 -//        emailListVM.removeSearchFilter()
  3.1130 -//        waitForExpectations(timeout: TestUtil.waitTime)
  3.1131 -//    }*/
  3.1132 -//
  3.1133 -//    fileprivate func setNewUpdateViewExpectation() {
  3.1134 -//        let updateViewExpectation = expectation(description: "UpdateViewCalled")
  3.1135 -//        masterViewController.expectationUpdateViewCalled = updateViewExpectation
  3.1136 -//    }
  3.1137 -//
  3.1138 -//    fileprivate func createViewModelWithExpectations(expectedUpdateView: Bool) {
  3.1139 -//        let viewModelTestDelegate = TestMasterViewController()
  3.1140 -//        setUpViewModel(masterViewController: viewModelTestDelegate)
  3.1141 -//    }
  3.1142 -//
  3.1143 -//    fileprivate func setUpViewModelExpectations(expectedUpdateView: Bool = false,
  3.1144 -//                                                expectationDidInsertDataAt: Bool = false,
  3.1145 -//                                                expectationDidUpdateDataAt: Bool = false,
  3.1146 -//                                                expectationDidDeleteDataAt: Bool = false ) {
  3.1147 -//        var expectationUpdateViewCalled: XCTestExpectation?
  3.1148 -//        if expectedUpdateView {
  3.1149 -//            expectationUpdateViewCalled = expectation(description: "UpdateViewCalled")
  3.1150 -//        }
  3.1151 -//
  3.1152 -//        var excpectationDidInsertDataAtCalled: XCTestExpectation?
  3.1153 -//        if expectationDidInsertDataAt {
  3.1154 -//            excpectationDidInsertDataAtCalled =
  3.1155 -//                expectation(description: "excpectationDidInsertDataAtCalled")
  3.1156 -//        }
  3.1157 -//
  3.1158 -//        var excpectationDidUpdateDataAtCalled: XCTestExpectation?
  3.1159 -//        if expectationDidUpdateDataAt {
  3.1160 -//            excpectationDidUpdateDataAtCalled =
  3.1161 -//                expectation(description: "excpectationDidUpdateDataAtCalled")
  3.1162 -//        }
  3.1163 -//
  3.1164 -//        var excpectationDidDeleteDataAtCalled: XCTestExpectation?
  3.1165 -//        if expectationDidDeleteDataAt {
  3.1166 -//            excpectationDidDeleteDataAtCalled =
  3.1167 -//                expectation(description: "excpectationDidInsertDataAtCalled")
  3.1168 -//        }
  3.1169 -//
  3.1170 -//        emailListVM.emailListViewModelDelegate = TestMasterViewController(
  3.1171 -//            expectationUpdateView: expectationUpdateViewCalled,
  3.1172 -//            expectationDidInsertDataAt: excpectationDidInsertDataAtCalled,
  3.1173 -//            expectationDidUpdateDataAt: excpectationDidUpdateDataAtCalled,
  3.1174 -//            expectationDidRemoveDataAt: excpectationDidDeleteDataAtCalled)
  3.1175 -//    }
  3.1176 -//
  3.1177 -//    fileprivate func getSafeLastLookAt() -> Date {
  3.1178 -//        guard let safeLastLookedAt = folder?.lastLookedAt as Date? else {
  3.1179 -//            XCTFail()
  3.1180 -//            return Date()
  3.1181 -//        }
  3.1182 -//        return safeLastLookedAt
  3.1183 -//    }
  3.1184 -//
  3.1185 -//    private func givenThereIsA(folderType: FolderType) {
  3.1186 -//        folder = Folder(name: "-", parent: folder, account: account, folderType: folderType)
  3.1187 -//        folder.save()
  3.1188 -//    }
  3.1189 -//
  3.1190 -//    @discardableResult private func givenThereIsAMessageIn(folderType: FolderType) -> Message? {
  3.1191 -//        givenThereIsA(folderType: folderType)
  3.1192 -//        return TestUtil.createMessages(number: 1, engineProccesed: true, inFolder: folder).first
  3.1193 +//    func insertMessagesWithoutDelegate(messages: [Message]) {
  3.1194 +//        results.append(contentsOf: messages)
  3.1195  //    }
  3.1196  //}
  3.1197 -//
  3.1198 -//class TestMasterViewController: EmailListViewModelDelegate {
  3.1199 -//
  3.1200 -//    var expectationUpdateViewCalled: XCTestExpectation?
  3.1201 -//    var excpectationDidInsertDataAtCalled: XCTestExpectation?
  3.1202 -//    var expectationDidUpdateDataAtCalled: XCTestExpectation?
  3.1203 -//    var expectationDidRemoveDataAtCalled: XCTestExpectation?
  3.1204 -//    var expetationDidChangeSeenStateForDataAt: XCTestExpectation?
  3.1205 -//
  3.1206 -//    init(expectationUpdateView: XCTestExpectation? = nil,
  3.1207 -//         expectationDidInsertDataAt: XCTestExpectation? = nil,
  3.1208 -//         expectationDidUpdateDataAt: XCTestExpectation? = nil,
  3.1209 -//         expectationDidRemoveDataAt: XCTestExpectation? = nil) {
  3.1210 -//        self.expectationUpdateViewCalled = expectationUpdateView
  3.1211 -//        self.excpectationDidInsertDataAtCalled = expectationDidInsertDataAt
  3.1212 -//        self.expectationDidUpdateDataAtCalled = expectationDidUpdateDataAt
  3.1213 -//        self.expectationDidRemoveDataAtCalled = expectationDidRemoveDataAt
  3.1214 -//    }
  3.1215 -//
  3.1216 -//    func willReceiveUpdates(viewModel: EmailListViewModel) {
  3.1217 -//        //not yet defined
  3.1218 -//    }
  3.1219 -//
  3.1220 -//    func allUpdatesReceived(viewModel: EmailListViewModel) {
  3.1221 -//        //not yet defined
  3.1222 -//    }
  3.1223 -//
  3.1224 -//    func reloadData(viewModel: EmailListViewModel) {
  3.1225 -//        //not yet defined
  3.1226 -//    }
  3.1227 -//
  3.1228 -//
  3.1229 -//    func emailListViewModel(viewModel: EmailListViewModel,
  3.1230 -//                            didInsertDataAt indexPaths: [IndexPath]) {
  3.1231 -//        if let excpectationDidInsertDataAtCalled = excpectationDidInsertDataAtCalled {
  3.1232 -//            excpectationDidInsertDataAtCalled.fulfill()
  3.1233 -//        } else {
  3.1234 -//            XCTFail()
  3.1235 -//        }
  3.1236 -//    }
  3.1237 -//
  3.1238 -//    func emailListViewModel(viewModel: EmailListViewModel,
  3.1239 -//                            didUpdateDataAt indexPaths: [IndexPath]) {
  3.1240 -//        if let expectationDidUpdateDataAtCalled = expectationDidUpdateDataAtCalled {
  3.1241 -//            expectationDidUpdateDataAtCalled.fulfill()
  3.1242 -//        } else {
  3.1243 -//            //XCTFail()
  3.1244 -//        }
  3.1245 -//    }
  3.1246 -//
  3.1247 -//    func emailListViewModel(viewModel: EmailListViewModel,
  3.1248 -//                            didChangeSeenStateForDataAt indexPaths: [IndexPath]) {
  3.1249 -//        XCTFail("Currently unused in tests. Should not be called")
  3.1250 -//    }
  3.1251 -//
  3.1252 -//    func emailListViewModel(viewModel: EmailListViewModel,
  3.1253 -//                            didRemoveDataAt indexPaths: [IndexPath]) {
  3.1254 -//        if let expectationDidRemoveDataAtCalled = expectationDidRemoveDataAtCalled {
  3.1255 -//            expectationDidRemoveDataAtCalled.fulfill()
  3.1256 -//        } else {
  3.1257 -//            //XCTFail()
  3.1258 -//        }
  3.1259 -//    }
  3.1260 -//
  3.1261 -//    func emailListViewModel(viewModel: EmailListViewModel,
  3.1262 -//                            didMoveData atIndexPath: IndexPath,
  3.1263 -//                            toIndexPath: IndexPath) {
  3.1264 -//        XCTFail()
  3.1265 -//    }
  3.1266 -//
  3.1267 -//    func emailListViewModel(viewModel: EmailListViewModel,
  3.1268 -//                            didUpdateUndisplayedMessage message: Message) {
  3.1269 -//        XCTFail()
  3.1270 -//    }
  3.1271 -//
  3.1272 -//    func toolbarIs(enabled: Bool) {
  3.1273 -//        XCTFail()
  3.1274 -//    }
  3.1275 -//
  3.1276 -//    func showUnflagButton(enabled: Bool) {
  3.1277 -//        XCTFail()
  3.1278 -//    }
  3.1279 -//
  3.1280 -//    func showUnreadButton(enabled: Bool) {
  3.1281 -//        XCTFail()
  3.1282 -//    }
  3.1283 -//
  3.1284 -//    func updateView() {
  3.1285 -//        if let expectationUpdateViewCalled = expectationUpdateViewCalled {
  3.1286 -//            expectationUpdateViewCalled.fulfill()
  3.1287 -//        } else {
  3.1288 -//            XCTFail()
  3.1289 -//        }
  3.1290 -//    }
  3.1291 -//}
  3.1292 -//
  3.1293 -////class TestServer: MessageQueryResults {
  3.1294 -////    var results: [Message] = [Message]()
  3.1295 -////
  3.1296 -////    required init(withFolder folder: Folder) {
  3.1297 -////        super.init(withDisplayableFolder: folder)
  3.1298 -////    }
  3.1299 -////
  3.1300 -////
  3.1301 -////    override var count: Int {
  3.1302 -////        return results.count
  3.1303 -////    }
  3.1304 -////
  3.1305 -////    override subscript(index: Int) -> Message {
  3.1306 -////        return results[index]
  3.1307 -////    }
  3.1308 -////
  3.1309 -////    override func startMonitoring() throws {
  3.1310 -////
  3.1311 -////    }
  3.1312 -////
  3.1313 -////    func insertData(message: Message) {
  3.1314 -////        results.append(message)
  3.1315 -////        let ip = IndexPath(row: results.firstIndex(of: message)!, section: 0)
  3.1316 -////        delegate?.didInsert(indexPath: ip)
  3.1317 -////    }
  3.1318 -////
  3.1319 -////    func updateData(message: Message) {
  3.1320 -////        let ip = IndexPath(row: results.firstIndex(of: message)!, section: 0)
  3.1321 -////        delegate?.didUpdate(indexPath: ip)
  3.1322 -////    }
  3.1323 -////
  3.1324 -////    func deleteData(message: Message) {
  3.1325 -////        let index = results.firstIndex(of: message)
  3.1326 -////        results.remove(at: index!)
  3.1327 -////        let ip = IndexPath(row: index!, section: 0)
  3.1328 -////        delegate?.didDelete(indexPath: ip)
  3.1329 -////    }
  3.1330 -////
  3.1331 -////    func insertMessagesWithoutDelegate(messages: [Message]) {
  3.1332 -////        results.append(contentsOf: messages)
  3.1333 -////    }
  3.1334 -////}
  3.1335 -//
  3.1336 -//class TestDetailsViewController {
  3.1337 -//    var emailDisplayDelegate : EmailDisplayDelegate
  3.1338 -//    init(emailDisplayDelegate: EmailDisplayDelegate) {
  3.1339 -//        self.emailDisplayDelegate = emailDisplayDelegate
  3.1340 -//    }
  3.1341 -//
  3.1342 -//    func emailDisplayDidChangeMarkSeen(message: Message) {
  3.1343 -//        self.emailDisplayDelegate.emailDisplayDidChangeMarkSeen(message: message)
  3.1344 -//    }
  3.1345 -//
  3.1346 -//    func emailDisplayDidDelete(message: Message) {
  3.1347 -//        self.emailDisplayDelegate.emailDisplayDidDelete(message: message)
  3.1348 -//    }
  3.1349 -//
  3.1350 -//    func emailDisplayDidFlag(message: Message) {
  3.1351 -//        self.emailDisplayDelegate.emailDisplayDidFlag(message: message)
  3.1352 -//    }
  3.1353 -//
  3.1354 -//    func emailDisplayDidUnflag(message: Message) {
  3.1355 -//        self.emailDisplayDelegate.emailDisplayDidUnflag(message: message)
  3.1356 -//    }
  3.1357 -//}
  3.1358 +
  3.1359 +class TestDetailsViewController {
  3.1360 +    var emailDisplayDelegate : EmailDisplayDelegate
  3.1361 +    init(emailDisplayDelegate: EmailDisplayDelegate) {
  3.1362 +        self.emailDisplayDelegate = emailDisplayDelegate
  3.1363 +    }
  3.1364 +
  3.1365 +    func emailDisplayDidChangeMarkSeen(message: Message) {
  3.1366 +        self.emailDisplayDelegate.emailDisplayDidChangeMarkSeen(message: message)
  3.1367 +    }
  3.1368 +
  3.1369 +    func emailDisplayDidDelete(message: Message) {
  3.1370 +        self.emailDisplayDelegate.emailDisplayDidDelete(message: message)
  3.1371 +    }
  3.1372 +
  3.1373 +    func emailDisplayDidFlag(message: Message) {
  3.1374 +        self.emailDisplayDelegate.emailDisplayDidFlag(message: message)
  3.1375 +    }
  3.1376 +
  3.1377 +    func emailDisplayDidUnflag(message: Message) {
  3.1378 +        self.emailDisplayDelegate.emailDisplayDidUnflag(message: message)
  3.1379 +    }
  3.1380 +}