Browse Source

Initial UI testing setup

simple-swift-promises
Shadowfacts 2 years ago
parent
commit
49f58cf955
Signed by: shadowfacts GPG Key ID: 94A5AB95422746E5
  1. 6
      .gitmodules
  2. 1
      Ambassador
  3. BIN
      BlankSlate.xcappdata/AppDataInfo.plist
  4. 1
      Embassy
  5. 49
      Tusker.xcodeproj/project.pbxproj
  6. 27
      Tusker.xcodeproj/xcshareddata/xcschemes/Tusker.xcscheme
  7. 9
      Tusker.xcworkspace/contents.xcworkspacedata
  8. 11
      Tusker/Info.plist
  9. 14
      Tusker/LocalData.swift
  10. 9
      Tusker/Screens/Onboarding/InstanceSelectorTableViewController.swift
  11. 7
      Tusker/Views/Instance Cell/InstanceTableViewCell.xib
  12. 38
      TuskerUITests/OnboardingTests.swift
  13. 58
      TuskerUITests/TuskerUITests.swift

6
.gitmodules

@ -7,3 +7,9 @@
[submodule "Gifu"]
path = Gifu
url = git://github.com/kaishin/Gifu.git
[submodule "Embassy"]
path = Embassy
url = https://github.com/envoy/Embassy.git
[submodule "Ambassador"]
path = Ambassador
url = https://github.com/envoy/Ambassador.git

1
Ambassador

@ -0,0 +1 @@
Subproject commit 4fe264af51e0dd7228486c604750909e368241a7

BIN
BlankSlate.xcappdata/AppDataInfo.plist

Binary file not shown.

1
Embassy

@ -0,0 +1 @@
Subproject commit 189436100c00efbf5fb2653fe7972a9371db0a91

49
Tusker.xcodeproj/project.pbxproj

