merge IOS-1495 IOS-1521
authorbuff <andreas@pep-project.org>
Tue, 07 May 2019 10:12:49 +0200
branchIOS-1521
changeset 85061f8bb1396d0c
parent 8500 c77fc727932f
parent 8502 ed1d581f863e
child 8507 0f779065eb5d
merge IOS-1495
pEpForiOSTests/Models/EmailListViewModelTest.swift
     1.1 --- a/pEpForiOSTests/Models/EmailListViewModelTest.swift	Mon May 06 18:30:55 2019 +0200
     1.2 +++ b/pEpForiOSTests/Models/EmailListViewModelTest.swift	Tue May 07 10:12:49 2019 +0200
     1.3 @@ -1,42 +1,167 @@
     1.4  //!!!: is WIP (IOS-1495), ignore failing tests for now.
     1.5  
     1.6 -////
     1.7 -////  EmailListViewModelTest.swift
     1.8 -////  pEpForiOSTests
     1.9 -////
    1.10 -////  Created by Xavier Algarra on 22/08/2018.
    1.11 -////  Copyright © 2018 p≡p Security S.A. All rights reserved.
    1.12 -////
    1.13  //
    1.14 +//  EmailListViewModelTest.swift
    1.15 +//  pEpForiOSTests
    1.16  //
    1.17 -//import XCTest
    1.18 -//@testable import pEpForiOS
    1.19 -//@testable import MessageModel
    1.20 -//
    1.21 -//class EmailListViewModelTest: CoreDataDrivenTestBase {
    1.22 -//    var folder: Folder!
    1.23 -//    var trashFolder: Folder!
    1.24 -//    var emailListVM : EmailListViewModel!
    1.25 -//    var masterViewController: TestMasterViewController!
    1.26 -//
    1.27 -//    /** this set up a view model with one account and one folder saved **/
    1.28 -//    override func setUp() {
    1.29 -//        super.setUp()
    1.30 -//
    1.31 -//        let acc = cdAccount.account()
    1.32 -//
    1.33 -//        folder = Folder(name: "inbox", parent: nil, account: acc, folderType: .inbox)
    1.34 -//        folder.save()
    1.35 -//        trashFolder = Folder(name: "trash",
    1.36 -//                             parent: nil,
    1.37 -//                             account: folder.account,
    1.38 -//                             folderType: .trash)
    1.39 -//        trashFolder.save()
    1.40 -//    }
    1.41 -//
    1.42 -//    // MARK: - Test section
    1.43 -//
    1.44 -//    func testViewModelSetUp() {
    1.45 +//  Created by Xavier Algarra on 22/08/2018.
    1.46 +//  Copyright © 2018 p≡p Security S.A. All rights reserved.
    1.47 +
    1.48 +import XCTest
    1.49 +@testable import pEpForiOS
    1.50 +@testable import MessageModel
    1.51 +
    1.52 +class EmailListViewModelTest: CoreDataDrivenTestBase {
    1.53 +    var folder: Folder!
    1.54 +    var trashFolder: Folder!
    1.55 +    var emailListVM : EmailListViewModel!
    1.56 +    var masterViewController: TestMasterViewController!
    1.57 +
    1.58 +    /** this set up a view model with one account and one folder saved **/
    1.59 +    override func setUp() {
    1.60 +        super.setUp()
    1.61 +
    1.62 +        let acc = cdAccount.account()
    1.63 +
    1.64 +        folder = Folder(name: "inbox", parent: nil, account: acc, folderType: .inbox)
    1.65 +        folder.save()
    1.66 +        trashFolder = Folder(name: "trash",
    1.67 +                             parent: nil,
    1.68 +                             account: folder.account,
    1.69 +                             folderType: .trash)
    1.70 +        trashFolder.save()
    1.71 +    }
    1.72 +
    1.73 +    // MARK: - Test section
    1.74 +
    1.75 +    func testViewModelSetUp() {
    1.76 +        setupViewModel()
    1.77 +        emailListVM.startMonitoring()
    1.78 +    }
    1.79 +
    1.80 +    func testCleanInitialSetup() {
    1.81 +        setupViewModel()
    1.82 +        emailListVM.startMonitoring()
    1.83 +        XCTAssertEqual(emailListVM.rowCount, 0)
    1.84 +    }
    1.85 +
    1.86 +    func test10MessagesInInitialSetup() {
    1.87 +         TestUtil.createMessages(number: 10, engineProccesed: true, inFolder: folder, setUids: true)
    1.88 +        setupViewModel()
    1.89 +        emailListVM.startMonitoring()
    1.90 +        XCTAssertEqual(emailListVM.rowCount, 10)
    1.91 +    }
    1.92 +
    1.93 +    func testGetFolderName() {
    1.94 +        setupViewModel()
    1.95 +        XCTAssertEqual(Folder.localizedName(realName: self.folder.realName), emailListVM.folderName)
    1.96 +    }
    1.97 +
    1.98 +    func testGetDestructiveAction() {
    1.99 +        TestUtil.createMessages(number: 1, engineProccesed: true, inFolder: folder)
   1.100 +        setupViewModel()
   1.101 +        emailListVM.startMonitoring()
   1.102 +        let destructiveAction = emailListVM.getDestructiveActtion(forMessageAt: 0)
   1.103 +
   1.104 +        XCTAssertEqual(destructiveAction, .trash)
   1.105 +    }
   1.106 +
   1.107 +    func testGetDestructiveActionInOutgoingFolderIsTrash() {
   1.108 +        _ = givenThereIsAMessageIn(folderType: .outbox)
   1.109 +        setupViewModel()
   1.110 +        emailListVM.startMonitoring()
   1.111 +        let destructiveAction = emailListVM.getDestructiveActtion(forMessageAt: 0)
   1.112 +
   1.113 +        XCTAssertEqual(destructiveAction, .trash)
   1.114 +    }
   1.115 +
   1.116 +    func testShouldShowToolbarEditButtonsIfItsNotOutboxFolder() {
   1.117 +        setupViewModel()
   1.118 +        emailListVM.startMonitoring()
   1.119 +        var showToolbarButtons = emailListVM.shouldShowToolbarEditButtons()
   1.120 +        XCTAssertTrue(showToolbarButtons)
   1.121 +
   1.122 +        givenThereIsA(folderType: .outbox)
   1.123 +        setupViewModel()
   1.124 +        emailListVM.startMonitoring()
   1.125 +        showToolbarButtons = emailListVM.shouldShowToolbarEditButtons()
   1.126 +        XCTAssertFalse(showToolbarButtons)
   1.127 +    }
   1.128 +
   1.129 +    /*func testUnreadFilterActive() {
   1.130 +        setupViewModel()
   1.131 +
   1.132 +        var unreadActive = emailListVM.unreadFilterEnabled()
   1.133 +
   1.134 +        XCTAssertFalse(unreadActive)
   1.135 +
   1.136 +        setupViewModel()
   1.137 +        emailListVM.startMonitoring()
   1.138 +
   1.139 +        let filter = CompositeFilter<FilterBase>()
   1.140 +        filter.add(filter: UnreadFilter())
   1.141 +        emailListVM.filterChanged(newFilter: filter)
   1.142 +        setUpViewModelExpectations(expectedUpdateView: true)
   1.143 +        emailListVM.isFilterEnabled = true
   1.144 +
   1.145 +        waitForExpectations(timeout: TestUtil.waitTime)
   1.146 +        unreadActive = emailListVM.unreadFilterEnabled()
   1.147 +
   1.148 +        XCTAssertTrue(unreadActive)
   1.149 +
   1.150 +    }*/
   1.151 +
   1.152 +    func testGetFlagAndMoreAction() {
   1.153 +        let messages = TestUtil.createMessages(number: 1, engineProccesed: true, inFolder: folder)
   1.154 +        setupViewModel()
   1.155 +        emailListVM.startMonitoring()
   1.156 +        var flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   1.157 +        let moreAction = emailListVM.getMoreAction(forMessageAt: 0)
   1.158 +
   1.159 +        XCTAssertEqual(flagAction, .flag)
   1.160 +        XCTAssertEqual(moreAction, .more)
   1.161 +
   1.162 +        messages[0].imapFlags?.flagged = true
   1.163 +        messages[0].save()
   1.164 +
   1.165 +        flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   1.166 +
   1.167 +        XCTAssertEqual(flagAction, .unflag)
   1.168 +    }
   1.169 +
   1.170 +    func testGetFlagAndMoreActionInOutgoingFolderIsNil() {
   1.171 +        givenThereIsAMessageIn(folderType: .outbox)
   1.172 +        setupViewModel()
   1.173 +        emailListVM.startMonitoring()
   1.174 +
   1.175 +        let flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   1.176 +        let moreAction = emailListVM.getMoreAction(forMessageAt: 0)
   1.177 +
   1.178 +        XCTAssertEqual(flagAction, nil)
   1.179 +        XCTAssertEqual(moreAction, nil)
   1.180 +    }
   1.181 +
   1.182 +    func testGetFlagAndMoreActionInDraftFolderIsNil() {
   1.183 +        givenThereIsAMessageIn(folderType: .drafts)
   1.184 +        setupViewModel()
   1.185 +        emailListVM.startMonitoring()
   1.186 +        let flagAction = emailListVM.getFlagAction(forMessageAt: 0)
   1.187 +        let moreAction = emailListVM.getMoreAction(forMessageAt: 0)
   1.188 +
   1.189 +        XCTAssertEqual(flagAction, nil)
   1.190 +        XCTAssertEqual(moreAction, nil)
   1.191 +    }
   1.192 +
   1.193 +    func testAccountExists() {
   1.194 +        setupViewModel()
   1.195 +        emailListVM.startMonitoring()
   1.196 +        var noAccounts = emailListVM.showLoginView
   1.197 +
   1.198 +        XCTAssertFalse(noAccounts)
   1.199 +
   1.200 +        cdAccount.delete()
   1.201 +        setupViewModel()
   1.202 +        //emailListVM.startMonitoring()
   1.203  //        setupViewModel()
   1.204  //        emailListVM.startMonitoring()
   1.205  //    }