IOS-663 more test IOS-663
authorbuff <andreas@pep-project.org>
Wed, 16 May 2018 14:53:29 +0200
branchIOS-663
changeset 4705fd8a8e83eae6
parent 4704 90b74243135a
child 4706 df31d9ce78ad
IOS-663 more test
pEpForiOSTests/Background/MoveToFolderOperationTest.swift
     1.1 --- a/pEpForiOSTests/Background/MoveToFolderOperationTest.swift	Wed May 16 13:10:24 2018 +0200
     1.2 +++ b/pEpForiOSTests/Background/MoveToFolderOperationTest.swift	Wed May 16 14:53:29 2018 +0200
     1.3 @@ -40,10 +40,59 @@
     1.4  
     1.5          // Assure deleted messages are in trash
     1.6          checkExistance(ofMessages: receivedMsgs, inFolderOfType: .trash, mustExist: true)
     1.7 -
     1.8      }
     1.9  
    1.10 +    func testMoveInboxToSpam() {
    1.11 +        assureMoveFromInbox(toFolderOfType: .spam)
    1.12 +    }
    1.13 +
    1.14 +    func testMoveInboxToTrash() {
    1.15 +        assureMoveFromInbox(toFolderOfType: .trash)
    1.16 +    }
    1.17 +
    1.18 +    func testMoveInboxToArchive() {
    1.19 +        assureMoveFromInbox(toFolderOfType: .archive)
    1.20 +    }
    1.21 +    
    1.22      // MARK: - HELPER
    1.23 +
    1.24 +    private func assureMoveFromInbox(toFolderOfType targetFolderType: FolderType) {
    1.25 +        // Setup 2 accounts
    1.26 +        // the testee
    1.27 +        cdAccount.createRequiredFoldersAndWait(testCase: self)
    1.28 +        Record.saveAndWait()
    1.29 +        // the sender
    1.30 +        let cdAccount2 = SecretTestData().createWorkingCdAccount(number: 1)
    1.31 +        TestUtil.skipValidation()
    1.32 +        Record.saveAndWait()
    1.33 +        cdAccount2.createRequiredFoldersAndWait(testCase: self)
    1.34 +        Record.saveAndWait()
    1.35 +
    1.36 +        // Send (and receive) messages from 2nd account to 1st account
    1.37 +        let receivedMsgs = sendAndReceive(numMails: 1, fromAccount: cdAccount2)
    1.38 +
    1.39 +        // Move messages to target folder
    1.40 +        move(messages: receivedMsgs, toFolerOfType: targetFolderType)
    1.41 +
    1.42 +        // Sync
    1.43 +        TestUtil.syncAndWait(numAccountsToSync: 2, testCase: self, skipValidation: true)
    1.44 +
    1.45 +        // Assure messages are in target folder
    1.46 +        checkExistance(ofMessages: receivedMsgs, inFolderOfType: targetFolderType, mustExist: true)
    1.47 +    }
    1.48 +
    1.49 +    private func move(messages:[Message], toFolerOfType type: FolderType) {
    1.50 +        for msg:Message in messages {
    1.51 +            guard let targetFolder = msg.parent.account.folder(ofType: type) else {
    1.52 +                XCTFail()
    1.53 +                return
    1.54 +            }
    1.55 +            // For some reason the swift compiler sees this as ambigous
    1.56 +//            msg.move(to: targetFolder)
    1.57 +            msg.targetFolder = targetFolder
    1.58 +        }
    1.59 +    }
    1.60 +
    1.61      private func messagesAreEqual(msg1: Message, msg2: Message) -> Bool {
    1.62          // For this test we consider messages in a folder as equal if they have the same UUID and none of the
    1.63          // comparees has been marked deleted.