@ -114,6 +114,9 @@
D64F80E2215875CC00BEF393 /* XCBActionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = D64F80E1215875CC00BEF393 /* XCBActionType.swift */; };
D6538945214D6D7500E3CEFC /* TableViewSwipeActionProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6538944214D6D7500E3CEFC /* TableViewSwipeActionProvider.swift */; };
D65A37F321472F300087646E /* SwiftSoup.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D6BED16E212663DA00F02DA0 /* SwiftSoup.framework */; };
D65F613423AEAB6600F3CFD3 /* OnboardingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D65F613323AEAB6600F3CFD3 /* OnboardingTests.swift */; };
D65F613623AFD65900F3CFD3 /* Ambassador.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D65F613523AFD65900F3CFD3 /* Ambassador.framework */; };
D65F613823AFD65D00F3CFD3 /* Embassy.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D65F613723AFD65D00F3CFD3 /* Embassy.framework */; };
D663625D2135C74800C9CBA2 /* ConversationMainStatusTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D663625C2135C74800C9CBA2 /* ConversationMainStatusTableViewCell.xib */; };
D663625F2135C75500C9CBA2 /* ConversationMainStatusTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D663625E2135C75500C9CBA2 /* ConversationMainStatusTableViewCell.swift */; };
D663626221360B1900C9CBA2 /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = D663626121360B1900C9CBA2 /* Preferences.swift */; };
@ -391,6 +394,11 @@
D64D0AB02128D9AE005A6F37 /* OnboardingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingViewController.swift; sourceTree = "<group>"; };
D64F80E1215875CC00BEF393 /* XCBActionType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCBActionType.swift; sourceTree = "<group>"; };
D6538944214D6D7500E3CEFC /* TableViewSwipeActionProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewSwipeActionProvider.swift; sourceTree = "<group>"; };
D65F612D23AE990C00F3CFD3 /* Embassy.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Embassy.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D65F613023AE99E000F3CFD3 /* Ambassador.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Ambassador.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D65F613323AEAB6600F3CFD3 /* OnboardingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingTests.swift; sourceTree = "<group>"; };
D65F613523AFD65900F3CFD3 /* Ambassador.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Ambassador.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D65F613723AFD65D00F3CFD3 /* Embassy.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Embassy.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D663625C2135C74800C9CBA2 /* ConversationMainStatusTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ConversationMainStatusTableViewCell.xib; sourceTree = "<group>"; };
D663625E2135C75500C9CBA2 /* ConversationMainStatusTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationMainStatusTableViewCell.swift; sourceTree = "<group>"; };
D663626121360B1900C9CBA2 /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = "<group>"; };
@ -501,6 +509,7 @@
D6F1F84C2193B56E00F5FE67 /* Cache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Cache.swift; sourceTree = "<group>"; };
D6F953EB212519E700CF0F2B /* TimelineTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineTableViewController.swift; sourceTree = "<group>"; };
D6F953EF21251A2900CF0F2B /* MastodonController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonController.swift; sourceTree = "<group>"; };
D6F98BD523AE951F008A4DAC /* Swifter.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Swifter.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -530,6 +539,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
D65F613823AFD65D00F3CFD3 /* Embassy.framework in Frameworks */,
D65F613623AFD65900F3CFD3 /* Ambassador.framework in Frameworks */,
D60A549221ED515800F1F87C /* GMImagePicker.framework in Frameworks */,
D61099C02144B0CC00432DC2 /* Pachyderm.framework in Frameworks */,
D65A37F321472F300087646E /* SwiftSoup.framework in Frameworks */,
@ -947,6 +958,11 @@
D65A37F221472F300087646E /* Frameworks */ = {
isa = PBXGroup;
children = (
D65F613723AFD65D00F3CFD3 /* Embassy.framework */,
D65F613523AFD65900F3CFD3 /* Ambassador.framework */,
D65F613023AE99E000F3CFD3 /* Ambassador.framework */,
D65F612D23AE990C00F3CFD3 /* Embassy.framework */,
D6F98BD523AE951F008A4DAC /* Swifter.framework */,
);
name = Frameworks;
sourceTree = "<group>";
@ -1259,6 +1275,7 @@
isa = PBXGroup;
children = (
D6D4DDEF212518A200E1C4BB /* TuskerUITests.swift */,
D65F613323AEAB6600F3CFD3 /* OnboardingTests.swift */,
D6D4DDF1212518A200E1C4BB /* Info.plist */,
);
path = TuskerUITests;
@ -1371,6 +1388,7 @@
D6D4DDC9212518A000E1C4BB /* Frameworks */,
D6D4DDCA212518A000E1C4BB /* Resources */,
D6F953E52125197500CF0F2B /* Embed Frameworks */,
D65F612C23AE957600F3CFD3 /* Embed debug-only frameworks */,
);
buildRules = (
);
@ -1415,6 +1433,8 @@
D6D4DDED212518A200E1C4BB /* PBXTargetDependency */,
);
name = TuskerUITests;
packageProductDependencies = (
);
productName = TuskerUITests;
productReference = D6D4DDEB212518A200E1C4BB /* TuskerUITests.xctest */;
productType = "com.apple.product-type.bundle.ui-testing";
@ -1472,6 +1492,8 @@
ca,
);
mainGroup = D6D4DDC3212518A000E1C4BB;
packageReferences = (
);
productRefGroup = D6D4DDCD212518A000E1C4BB /* Products */;
projectDirPath = "";
projectRoot = "";
@ -1564,6 +1586,31 @@
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
D65F612C23AE957600F3CFD3 /* Embed debug-only frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${BUILT_PRODUCTS_DIR}/Embassy.framework",
"${BUILT_PRODUCTS_DIR}/Ambassador.framework",
);
name = "Embed debug-only frameworks";
outputFileListPaths = (
);
outputPaths = (
"${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Embassy.framework",
"${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Ambassador.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if [ \"${CONFIGURATION}\" == \"Debug\" ]; then\n echo \"Embedding ${SCRIPT_INPUT_FILE_0}\"\n cp -R $SCRIPT_INPUT_FILE_0 $SCRIPT_OUTPUT_FILE_0\n codesign --force --verbose --sign $EXPANDED_CODE_SIGN_IDENTITY $SCRIPT_OUTPUT_FILE_0\n \n echo \"Embedding ${SCRIPT_INPUT_FILE_1}\"\n cp -R $SCRIPT_INPUT_FILE_1 $SCRIPT_OUTPUT_FILE_1\n codesign --force --verbose --sign $EXPANDED_CODE_SIGN_IDENTITY $SCRIPT_OUTPUT_FILE_1\nelse\n echo \"Skipping embedding debug frameworks\"\nfi\n";
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
D60A548721ED515800F1F87C /* Sources */ = {
isa = PBXSourcesBuildPhase;
@ -1764,6 +1811,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D65F613423AEAB6600F3CFD3 /* OnboardingTests.swift in Sources */,
D6D4DDF0212518A200E1C4BB /* TuskerUITests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -2166,6 +2214,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
OTHER_LDFLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = net.shadowfacts.Tusker;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";

27
Tusker.xcodeproj/xcshareddata/xcschemes/Tusker.xcscheme

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
version = "1.3">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
@ -27,6 +27,15 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D6D4DDCB212518A000E1C4BB"
BuildableName = "Tusker.app"
BlueprintName = "Tusker"
ReferencedContainer = "container:Tusker.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
@ -47,6 +56,9 @@
BlueprintName = "TuskerUITests"
ReferencedContainer = "container:Tusker.xcodeproj">
</BuildableReference>
<DeviceAppData
resolvedPath = "../BlankSlate.xcappdata">
</DeviceAppData>
</TestableReference>
<TestableReference
skipped = "NO">
@ -59,17 +71,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D6D4DDCB212518A000E1C4BB"
BuildableName = "Tusker.app"
BlueprintName = "Tusker"
ReferencedContainer = "container:Tusker.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
@ -91,8 +92,6 @@
ReferencedContainer = "container:Tusker.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"

9
Tusker.xcworkspace/contents.xcworkspacedata

@ -5,6 +5,9 @@
location = "container:Tusker.xcodeproj">
</FileRef>
<FileRef
location = "group:BlankSlate.xcappdata">
</FileRef>
<FileRef
location = "group:Cache/Cache.xcodeproj">
</FileRef>
<FileRef
@ -13,4 +16,10 @@
<FileRef
location = "group:Gifu/Gifu.xcodeproj">
</FileRef>
<FileRef
location = "group:Embassy/Embassy.xcodeproj">
</FileRef>
<FileRef
location = "group:Ambassador/Ambassador.xcodeproj">
</FileRef>
</Workspace>

11
Tusker/Info.plist

@ -2,6 +2,17 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
<key>NSUserActivityTypes</key>
<array>
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.show-timeline</string>

14
Tusker/LocalData.swift

@ -12,7 +12,15 @@ class LocalData {
static let shared = LocalData()
let defaults = UserDefaults()
let defaults: UserDefaults
private init() {
if ProcessInfo.processInfo.environment.keys.contains("UI_TESTING") {
defaults = UserDefaults(suiteName: "\(Bundle.main.bundleIdentifier!).uitesting")!
} else {
defaults = UserDefaults()
}
}
private let onboardingCompleteKey = "onboardingComplete"
var onboardingComplete: Bool {
@ -63,10 +71,6 @@ class LocalData {
defaults.set(newValue, forKey: accessTokenKey)
}
}
private init() {
}
}
extension Notification.Name {

9
Tusker/Screens/Onboarding/InstanceSelectorTableViewController.swift

@ -75,14 +75,7 @@ class InstanceSelectorTableViewController: UITableViewController {
}
private func updateSpecificInstance(domain: String) {
var components = URLComponents()
if domain.contains("://") {
let parts = domain.components(separatedBy: "://")
components.scheme = parts[0]
components.host = parts[1]
} else {
components.host = domain
}
var components = URLComponents(string: domain)!
if components.scheme != "https" && components.scheme != "http" {
components.scheme = "https"
}

7
Tusker/Views/Instance Cell/InstanceTableViewCell.xib

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14868" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14824"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15703"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
@ -53,6 +53,9 @@
</stackView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" text="Instance Description" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="aD6-LG-BWG" customClass="ContentLabel" customModule="Tusker" customModuleProvider="target">
<rect key="frame" x="0.0" y="26.5" width="200" height="20.5"/>
<accessibility key="accessibilityConfiguration">
<accessibilityTraits key="traits" staticText="YES" notEnabled="YES"/>
</accessibility>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>

38
TuskerUITests/OnboardingTests.swift

@ -0,0 +1,38 @@
//
// OnboardingTests.swift
// TuskerUITests
//
// Created by Shadowfacts on 12/21/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import XCTest
import Ambassador
class OnboardingTests: TuskerUITests {
override func setUp() {
super.setUp()
router["/api/v1/instance"] = JSONResponse(handler: { (_) in
return [
"description": "An instance description",
"max_toot_chars": 500,
"thumbnail": "http://localhost:8080/thumbnail.png",
"title": "Localhost",
"uri": "http://localhost:8080",
"version": "2.7.2",
"urls": [:]
]
})
}
func testExample() {
let searchField = app.searchFields.element
searchField.tap()
searchField.typeText("http://localhost:8080")
XCTAssertTrue(app.staticTexts["localhost"].exists)
XCTAssertTrue(app.staticTexts["An instance description"].exists)
}
}

58
TuskerUITests/TuskerUITests.swift

@ -7,28 +7,56 @@
//
import XCTest
import Embassy
import Ambassador
class TuskerUITests: XCTestCase {
var eventLoop: EventLoop!
var router: Router!
var server: HTTPServer!
var eventLoopThreadCondition: NSCondition!
var eventLoopThread: Thread!
var app: XCUIApplication!
private func setupWebServer() {
eventLoop = try! SelectorEventLoop(selector: try! KqueueSelector())
router = Router()
server = DefaultHTTPServer(eventLoop: eventLoop, port: 8080, app: router.app)
router["/hello"] = JSONResponse(handler: { (_) in
return ["Hello", "World"]
})
try! server.start()
eventLoopThreadCondition = NSCondition()
eventLoopThread = Thread(block: {
self.eventLoop.runForever()
self.eventLoopThreadCondition.lock()
self.eventLoopThreadCondition.signal()
self.eventLoopThreadCondition.unlock()
})
eventLoopThread.start()
}
override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.
// In UI tests it is usually best to stop immediately when a failure occurs.
setupWebServer()
continueAfterFailure = false
// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
XCUIApplication().launch()
// In UI tests its important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
app = XCUIApplication()
app.launchEnvironment["UI_TESTING"] = "true"
app.launch()
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testExample() {
// Use recording to get started writing UI tests.
// Use XCTAssert and related functions to verify your tests produce the correct results.
server.stopAndWait()
eventLoopThreadCondition.lock()
eventLoop.stop()
while eventLoop.running {
if !eventLoopThreadCondition.wait(until: Date(timeIntervalSinceNow: 10)) {
fatalError("Join eventLoopThread timeout")
}
}
}
}

Loading…
Cancel
Save