Skip to content

Commit

Permalink
Add testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Антон Гостев authored and Антон Гостев committed May 9, 2017
1 parent c6869cc commit 0f2daa0
Show file tree
Hide file tree
Showing 6 changed files with 663 additions and 15 deletions.
25 changes: 25 additions & 0 deletions FBTest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
E222F3BB1EC1C6E20086BCD4 /* View.swift in Sources */ = {isa = PBXBuildFile; fileRef = E222F3BA1EC1C6E20086BCD4 /* View.swift */; };
E222F3BD1EC1C7080086BCD4 /* Presenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = E222F3BC1EC1C7080086BCD4 /* Presenter.swift */; };
E222F3BF1EC1C7310086BCD4 /* PresenterImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = E222F3BE1EC1C7310086BCD4 /* PresenterImpl.swift */; };
E222F3C41EC1EAFD0086BCD4 /* FacebokTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E222F3C31EC1EAFD0086BCD4 /* FacebokTests.swift */; };
E222F3C61EC205490086BCD4 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = E222F3C51EC205490086BCD4 /* GeneratedMocks.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -67,6 +69,8 @@
E222F3BA1EC1C6E20086BCD4 /* View.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = View.swift; sourceTree = "<group>"; };
E222F3BC1EC1C7080086BCD4 /* Presenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Presenter.swift; sourceTree = "<group>"; };
E222F3BE1EC1C7310086BCD4 /* PresenterImpl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PresenterImpl.swift; sourceTree = "<group>"; };
E222F3C31EC1EAFD0086BCD4 /* FacebokTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FacebokTests.swift; sourceTree = "<group>"; };
E222F3C51EC205490086BCD4 /* GeneratedMocks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedMocks.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -146,8 +150,10 @@
E222F39A1EC1C4080086BCD4 /* FBTestTests */ = {
isa = PBXGroup;
children = (
E222F3C51EC205490086BCD4 /* GeneratedMocks.swift */,
E222F39B1EC1C4080086BCD4 /* FBTestTests.swift */,
E222F39D1EC1C4080086BCD4 /* Info.plist */,
E222F3C31EC1EAFD0086BCD4 /* FacebokTests.swift */,
);
path = FBTestTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -242,6 +248,7 @@
E222F3951EC1C4080086BCD4 /* Resources */,
FB9AC5F46C5937B672A9B45E /* [CP] Embed Pods Frameworks */,
3F89A0541E8ADAE4212C9441 /* [CP] Copy Pods Resources */,
E222F3C01EC1E49C0086BCD4 /* ShellScript */,
);
buildRules = (
);
Expand Down Expand Up @@ -471,6 +478,19 @@
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
E222F3C01EC1E49C0086BCD4 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# Define output file; change \"${PROJECT_NAME}Tests\" to your test's root source folder, if it's not the default name\nOUTPUT_FILE=\"./${PROJECT_NAME}Tests/GeneratedMocks.swift\"\necho \"Generated Mocks File = ${OUTPUT_FILE}\"\n\n# Define input directory; change \"${PROJECT_NAME}\" to your project's root source folder, if it's not the default name\nINPUT_DIR=\"./${PROJECT_NAME}\"\necho \"Mocks Input Directory = ${INPUT_DIR}\"\n\n# Generate mock files; include as many input files as you'd like to create mocks for\n${PODS_ROOT}/Cuckoo/run generate --testable \"${PROJECT_NAME}\" \\\n--output \"${OUTPUT_FILE}\" \\\n\"${INPUT_DIR}/PresenterImpl.swift\" \\\n\"${INPUT_DIR}/ViewController.swift\" \\\n\"${INPUT_DIR}/Facebook.swift\"";
};
FB9AC5F46C5937B672A9B45E /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -506,6 +526,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
E222F3C41EC1EAFD0086BCD4 /* FacebokTests.swift in Sources */,
E222F3C61EC205490086BCD4 /* GeneratedMocks.swift in Sources */,
E222F39C1EC1C4080086BCD4 /* FBTestTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -755,6 +777,7 @@
E222F3AD1EC1C4080086BCD4 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
E222F3AE1EC1C4080086BCD4 /* Build configuration list for PBXNativeTarget "FBTestTests" */ = {
isa = XCConfigurationList;
Expand All @@ -763,6 +786,7 @@
E222F3B01EC1C4080086BCD4 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
E222F3B11EC1C4080086BCD4 /* Build configuration list for PBXNativeTarget "FBTestUITests" */ = {
isa = XCConfigurationList;
Expand All @@ -771,6 +795,7 @@
E222F3B31EC1C4080086BCD4 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
4 changes: 2 additions & 2 deletions FBTest/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="FBTest" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="ViewController" id="BYZ-38-t0r" customClass="ViewController" customModule="FBTest" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
Expand All @@ -23,7 +23,7 @@
<subviews>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="4iO-mm-ecH">
<rect key="frame" x="100" y="318" width="174" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<state key="normal" title="Get Token"/>
<connections>
<action selector="getTokenButtonTapAction:" destination="BYZ-38-t0r" eventType="touchUpInside" id="5pK-4N-9Dy"/>
Expand Down
8 changes: 6 additions & 2 deletions FBTest/Facebook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ import SafariServices

class Facebook {

static let shared = Facebook()
static let shared : Facebook = Facebook()

private init() {
}

let url = URL(string: "https://www.facebook.com/dialog/oauth?client_id=1211141362338583&client_secret=e891ddb7d10306bd8c2757de21795638&redirect_uri=fbconnect://success&response_type=token")
let url : URL? = URL(string: "https://www.facebook.com/dialog/oauth?client_id=1211141362338583&client_secret=e891ddb7d10306bd8c2757de21795638&redirect_uri=fbconnect://success&response_type=token")

var viewController : UIViewController?

var svc : SFSafariViewController?

var callback : ((String?, Error?) -> Void)?

var loginWasCalled : Bool = false

/*! Get facebook access token by opening a login window.

@param callback returns AccessToken as String or an Error.
Expand All @@ -38,6 +40,8 @@ class Facebook {
/*! Open a login window.
*/
private func login() {
loginWasCalled = true

svc = SFSafariViewController(url: url!)
viewController?.present(svc!, animated: true, completion: nil)
}
Expand Down
28 changes: 17 additions & 11 deletions FBTestTests/FBTestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,35 @@

import XCTest
@testable import FBTest
import Cuckoo

class FBTestTests: XCTestCase {

var viewController: ViewController!

override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.

viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ViewController") as! ViewController
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}

func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}

func testPerformanceExample() {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
func testCallsGetAuthTokenOfFacebookAfterTapGetTokenButton() {

let presenter = PresenterImpl(view: viewController)

viewController.presenter = presenter

XCTAssertFalse(Facebook.shared.loginWasCalled)

viewController.getTokenButtonTapAction(self)

XCTAssertTrue(Facebook.shared.loginWasCalled)

}

}
33 changes: 33 additions & 0 deletions FBTestTests/FacebokTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// FacebokTests.swift
// FBTest
//
// Created by Антон Гостев on 09.05.17.
// Copyright © 2017 Антон Гостев. All rights reserved.
//

import XCTest
@testable import FBTest
import Cuckoo

class FacebokTests: XCTestCase {

override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}

func testVariables() {

let url = URL(string: "https://www.facebook.com/dialog/oauth?client_id=1211141362338583&client_secret=e891ddb7d10306bd8c2757de21795638&redirect_uri=fbconnect://success&response_type=token")

XCTAssertEqual(url, Facebook.shared.url)

}

}
Loading

0 comments on commit 0f2daa0

Please sign in to comment.