Skip to content

Commit

Permalink
#127: Use Clean Architecture for NumberOfKeys Scene + Unit Tests
Browse files Browse the repository at this point in the history
Improve unit tests for KeyType scene
  • Loading branch information
broadwaylamb committed Jul 20, 2016
1 parent 3ba245b commit a91d957
Show file tree
Hide file tree
Showing 16 changed files with 461 additions and 44 deletions.
42 changes: 39 additions & 3 deletions GroupLockiOS/GroupLock.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
8704DED01D3D03990017F88E /* ProvideKeyRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8704DEC91D3D03990017F88E /* ProvideKeyRouter.swift */; };
8704DED11D3D03990017F88E /* ProvideKeyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8704DECA1D3D03990017F88E /* ProvideKeyViewController.swift */; };
8704DED51D3D08320017F88E /* Crypto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8704DED41D3D08320017F88E /* Crypto.swift */; };
870DBF921D3F932C004430A5 /* NumberOfKeysConfigurator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 870DBF8C1D3F932C004430A5 /* NumberOfKeysConfigurator.swift */; };
870DBF931D3F932C004430A5 /* NumberOfKeysInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 870DBF8D1D3F932C004430A5 /* NumberOfKeysInteractor.swift */; };
870DBF941D3F932C004430A5 /* NumberOfKeysModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 870DBF8E1D3F932C004430A5 /* NumberOfKeysModels.swift */; };
870DBF951D3F932C004430A5 /* NumberOfKeysPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 870DBF8F1D3F932C004430A5 /* NumberOfKeysPresenter.swift */; };
870DBF961D3F932C004430A5 /* NumberOfKeysRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 870DBF901D3F932C004430A5 /* NumberOfKeysRouter.swift */; };
870DBF9E1D3F9BE9004430A5 /* NumberOfKeysInteractorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 870DBF9A1D3F9BE9004430A5 /* NumberOfKeysInteractorTests.swift */; };
870DBFA01D3F9BE9004430A5 /* NumberOfKeysViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 870DBF9C1D3F9BE9004430A5 /* NumberOfKeysViewControllerTests.swift */; };
8713DE4B1CEFA5400089C92A /* ChooseFileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8713DE4A1CEFA5400089C92A /* ChooseFileViewController.swift */; };
8713DE4F1CEFAAF30089C92A /* HomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8713DE4E1CEFAAF30089C92A /* HomeViewController.swift */; };
871C6AE11CF1E8A7004C5B38 /* NUIGeneralViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 871C6AE01CF1E8A7004C5B38 /* NUIGeneralViewTests.swift */; };
Expand Down Expand Up @@ -113,6 +120,13 @@
8704DEC91D3D03990017F88E /* ProvideKeyRouter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ProvideKeyRouter.swift; path = Scenes/Home_Stack/ProvideKeyScene/ProvideKeyRouter.swift; sourceTree = "<group>"; };
8704DECA1D3D03990017F88E /* ProvideKeyViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ProvideKeyViewController.swift; path = Scenes/Home_Stack/ProvideKeyScene/ProvideKeyViewController.swift; sourceTree = "<group>"; };
8704DED41D3D08320017F88E /* Crypto.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Crypto.swift; path = Core/Crypto.swift; sourceTree = "<group>"; };
870DBF8C1D3F932C004430A5 /* NumberOfKeysConfigurator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NumberOfKeysConfigurator.swift; path = Scenes/Home_Stack/NumberOfKeysScene/NumberOfKeysConfigurator.swift; sourceTree = "<group>"; };
870DBF8D1D3F932C004430A5 /* NumberOfKeysInteractor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NumberOfKeysInteractor.swift; path = Scenes/Home_Stack/NumberOfKeysScene/NumberOfKeysInteractor.swift; sourceTree = "<group>"; };
870DBF8E1D3F932C004430A5 /* NumberOfKeysModels.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NumberOfKeysModels.swift; path = Scenes/Home_Stack/NumberOfKeysScene/NumberOfKeysModels.swift; sourceTree = "<group>"; };
870DBF8F1D3F932C004430A5 /* NumberOfKeysPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NumberOfKeysPresenter.swift; path = Scenes/Home_Stack/NumberOfKeysScene/NumberOfKeysPresenter.swift; sourceTree = "<group>"; };
870DBF901D3F932C004430A5 /* NumberOfKeysRouter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NumberOfKeysRouter.swift; path = Scenes/Home_Stack/NumberOfKeysScene/NumberOfKeysRouter.swift; sourceTree = "<group>"; };
870DBF9A1D3F9BE9004430A5 /* NumberOfKeysInteractorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumberOfKeysInteractorTests.swift; sourceTree = "<group>"; };
870DBF9C1D3F9BE9004430A5 /* NumberOfKeysViewControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumberOfKeysViewControllerTests.swift; sourceTree = "<group>"; };
8713DE4A1CEFA5400089C92A /* ChooseFileViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChooseFileViewController.swift; path = Scenes/Home_Stack/ChooseFileScene/ChooseFileViewController.swift; sourceTree = "<group>"; };
8713DE4E1CEFAAF30089C92A /* HomeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HomeViewController.swift; path = Scenes/Home_Stack/HomeViewController.swift; sourceTree = "<group>"; };
871C6AE01CF1E8A7004C5B38 /* NUIGeneralViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NUIGeneralViewTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -244,6 +258,15 @@
name = Core;
sourceTree = "<group>";
};
870DBF991D3F9BBB004430A5 /* NumberOfKeysSceneTests */ = {
isa = PBXGroup;
children = (
870DBF9A1D3F9BE9004430A5 /* NumberOfKeysInteractorTests.swift */,
870DBF9C1D3F9BE9004430A5 /* NumberOfKeysViewControllerTests.swift */,
);
name = NumberOfKeysSceneTests;
sourceTree = "<group>";
};
8713DE4C1CEFA5520089C92A /* Library Stack */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -315,13 +338,13 @@
name = PasswordScene;
sourceTree = "<group>";
};
87736F181D3D562800B93D7B /* KeyTypesceneTests */ = {
87736F181D3D562800B93D7B /* KeyTypeSceneTests */ = {
isa = PBXGroup;
children = (
87736F191D3D565300B93D7B /* KeyTypeInteractorTests.swift */,
87736F1B1D3D565300B93D7B /* KeyTypeViewControllerTests.swift */,
);
name = KeyTypesceneTests;
name = KeyTypeSceneTests;
sourceTree = "<group>";
};
877ED3301CF7B1F000C5D0D4 /* ViewController Tests */ = {
Expand Down Expand Up @@ -425,7 +448,8 @@
873419B31D3817A0005D036C /* Test Resources */,
87FFF0341D33BFB1007315C7 /* PasswordSceneTests */,
874801871D36C3F8001A086C /* ChooseFileSceneTests */,
87736F181D3D562800B93D7B /* KeyTypesceneTests */,
87736F181D3D562800B93D7B /* KeyTypeSceneTests */,
870DBF991D3F9BBB004430A5 /* NumberOfKeysSceneTests */,
877ED3301CF7B1F000C5D0D4 /* ViewController Tests */,
87B072C61CC0E0C400916D09 /* NUI Tests */,
87B6922A1CB425E0008ACB6A /* Info.plist */,
Expand Down Expand Up @@ -465,7 +489,12 @@
87FAC9EF1D34ECBE00FE3602 /* NumberOfKeysScene */ = {
isa = PBXGroup;
children = (
870DBF901D3F932C004430A5 /* NumberOfKeysRouter.swift */,
8AE919D91D2F508A002024AC /* NumberOfKeysViewController.swift */,
870DBF8D1D3F932C004430A5 /* NumberOfKeysInteractor.swift */,
870DBF8F1D3F932C004430A5 /* NumberOfKeysPresenter.swift */,
870DBF8C1D3F932C004430A5 /* NumberOfKeysConfigurator.swift */,
870DBF8E1D3F932C004430A5 /* NumberOfKeysModels.swift */,
);
name = NumberOfKeysScene;
sourceTree = "<group>";
Expand Down Expand Up @@ -779,12 +808,16 @@
8713DE4B1CEFA5400089C92A /* ChooseFileViewController.swift in Sources */,
87FFF0521D34E9AE007315C7 /* ChooseFileRouter.swift in Sources */,
87736F141D3D49C200B93D7B /* KeyTypeModels.swift in Sources */,
870DBF951D3F932C004430A5 /* NumberOfKeysPresenter.swift in Sources */,
870DBF931D3F932C004430A5 /* NumberOfKeysInteractor.swift in Sources */,
8704DED01D3D03990017F88E /* ProvideKeyRouter.swift in Sources */,
87FFF0531D34E9AE007315C7 /* ChooseFileWorker.swift in Sources */,
87B509C11CD0B67A00641EC3 /* FileManager.swift in Sources */,
87FFF0501D34E9AE007315C7 /* ChooseFileModels.swift in Sources */,
87B6927F1CB45188008ACB6A /* UIViewController.swift in Sources */,
870DBF941D3F932C004430A5 /* NumberOfKeysModels.swift in Sources */,
8AE919DA1D2F508A002024AC /* NumberOfKeysViewController.swift in Sources */,
870DBF921D3F932C004430A5 /* NumberOfKeysConfigurator.swift in Sources */,
8704DECD1D3D03990017F88E /* ProvideKeyInteractor.swift in Sources */,
8704DED11D3D03990017F88E /* ProvideKeyViewController.swift in Sources */,
8704DEB31D3CCD8E0017F88E /* ManagedFile+CoreDataProperties.swift in Sources */,
Expand All @@ -797,6 +830,7 @@
8704DED51D3D08320017F88E /* Crypto.swift in Sources */,
87B692111CB425E0008ACB6A /* AppDelegate.swift in Sources */,
87CF826A1D3E3058000147EB /* ProvideKeyCell.swift in Sources */,
870DBF961D3F932C004430A5 /* NumberOfKeysRouter.swift in Sources */,
873419B21D37D686005D036C /* GroupLock.xcdatamodeld in Sources */,
87FFF02E1D33ACCE007315C7 /* PasswordConfigurator.swift in Sources */,
);
Expand All @@ -811,6 +845,7 @@
87B072E21CC1B7B300916D09 /* NUIPasswordViewTests.swift in Sources */,
877ED32F1CF7B1E300C5D0D4 /* UIViewControllerTests.swift in Sources */,
87C49EA11CF1EBDB006C0A83 /* NUIGeneralTableTests.swift in Sources */,
870DBF9E1D3F9BE9004430A5 /* NumberOfKeysInteractorTests.swift in Sources */,
87736F1F1D3D565300B93D7B /* KeyTypeViewControllerTests.swift in Sources */,
87B072E41CC1B8E600916D09 /* NUIProceedButtonTests.swift in Sources */,
87C49EA51CF1F349006C0A83 /* NUIGeneralTableCellTests.swift in Sources */,
Expand All @@ -828,6 +863,7 @@
877ED3351CF8B18900C5D0D4 /* NUICollectionViewCellTests.swift in Sources */,
87B072DB1CC1AB4200916D09 /* NUIBarButtonTests.swift in Sources */,
8748018D1D36C434001A086C /* ChooseFilePresenterTests.swift in Sources */,
870DBFA01D3F9BE9004430A5 /* NumberOfKeysViewControllerTests.swift in Sources */,
87B072E71CC1B9F900916D09 /* NUIEnterPasswordLabelTests.swift in Sources */,
87C49EA91CF1FB85006C0A83 /* NUIDirectoryButtonTests.swift in Sources */,
);
Expand Down
12 changes: 6 additions & 6 deletions GroupLockiOS/GroupLock/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
Expand Down Expand Up @@ -278,7 +278,7 @@
<barButtonItem key="backBarButtonItem" title="Back" id="zu9-7U-oVW"/>
<barButtonItem key="rightBarButtonItem" enabled="NO" title="Next" id="Leg-Dc-weu">
<connections>
<segue destination="vTA-sU-hsi" kind="show" id="4aj-4M-Izd"/>
<segue destination="vTA-sU-hsi" kind="show" identifier="KeyType" id="4aj-4M-Izd"/>
</connections>
</barButtonItem>
</navigationItem>
Expand Down Expand Up @@ -390,7 +390,7 @@
<!--Number Of Keys-->
<scene sceneID="S7w-4u-xQY">
<objects>
<viewController id="PUy-bJ-rb1" customClass="NumberOfKeysViewController" customModule="GroupLock" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="NumberOfKeysViewController" id="PUy-bJ-rb1" customClass="NumberOfKeysViewController" customModule="GroupLock" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="u5W-qr-D7n"/>
<viewControllerLayoutGuide type="bottom" id="NUO-f3-vRZ"/>
Expand Down Expand Up @@ -455,7 +455,7 @@
<barButtonItem key="backBarButtonItem" title="Back" id="HLb-FG-cDF"/>
<barButtonItem key="rightBarButtonItem" title="Next" id="3N9-g4-PfW">
<connections>
<segue destination="nBG-Ui-WPY" kind="show" id="tde-5B-Flf"/>
<segue destination="nBG-Ui-WPY" kind="show" identifier="ProvideKey" id="tde-5B-Flf"/>
</connections>
</barButtonItem>
</navigationItem>
Expand All @@ -467,10 +467,10 @@
</objects>
<point key="canvasLocation" x="4385" y="-601"/>
</scene>
<!--Your Keys-->
<!--ProvideKey-->
<scene sceneID="GQ5-4G-oR8">
<objects>
<collectionViewController id="nBG-Ui-WPY" customClass="ProvideKeyViewController" customModule="GroupLock" customModuleProvider="target" sceneMemberID="viewController">
<collectionViewController id="nBG-Ui-WPY" userLabel="ProvideKey" customClass="ProvideKeyViewController" customModule="GroupLock" customModuleProvider="target" sceneMemberID="viewController">
<collectionView key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" id="w2s-Bi-0nc">
<rect key="frame" x="0.0" y="64" width="600" height="536"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

protocol KeyTypeInteractorInput {
var files: [ManagedFile] { get set }
var files: [ManagedFile]! { get set }
var keyType: KeyType { get }

func setKeyType(request: KeyTypeModels.SetType.Request)
Expand All @@ -25,7 +25,7 @@ class KeyTypeInteractor: KeyTypeInteractorInput {

// MARK: - Business logic

var files = [ManagedFile]()
var files: [ManagedFile]!
var keyType: KeyType = .QRCode

func setKeyType(request: KeyTypeModels.SetType.Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ class KeyTypeRouter: KeyTypeRouterInput {
func passDataToNumberOfKeysScene(segue: UIStoryboardSegue) {

let numberOfKeysViewController = segue.destinationViewController as! NumberOfKeysViewController

numberOfKeysViewController.output.files = viewController.output.files
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protocol KeyTypeViewControllerInput {
}

protocol KeyTypeViewControllerOutput {
var files: [ManagedFile] { get set }
var files: [ManagedFile]! { get set }
var keyType: KeyType { get }

func setKeyType(request: KeyTypeModels.SetType.Request)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// NumberOfKeysConfigurator.swift
// GroupLock
//
// Created by Sergej Jaskiewicz on 20.07.16.
// Copyright (c) 2016 Lanit-Tercom School. All rights reserved.
//

import UIKit

// MARK: - Connect View, Interactor, and Presenter

extension NumberOfKeysViewController: NumberOfKeysPresenterOutput {
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
router.passDataToNextScene(segue)
}
}

extension NumberOfKeysInteractor: NumberOfKeysViewControllerOutput {}

extension NumberOfKeysPresenter: NumberOfKeysInteractorOutput {}

class NumberOfKeysConfigurator {

// MARK: - Configuration

static func configure(viewController: NumberOfKeysViewController) {
let router = NumberOfKeysRouter()
router.viewController = viewController

let presenter = NumberOfKeysPresenter()
presenter.output = viewController

let interactor = NumberOfKeysInteractor()
interactor.output = presenter

viewController.output = interactor
viewController.router = router
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// NumberOfKeysInteractor.swift
// GroupLock
//
// Created by Sergej Jaskiewicz on 20.07.16.
// Copyright (c) 2016 Lanit-Tercom School. All rights reserved.
//

import Foundation

protocol NumberOfKeysInteractorInput {
var numberOfKeys: Int { get }
var files: [ManagedFile]! { get }
}

protocol NumberOfKeysInteractorOutput {

}

class NumberOfKeysInteractor: NumberOfKeysInteractorInput {

var output: NumberOfKeysInteractorOutput!

// MARK: - Business logic

var numberOfKeys = Crypto.maximumNumberOfKeys

var files: [ManagedFile]!
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// NumberOfKeysModels.swift
// GroupLock
//
// Created by Sergej Jaskiewicz on 20.07.16.
// Copyright (c) 2016 Lanit-Tercom School. All rights reserved.
//

import Foundation

// MARK: Scene
struct NumberOfKeys {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// NumberOfKeysPresenter.swift
// GroupLock
//
// Created by Sergej Jaskiewicz on 20.07.16.
// Copyright (c) 2016 Lanit-Tercom School. All rights reserved.
//

import Foundation

protocol NumberOfKeysPresenterInput {

}

protocol NumberOfKeysPresenterOutput: class {

}

class NumberOfKeysPresenter: NumberOfKeysPresenterInput {

weak var output: NumberOfKeysPresenterOutput!

// MARK: - Presentation logic

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// NumberOfKeysRouter.swift
// GroupLock
//
// Created by Sergej Jaskiewicz on 20.07.16.
// Copyright (c) 2016 Lanit-Tercom School. All rights reserved.
//

import UIKit

protocol NumberOfKeysRouterInput {

}

class NumberOfKeysRouter: NumberOfKeysRouterInput {

weak var viewController: NumberOfKeysViewController!

// MARK: - Navigation

// MARK: - Communication

func passDataToNextScene(segue: UIStoryboardSegue) {

if segue.identifier == "ProvideKey" {
passDataToProvideKeyScene(segue)
}
}

func passDataToProvideKeyScene(segue: UIStoryboardSegue) {

let provideKeysViewController = segue.destinationViewController as! ProvideKeyViewController
provideKeysViewController.output.numberOfKeys = (viewController.pickerView.selectedRowInComponent(0) + 1,
viewController.pickerView.selectedRowInComponent(1) + 1)
}
}
Loading

0 comments on commit a91d957

Please sign in to comment.