IOS-1495 server is MessageQueryResult is server now IOS-1495
authorXavier Algarra <xavier@pep-project.org>
Fri, 15 Mar 2019 19:04:39 +0100
branchIOS-1495
changeset 80123b0fadafee82
parent 8011 da69019044e1
child 8013 b4b7750a4648
IOS-1495 server is MessageQueryResult is server now
pEpForiOSTests/Models/EmailListViewModelTest.swift
     1.1 --- a/pEpForiOSTests/Models/EmailListViewModelTest.swift	Fri Mar 15 18:52:24 2019 +0100
     1.2 +++ b/pEpForiOSTests/Models/EmailListViewModelTest.swift	Fri Mar 15 19:04:39 2019 +0100
     1.3 @@ -17,7 +17,7 @@
     1.4      var emailListVM : EmailListViewModel!
     1.5      var server: TestServer!
     1.6      var masterViewController: TestMasterViewController!
     1.7 -    var messageQueryResults: MessageQueryResults!
     1.8 +    //var messageQueryResults: MessageQueryResults!
     1.9  
    1.10      /** this set up a view model with one account and one folder saved **/
    1.11      override func setUp() {
    1.12 @@ -32,8 +32,8 @@
    1.13                               account: folder.account,
    1.14                               folderType: .trash)
    1.15          trashFolder.save()
    1.16 -        messageQueryResults = MessageQueryResults(withFolder: folder)
    1.17 -        test
    1.18 +        //messageQueryResults = MessageQueryResults(withFolder: folder)
    1.19 +        server = TestServer(withFolder: folder)
    1.20      }
    1.21  
    1.22      // MARK: - Test section
    1.23 @@ -337,7 +337,7 @@
    1.24          TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder)
    1.25          setupViewModel()
    1.26          XCTAssertEqual(emailListVM.rowCount, 10)
    1.27 -        setUpMessageFolderDelegate()
    1.28 +        //setUpMessageFolderDelegate()
    1.29          setUpViewModelExpectations(expectationDidInsertDataAt: true)
    1.30          let msg = TestUtil.createMessage(inFolder: folder, from: folder.account.user)
    1.31          msg.save()
    1.32 @@ -365,7 +365,7 @@
    1.33          XCTAssertFalse((msg.imapFlags?.flagged)!)
    1.34          setupViewModel()
    1.35          XCTAssertEqual(emailListVM.rowCount, 11)
    1.36 -        setUpMessageFolderDelegate()
    1.37 +        //setUpMessageFolderDelegate()
    1.38          setUpViewModelExpectations(expectationDidUpdateDataAt: true)
    1.39          msg.imapFlags?.flagged = true
    1.40          msg.save()
    1.41 @@ -398,7 +398,7 @@
    1.42          XCTAssertFalse((msg.imapFlags?.flagged)!)
    1.43          setupViewModel()
    1.44          XCTAssertEqual(emailListVM.rowCount, 11)
    1.45 -        setUpMessageFolderDelegate()
    1.46 +        //setUpMessageFolderDelegate()
    1.47          setUpViewModelExpectations(expectationDidDeleteDataAt: true)
    1.48          msg.delete()
    1.49          server.deleteData(message: msg)
    1.50 @@ -468,18 +468,12 @@
    1.51          let msgsyncservice = MessageSyncService()
    1.52          self.emailListVM = EmailListViewModel(emailListViewModelDelegate: masterViewController,
    1.53                                                messageSyncService: msgsyncservice,
    1.54 -                                              folderToShow: folder, messageQueryResults: messageQueryResults)
    1.55 -
    1.56 -    }
    1.57 -
    1.58 -    fileprivate func setServer() {
    1.59 -        self.server = TestServer(messageQueryResults: messageQueryResults)
    1.60 +                                              folderToShow: folder, messageQueryResults: server)
    1.61  
    1.62      }
    1.63  
    1.64      fileprivate func setupViewModel() {
    1.65          createViewModelWithExpectations(expectedUpdateView: true)
    1.66 -        setServer()
    1.67      }
    1.68  
    1.69      fileprivate func setSearchFilter(text: String) {
    1.70 @@ -660,28 +654,42 @@
    1.71      }
    1.72  }
    1.73  
    1.74 -class TestServer {
    1.75 -    var messageQueryResults : MessageQueryResults
    1.76 +class TestServer: MessageQueryResults {
    1.77      var results: [Message] = [Message]()
    1.78 -    init(messageQueryResults: MessageQueryResults) {
    1.79 -        self.messageQueryResults = messageQueryResults
    1.80 +
    1.81 +    required init(withFolder folder: Folder) {
    1.82 +        super.init(withFolder: folder)
    1.83      }
    1.84 +
    1.85 +
    1.86 +    override var count: Int {
    1.87 +        return results.count
    1.88 +    }
    1.89 +
    1.90 +    override subscript(index: Int) -> Message {
    1.91 +        return results[index]
    1.92 +    }
    1.93 +
    1.94 +    override func startMonitoring() throws {
    1.95 +
    1.96 +    }
    1.97 +
    1.98      func insertData(message: Message) {
    1.99          results.append(message)
   1.100          let ip = IndexPath(row: results.firstIndex(of: message)!, section: 0)
   1.101 -        self.messageQueryResults.delegate?.didInsert(indexPath: ip)
   1.102 +        delegate?.didInsert(indexPath: ip)
   1.103      }
   1.104  
   1.105      func updateData(message: Message) {
   1.106          let ip = IndexPath(row: results.firstIndex(of: message)!, section: 0)
   1.107 -        self.messageQueryResults.delegate?.didUpdate(indexPath: ip)
   1.108 +        delegate?.didUpdate(indexPath: ip)
   1.109      }
   1.110  
   1.111      func deleteData(message: Message) {
   1.112          let index = results.firstIndex(of: message)
   1.113          results.remove(at: index!)
   1.114          let ip = IndexPath(row: index!, section: 0)
   1.115 -        self.messageQueryResults.delegate?.didDelete(indexPath: ip)
   1.116 +        delegate?.didDelete(indexPath: ip)
   1.117      }
   1.118  
   1.119      func insertMessagesWithoutDelegate(messages: [Message]) {