pEpForiOSTests/ObservableModelTest.swift
author Xavier Algarra <xavier@pep-project.org>
Tue, 06 Jun 2017 07:49:23 +0200
changeset 2248 75013a586bfd
parent 1062 fae04f06fe15
permissions -rw-r--r--
IOS-137 add multiple accounts option with the new login
xavier@1029
     1
//
xavier@1029
     2
//  ObservableModelTest.swift
xavier@1029
     3
//  pEpForiOS
xavier@1029
     4
//
xavier@1029
     5
//  Created by Xavier Algarra on 11/11/16.
xavier@1029
     6
//  Copyright © 2016 p≡p Security S.A. All rights reserved.
xavier@1029
     7
//
xavier@1029
     8
xavier@1029
     9
import XCTest
xavier@1029
    10
import MessageModel
xavier@1029
    11
xavier@1029
    12
class ObservableModelTest: XCTestCase {
dirk@1043
    13
    var persistentSetup: PersistentSetup!
dirk@1043
    14
xavier@1029
    15
    override func setUp() {
xavier@1029
    16
        super.setUp()
dirk@1043
    17
        persistentSetup = PersistentSetup()
dirk@1043
    18
    }
dirk@1043
    19
dirk@1043
    20
    override func tearDown() {
dirk@1043
    21
        persistentSetup = nil
dirk@1043
    22
        super.tearDown()
xavier@1029
    23
    }
xavier@1029
    24
dirk@1062
    25
    /*
xavier@1029
    26
    func testModelObserver() {
xavier@1029
    27
xavier@1029
    28
        class MockModel:ModelSaveProtocol {
xavier@1056
    29
            public struct ImapFlags {
xavier@1056
    30
                public var deleted = false
xavier@1056
    31
                public var draft = false
xavier@1056
    32
                public var flagged = false
xavier@1056
    33
                public var recent = false
xavier@1056
    34
                public var seen = false
xavier@1056
    35
            }
xavier@1056
    36
xavier@1056
    37
            open var imapFlags: ImapFlags? = ImapFlags() {
xavier@1056
    38
                didSet{
xavier@1056
    39
                    notifyObserver()
xavier@1056
    40
                }
xavier@1056
    41
            }
xavier@1029
    42
            var dirty: Bool = false
xavier@1029
    43
            var saveIsCalled: XCTestExpectation?
xavier@1029
    44
            var mockProperty = "" {
xavier@1029
    45
                didSet{
xavier@1029
    46
                    notifyObserver()
xavier@1029
    47
                    dirty = true;
xavier@1029
    48
                }
xavier@1029
    49
            }
dirk@1043
    50
xavier@1029
    51
            func save() {
xavier@1029
    52
                dirty = false
xavier@1029
    53
                self.saveIsCalled?.fulfill()
xavier@1029
    54
xavier@1029
    55
            }
xavier@1029
    56
        }
xavier@1029
    57
xavier@1029
    58
        let mm = MockModel();
xavier@1029
    59
        mm.saveIsCalled = expectation(description: "mm_dirty")
xavier@1029
    60
        XCTAssertFalse(mm.dirty)
xavier@1056
    61
        //mm.mockProperty = "new string"
xavier@1056
    62
        mm.imapFlags?.draft = true
xavier@1029
    63
        XCTAssertTrue(mm.dirty)
xavier@1029
    64
        
xavier@1029
    65
        waitForExpectations(timeout: TestUtil.waitTime, handler: { (error) in
xavier@1029
    66
            XCTAssertNil(error)
xavier@1029
    67
            XCTAssertFalse(mm.dirty)
xavier@1029
    68
        })
xavier@1029
    69
    }
dirk@1062
    70
     */
xavier@1029
    71
}