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