IOS-1697 fix naming, not crashing in test IOS-1697
authorAlejandro Gelos <alejandro@pep-project.org>
Wed, 07 Aug 2019 16:22:18 +0200
branchIOS-1697
changeset 960251d9c7d8b90a
parent 9601 dc281878e429
child 9603 8b6427c4c87d
IOS-1697 fix naming, not crashing in test
pEpForiOS.xcodeproj/project.pbxproj
pEpForiOS/UI/KeySyncHandshake/KeySyncHandshakeViewController.swift
pEpForiOS/UI/KeySyncHandshake/KeySyncHandshakeViewModel.swift
pEpForiOS/UI/Util/Extensions/UIViewController+Extension.swift
pEpForiOSTests/UI/KeySyncHandshake/KeySyncHandshakeViewModelTest.swift
pEpForiOSTests/UI/Util/Extensions/UIViewController/UIViewController+KeySyncHandshakeTest.swift
     1.1 --- a/pEpForiOS.xcodeproj/project.pbxproj	Wed Aug 07 15:31:22 2019 +0200
     1.2 +++ b/pEpForiOS.xcodeproj/project.pbxproj	Wed Aug 07 16:22:18 2019 +0200
     1.3 @@ -208,7 +208,6 @@
     1.4  		222B35581DF96389007A1F82 /* Capability.swift in Sources */ = {isa = PBXBuildFile; fileRef = 222B35571DF96389007A1F82 /* Capability.swift */; };
     1.5  		228038681DC9DE6D00F1CB45 /* TextfieldResponder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 228038671DC9DE6D00F1CB45 /* TextfieldResponder.swift */; };
     1.6  		3705095D22CF4AC900CB73D6 /* KeySyncHandshakeViewModelTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3705095C22CF4AC900CB73D6 /* KeySyncHandshakeViewModelTest.swift */; };
     1.7 -		3705096022CF663800CB73D6 /* UIViewController+KeySyncHandshakeTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3705095F22CF663800CB73D6 /* UIViewController+KeySyncHandshakeTest.swift */; };
     1.8  		3705096622CF688F00CB73D6 /* KeySyncHandshakeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3705096522CF688F00CB73D6 /* KeySyncHandshakeViewModel.swift */; };
     1.9  		3705096822CF6AD100CB73D6 /* KeySyncHandshakeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3705096722CF6AD100CB73D6 /* KeySyncHandshakeViewController.swift */; };
    1.10  		3705096A22D4D83B00CB73D6 /* PEPSessionMoc.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3705096922D4D83B00CB73D6 /* PEPSessionMoc.swift */; };
    1.11 @@ -688,7 +687,6 @@
    1.12  		222B35571DF96389007A1F82 /* Capability.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Capability.swift; sourceTree = "<group>"; };
    1.13  		228038671DC9DE6D00F1CB45 /* TextfieldResponder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextfieldResponder.swift; sourceTree = "<group>"; };
    1.14  		3705095C22CF4AC900CB73D6 /* KeySyncHandshakeViewModelTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeySyncHandshakeViewModelTest.swift; sourceTree = "<group>"; };
    1.15 -		3705095F22CF663800CB73D6 /* UIViewController+KeySyncHandshakeTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+KeySyncHandshakeTest.swift"; sourceTree = "<group>"; };
    1.16  		3705096522CF688F00CB73D6 /* KeySyncHandshakeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeySyncHandshakeViewModel.swift; sourceTree = "<group>"; };
    1.17  		3705096722CF6AD100CB73D6 /* KeySyncHandshakeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeySyncHandshakeViewController.swift; sourceTree = "<group>"; };
    1.18  		3705096922D4D83B00CB73D6 /* PEPSessionMoc.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PEPSessionMoc.swift; sourceTree = "<group>"; };
    1.19 @@ -1611,20 +1609,6 @@
    1.20  			name = Cells;
    1.21  			sourceTree = "<group>";
    1.22  		};
    1.23 -		3705095A22CE32BA00CB73D6 /* Recovered References */ = {
    1.24 -			isa = PBXGroup;
    1.25 -			children = (
    1.26 -				154918E222BA74D70091B6D6 /* PantomimeFramework.framework */,
    1.27 -				154918DF22BA74BA0091B6D6 /* AppAuth.framework */,
    1.28 -				154918CF22BA74230091B6D6 /* ldns_xcode.framework */,
    1.29 -				154918DC22BA74A90091B6D6 /* PEPObjCAdapterFramework.framework */,
    1.30 -				154918D922BA74800091B6D6 /* MessageModel.framework */,
    1.31 -				154918D322BA74670091B6D6 /* pEpIOSToolbox.framework */,
    1.32 -				154918D622BA74700091B6D6 /* SwipeCellKit.framework */,
    1.33 -			);
    1.34 -			name = "Recovered References";
    1.35 -			sourceTree = "<group>";
    1.36 -		};
    1.37  		3705095B22CF465300CB73D6 /* KeySyncHandshake */ = {
    1.38  			isa = PBXGroup;
    1.39  			children = (
    1.40 @@ -1634,22 +1618,6 @@
    1.41  			path = KeySyncHandshake;
    1.42  			sourceTree = "<group>";
    1.43  		};
    1.44 -		3705095E22CF65DC00CB73D6 /* Extensions */ = {
    1.45 -			isa = PBXGroup;
    1.46 -			children = (
    1.47 -				3705096322CF682400CB73D6 /* UIViewController */,
    1.48 -			);
    1.49 -			path = Extensions;
    1.50 -			sourceTree = "<group>";
    1.51 -		};
    1.52 -		3705096322CF682400CB73D6 /* UIViewController */ = {
    1.53 -			isa = PBXGroup;
    1.54 -			children = (
    1.55 -				3705095F22CF663800CB73D6 /* UIViewController+KeySyncHandshakeTest.swift */,
    1.56 -			);
    1.57 -			path = UIViewController;
    1.58 -			sourceTree = "<group>";
    1.59 -		};
    1.60  		3705096422CF686C00CB73D6 /* KeySyncHandshake */ = {
    1.61  			isa = PBXGroup;
    1.62  			children = (
    1.63 @@ -1798,7 +1766,6 @@
    1.64  		4356FFEA21356CB600804089 /* Util */ = {
    1.65  			isa = PBXGroup;
    1.66  			children = (
    1.67 -				3705095E22CF65DC00CB73D6 /* Extensions */,
    1.68  				15D439A1216F7DCA00EB3933 /* AccountPickerViewModel */,
    1.69  				1526597B2163772C006A78DF /* SuggestTableViewController */,
    1.70  				4356FFEB21356CB600804089 /* ReplyAllPossibleCheckerTest.swift */,
    1.71 @@ -3096,7 +3063,6 @@
    1.72  				151F71FB202A06760057C74D /* MockBackgrounder.swift in Sources */,
    1.73  				43D51E891DD5D902008B77A8 /* SimpleOperationsTest.swift in Sources */,
    1.74  				3705096A22D4D83B00CB73D6 /* PEPSessionMoc.swift in Sources */,
    1.75 -				3705096022CF663800CB73D6 /* UIViewController+KeySyncHandshakeTest.swift in Sources */,
    1.76  				151F71FE202A06760057C74D /* CdMessage+TestUtils.swift in Sources */,
    1.77  				3791A45F22BA6A0300A9E534 /* MessageModelServiceMoc.swift in Sources */,
    1.78  				151F71F9202A06760057C74D /* ReplicationServiceObserver.swift in Sources */,
     2.1 --- a/pEpForiOS/UI/KeySyncHandshake/KeySyncHandshakeViewController.swift	Wed Aug 07 15:31:22 2019 +0200
     2.2 +++ b/pEpForiOS/UI/KeySyncHandshake/KeySyncHandshakeViewController.swift	Wed Aug 07 16:22:18 2019 +0200
     2.3 @@ -9,6 +9,10 @@
     2.4  import UIKit
     2.5  
     2.6  final class KeySyncHandshakeViewController: UIViewController {
     2.7 +    enum Action {
     2.8 +        case cancel, decline, accept
     2.9 +    }
    2.10 +
    2.11      static let storyboardId = "KeySyncHandshakeViewController"
    2.12      
    2.13      @IBOutlet weak var keySyncWords: UILabel! {
    2.14 @@ -30,12 +34,12 @@
    2.15      }
    2.16      @IBOutlet weak var alertTitle: UILabel! {
    2.17          didSet {
    2.18 -            alertTitle.text = NSLocalizedString("p≡p Sync", comment: "handshake sync alert title")
    2.19 +            alertTitle.text = NSLocalizedString("p≡p Sync", comment: "keySync handshake alert title")
    2.20          }
    2.21      }
    2.22      @IBOutlet weak var message: UILabel! {
    2.23          didSet {
    2.24 -            message.text = NSLocalizedString("A second device is detected. Please confirm the Trustwords on both devices to sync all your privacy. Shall we synchronize?", comment: "handshake sync alert message")
    2.25 +            message.text = NSLocalizedString("A second device is detected. Please confirm the Trustwords on both devices to sync all your privacy. Shall we synchronize?", comment: "keySync handshake alert message")
    2.26          }
    2.27      }
    2.28  
    2.29 @@ -66,10 +70,6 @@
    2.30          }
    2.31      }
    2.32  
    2.33 -    enum Action {
    2.34 -        case cancel, decline, accept
    2.35 -    }
    2.36 -
    2.37      var completion: ((Action) -> Void)?
    2.38  
    2.39      private let viewModel = KeySyncHandshakeViewModel()
    2.40 @@ -92,7 +92,7 @@
    2.41          guard let action = pressedAction(tag: sender.tag) else {
    2.42              return
    2.43          }
    2.44 -        viewModel.didPress(action: action)
    2.45 +        viewModel.handle(action: action)
    2.46      }
    2.47  
    2.48      @IBAction func didLongPressWords(_ sender: UILongPressGestureRecognizer) {
     3.1 --- a/pEpForiOS/UI/KeySyncHandshake/KeySyncHandshakeViewModel.swift	Wed Aug 07 15:31:22 2019 +0200
     3.2 +++ b/pEpForiOS/UI/KeySyncHandshake/KeySyncHandshakeViewModel.swift	Wed Aug 07 16:22:18 2019 +0200
     3.3 @@ -51,7 +51,7 @@
     3.4          delegate?.change(handshakeWordsTo: trustWorkds())
     3.5      }
     3.6  
     3.7 -    func didPress(action: Action) {
     3.8 +    func handle(action: Action) {
     3.9          switch action {
    3.10          case .accept, .cancel, .decline:
    3.11              delegate?.didPress(action: action)
    3.12 @@ -85,7 +85,7 @@
    3.13                                                        full: fullTrustWords)
    3.14          } catch {
    3.15              Log.shared.errorAndCrash("%@", error.localizedDescription)
    3.16 -            return String()
    3.17 +            return ""
    3.18          }
    3.19      }
    3.20  
     4.1 --- a/pEpForiOS/UI/Util/Extensions/UIViewController+Extension.swift	Wed Aug 07 15:31:22 2019 +0200
     4.2 +++ b/pEpForiOS/UI/Util/Extensions/UIViewController+Extension.swift	Wed Aug 07 16:22:18 2019 +0200
     4.3 @@ -44,7 +44,7 @@
     4.4      func presentKeySyncHandShakeAlert(meFPR: String, partnerFPR: String,
     4.5                          completion: @escaping (KeySyncHandshakeViewController.Action) -> Void ) {
     4.6  
     4.7 -        let storyboard = UIStoryboard(name: "Reusable", bundle: .main)
     4.8 +        let storyboard = UIStoryboard(name: Constants.suggestionsStoryboard, bundle: .main)
     4.9          guard let handShakeViewController = storyboard.instantiateViewController(
    4.10              withIdentifier: KeySyncHandshakeViewController.storyboardId) as? KeySyncHandshakeViewController else {
    4.11                  Log.shared.errorAndCrash("Fail to instantiateViewController KeySyncHandshakeViewController")
     5.1 --- a/pEpForiOSTests/UI/KeySyncHandshake/KeySyncHandshakeViewModelTest.swift	Wed Aug 07 15:31:22 2019 +0200
     5.2 +++ b/pEpForiOSTests/UI/KeySyncHandshake/KeySyncHandshakeViewModelTest.swift	Wed Aug 07 16:22:18 2019 +0200
     5.3 @@ -16,6 +16,8 @@
     5.4      var expected: State?
     5.5  
     5.6      override func setUp() {
     5.7 +        super.setUp()
     5.8 +
     5.9          keySyncHandshakeVM = KeySyncHandshakeViewModel(pEpSession: PEPSessionMoc())
    5.10          keySyncHandshakeVM?.fingerPrints(meFPR: "", partnerFPR: "")
    5.11          keySyncHandshakeVM?.delegate = self
    5.12 @@ -25,19 +27,20 @@
    5.13      }
    5.14  
    5.15      override func tearDown() {
    5.16 -        unwrap(value: keySyncHandshakeVM)
    5.17 -        unwrap(value: actual)
    5.18 -        unwrap(value: expected)
    5.19 -
    5.20          keySyncHandshakeVM?.delegate = nil
    5.21          keySyncHandshakeVM = nil
    5.22          actual = nil
    5.23          expected = nil
    5.24 +
    5.25 +        super.tearDown()
    5.26      }
    5.27  
    5.28      func testDidSelectLanguageToOtherOrSame() {
    5.29          // GIVEN
    5.30 -        let keySyncHandshakeVM = unwrap(value: self.keySyncHandshakeVM)
    5.31 +        guard let keySyncHandshakeVM = keySyncHandshakeVM else {
    5.32 +            XCTFail()
    5.33 +            return
    5.34 +        }
    5.35          expected = State(didCallClosePicker: true, didCallToUpdateTrustedWords: true)
    5.36  
    5.37          // WHEN
    5.38 @@ -49,11 +52,14 @@
    5.39  
    5.40      func testDidPressActionAccept() {
    5.41          // GIVEN
    5.42 -        let keySyncHandshakeVM = unwrap(value: self.keySyncHandshakeVM)
    5.43 +        guard let keySyncHandshakeVM = keySyncHandshakeVM else {
    5.44 +            XCTFail()
    5.45 +            return
    5.46 +        }
    5.47          expected = State(didCallDidPressAction: true, pressedAction: .accept)
    5.48  
    5.49          // WHEN
    5.50 -        keySyncHandshakeVM.didPress(action: .accept)
    5.51 +        keySyncHandshakeVM.handle(action: .accept)
    5.52  
    5.53          // THEN
    5.54          assertExpectations()
    5.55 @@ -61,11 +67,14 @@
    5.56  
    5.57      func testDidPressActionChangeLanguage() {
    5.58          // GIVEN
    5.59 -        let keySyncHandshakeVM = unwrap(value: self.keySyncHandshakeVM)
    5.60 +        guard let keySyncHandshakeVM = keySyncHandshakeVM else {
    5.61 +            XCTFail()
    5.62 +            return
    5.63 +        }
    5.64          expected = State(didCallShowPicker: true, languagesToShow: ["", ""])
    5.65  
    5.66          // WHEN
    5.67 -        keySyncHandshakeVM.didPress(action: .changeLanguage)
    5.68 +        keySyncHandshakeVM.handle(action: .changeLanguage)
    5.69  
    5.70          // THEN
    5.71          assertExpectations()
    5.72 @@ -73,11 +82,14 @@
    5.73  
    5.74      func testDidPressActionDecline() {
    5.75          // GIVEN
    5.76 -        let keySyncHandshakeVM = unwrap(value: self.keySyncHandshakeVM)
    5.77 +        guard let keySyncHandshakeVM = keySyncHandshakeVM else {
    5.78 +            XCTFail()
    5.79 +            return
    5.80 +        }
    5.81          expected = State(didCallDidPressAction: true, pressedAction: .decline)
    5.82  
    5.83          // WHEN
    5.84 -        keySyncHandshakeVM.didPress(action: .decline)
    5.85 +        keySyncHandshakeVM.handle(action: .decline)
    5.86  
    5.87          // THEN
    5.88          assertExpectations()
    5.89 @@ -85,11 +97,14 @@
    5.90  
    5.91      func testDidPressActionCancel() {
    5.92          // GIVEN
    5.93 -        let keySyncHandshakeVM = unwrap(value: self.keySyncHandshakeVM)
    5.94 +        guard let keySyncHandshakeVM = keySyncHandshakeVM else {
    5.95 +            XCTFail()
    5.96 +            return
    5.97 +        }
    5.98          expected = State(didCallDidPressAction: true, pressedAction: .cancel)
    5.99  
   5.100          // WHEN
   5.101 -        keySyncHandshakeVM.didPress(action: .cancel)
   5.102 +        keySyncHandshakeVM.handle(action: .cancel)
   5.103  
   5.104          // THEN
   5.105          assertExpectations()
   5.106 @@ -97,7 +112,10 @@
   5.107  
   5.108      func testDidLongPressWords() {
   5.109          // GIVEN
   5.110 -        let keySyncHandshakeVM = unwrap(value: self.keySyncHandshakeVM)
   5.111 +        guard let keySyncHandshakeVM = keySyncHandshakeVM else {
   5.112 +            XCTFail()
   5.113 +            return
   5.114 +        }
   5.115          expected = State(didCallToUpdateTrustedWords: true, fullWordsVersion: true)
   5.116  
   5.117          // WHEN
   5.118 @@ -134,22 +152,16 @@
   5.119  // MARK: - Private
   5.120  
   5.121  extension KeySyncHandshakeViewModelTest {
   5.122 -    @discardableResult
   5.123 -    private func unwrap<T>(value: T?) -> T {
   5.124 -        guard let value = value else {
   5.125 -            XCTFail()
   5.126 -            fatalError("value is nil")
   5.127 -        }
   5.128 -        return value
   5.129 -    }
   5.130 -
   5.131      private func setDefaultActualState() {
   5.132          actual = State()
   5.133      }
   5.134  
   5.135      private func assertExpectations() {
   5.136 -        let expected = unwrap(value: self.expected)
   5.137 -        let actual = unwrap(value: self.actual)
   5.138 +        guard let expected = expected,
   5.139 +            let actual = actual else {
   5.140 +                XCTFail()
   5.141 +                return
   5.142 +        }
   5.143  
   5.144          //bools
   5.145          XCTAssertEqual(expected.didCallShowPicker, actual.didCallShowPicker)
     6.1 --- a/pEpForiOSTests/UI/Util/Extensions/UIViewController/UIViewController+KeySyncHandshakeTest.swift	Wed Aug 07 15:31:22 2019 +0200
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,32 +0,0 @@
     6.4 -//
     6.5 -//  UIViewController+KeySyncHandshakeTest.swift
     6.6 -//  pEpForiOSTests
     6.7 -//
     6.8 -//  Created by Alejandro Gelos on 05/07/2019.
     6.9 -//  Copyright © 2019 p≡p Security S.A. All rights reserved.
    6.10 -//
    6.11 -
    6.12 -import XCTest
    6.13 -
    6.14 -class UIViewController_KeySyncHandshakeTest: XCTestCase {
    6.15 -
    6.16 -    override func setUp() {
    6.17 -        // Put setup code here. This method is called before the invocation of each test method in the class.
    6.18 -    }
    6.19 -
    6.20 -    override func tearDown() {
    6.21 -        // Put teardown code here. This method is called after the invocation of each test method in the class.
    6.22 -    }
    6.23 -
    6.24 -    func testExample() {
    6.25 -        // This is an example of a functional test case.
    6.26 -        // Use XCTAssert and related functions to verify your tests produce the correct results.
    6.27 -    }
    6.28 -
    6.29 -    func testPerformanceExample() {
    6.30 -        // This is an example of a performance test case.
    6.31 -        self.measure {
    6.32 -            // Put the code you want to measure the time of here.
    6.33 -        }
    6.34 -    }
    6.35 -}