Skip to content

Commit

Permalink
PAI-97 Add "Application Is Running Inside a UI Test Environment"
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartosz Janda committed Jun 29, 2017
1 parent 6574184 commit 61d5d8a
Show file tree
Hide file tree
Showing 39 changed files with 995 additions and 29 deletions.
1 change: 1 addition & 0 deletions .jazzy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ custom_categories:
children:
- LaunchEnvironmentManager
- AnimationHandler
- IsInUITestHandler
- ContactsHandler
- EventKitHandler
- Handler
Expand Down
12 changes: 12 additions & 0 deletions AutoMate-AppBuddy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
96D1FA1A1E4C84B100257883 /* FoundationExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D1FA191E4C84B100257883 /* FoundationExtensionsTests.swift */; };
96EA13041E5DBEED001DE308 /* ContactsParsers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96EA13031E5DBEED001DE308 /* ContactsParsers.swift */; };
96EA13061E5DC26E001DE308 /* contacts.json in Resources */ = {isa = PBXBuildFile; fileRef = 96EA13051E5DC26E001DE308 /* contacts.json */; };
96F1A7571F05023200EDCD14 /* IsInUITestHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F1A7561F05023200EDCD14 /* IsInUITestHandler.swift */; };
96F1A7581F05023200EDCD14 /* IsInUITestHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F1A7561F05023200EDCD14 /* IsInUITestHandler.swift */; };
96F1A7591F05023300EDCD14 /* IsInUITestHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F1A7561F05023200EDCD14 /* IsInUITestHandler.swift */; };
96F1A75C1F050C3F00EDCD14 /* IsInUITestHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F1A75B1F050C3F00EDCD14 /* IsInUITestHandlerTests.swift */; };
96F4608D1EFD104C00AE05A2 /* Either.swift in Sources */ = {isa = PBXBuildFile; fileRef = 968837D31E5DA1FF00ED7CF0 /* Either.swift */; };
96F4608E1EFD104C00AE05A2 /* Either.swift in Sources */ = {isa = PBXBuildFile; fileRef = 968837D31E5DA1FF00ED7CF0 /* Either.swift */; };
96F460931EFD107C00AE05A2 /* Bundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = E442564A1E3B7B7200B2D83B /* Bundle.swift */; };
Expand Down Expand Up @@ -122,6 +126,8 @@
96EA13031E5DBEED001DE308 /* ContactsParsers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactsParsers.swift; sourceTree = "<group>"; };
96EA13051E5DC26E001DE308 /* contacts.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = contacts.json; sourceTree = "<group>"; };
96EA13071E5DC3DC001DE308 /* ContactsHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactsHandler.swift; sourceTree = "<group>"; };
96F1A7561F05023200EDCD14 /* IsInUITestHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IsInUITestHandler.swift; sourceTree = "<group>"; };
96F1A75B1F050C3F00EDCD14 /* IsInUITestHandlerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IsInUITestHandlerTests.swift; sourceTree = "<group>"; };
96F555141EFD091500393409 /* AutoMate_AppBuddy.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AutoMate_AppBuddy.framework; sourceTree = BUILT_PRODUCTS_DIR; };
96F555221EFD0C9700393409 /* AutoMate_AppBuddy.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AutoMate_AppBuddy.framework; sourceTree = BUILT_PRODUCTS_DIR; };
E40226591E68191A007D15AB /* ContactsInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactsInterface.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -219,6 +225,7 @@
E40226591E68191A007D15AB /* ContactsInterface.swift */,
E46B79AA1E28F3D800BC36B4 /* EventKitHandler.swift */,
E4D4E04D1E66B4F0006AE3B7 /* EventKitInterface.swift */,
96F1A7561F05023200EDCD14 /* IsInUITestHandler.swift */,
E4932BB01E2E40A000FB8244 /* LaunchEnvironmentManager.swift */,
);
name = Managers;
Expand Down Expand Up @@ -319,6 +326,7 @@
E4611C861E76810C0039433F /* EventKitHandlerTests.swift */,
E49E84881E4B43DF008A13AE /* EventKitParserTests.swift */,
96D1FA191E4C84B100257883 /* FoundationExtensionsTests.swift */,
96F1A75B1F050C3F00EDCD14 /* IsInUITestHandlerTests.swift */,
E49E848A1E4B43DF008A13AE /* LaunchEnvironmentManagerTests.swift */,
E49E84891E4B43DF008A13AE /* LaunchEnvironmentResourceTests.swift */,
);
Expand Down Expand Up @@ -595,6 +603,7 @@
96F460A61EFD10CD00AE05A2 /* EventKit+Parsers.swift in Sources */,
96F460951EFD107C00AE05A2 /* DateComponents.swift in Sources */,
96F460AA1EFD10D800AE05A2 /* Contacts+Parsers.swift in Sources */,
96F1A7581F05023200EDCD14 /* IsInUITestHandler.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -623,6 +632,7 @@
96F460A81EFD10CD00AE05A2 /* EventKit+Parsers.swift in Sources */,
96F4609A1EFD107C00AE05A2 /* DateComponents.swift in Sources */,
96F460AC1EFD10D900AE05A2 /* Contacts+Parsers.swift in Sources */,
96F1A7591F05023300EDCD14 /* IsInUITestHandler.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -651,6 +661,7 @@
E42C2FA31E52FAAF000F1D7C /* EKReccurrence+Parsers.swift in Sources */,
968837D21E5D9E3100ED7CF0 /* Contacts+CNLabelValues.swift in Sources */,
96AB73F51E44C83300FA811A /* AnimationHandler.swift in Sources */,
96F1A7571F05023200EDCD14 /* IsInUITestHandler.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -663,6 +674,7 @@
E49E84911E4B43DF008A13AE /* LaunchEnvironmentResourceTests.swift in Sources */,
96EA13041E5DBEED001DE308 /* ContactsParsers.swift in Sources */,
E42C2FAB1E5441F3000F1D7C /* EKRecurrence.swift in Sources */,
96F1A75C1F050C3F00EDCD14 /* IsInUITestHandlerTests.swift in Sources */,
9606D1651E55E26500FC5130 /* ContactsParserTests.swift in Sources */,
E49E84901E4B43DF008A13AE /* EventKitParserTests.swift in Sources */,
E49E848E1E4B43DF008A13AE /* Handlers.swift in Sources */,
Expand Down
6 changes: 6 additions & 0 deletions AutoMate-AppBuddy/ContactsHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import Contacts
/// ```
///
/// - note:
/// `defaultContactsHander` singleton could be used intead of creating new instance of the `ContactsHandler`.
///
/// - note:
/// Launch environment for the handler can be set by the `ContactLaunchEnvironment`
/// from the [AutoMate](https://github.com/PGSSoft/AutoMate) project.
///
Expand All @@ -38,6 +41,7 @@ import Contacts
///
/// - seealso: `LaunchEnvironmentManager`
/// - seealso: `LaunchEnvironmentResource`
/// - seealso: `defaultContactsHander`
public struct ContactsHandler<C: ContactParser, I: ContactsInterface>: Handler
where C.T == Any,
C.U == CNMutableContact {
Expand Down Expand Up @@ -100,6 +104,8 @@ public struct ContactsHandler<C: ContactParser, I: ContactsInterface>: Handler
/// launchManager.add(handler: defaultContactsHander, for: .contacts)
/// launchManager.setup()
/// ```
///
/// - seealso: `ContactsHandler`
public let defaultContactsHander = ContactsHandler(withParser: ContactDictionaryParser(with: CNContactStore()), contactsInterface: ContactsInterface())

#endif
6 changes: 6 additions & 0 deletions AutoMate-AppBuddy/EventKitHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import EventKit
/// ```
///
/// - note:
/// `defaultEventKitHander` singleton could be used intead of creating new instance of the `EventKitHandler`.
///
/// - note:
/// Launch environment for the handler can be set by the `EventLaunchEnvironment`
/// and `ReminderLaunchEnvironment` from the [AutoMate](https://github.com/PGSSoft/AutoMate) project.
///
Expand All @@ -39,6 +42,7 @@ import EventKit
///
/// - seealso: `LaunchEnvironmentManager`
/// - seealso: `LaunchEnvironmentResource`
/// - seealso: `defaultEventKitHander`
public class EventKitHandler<E: EventParser, R: ReminderParser, I: EventKitInterfaceProtocol>: Handler
where E.T == [String: Any],
R.T == [String: Any],
Expand Down Expand Up @@ -165,6 +169,8 @@ public typealias DefaultEventKitHander = EventKitHandler<EventDictionaryParser,
/// launchManager.add(handler: defaultEventKitHander, for: .reminders)
/// launchManager.setup()
/// ```
///
/// - seealso: `EventKitHandler`
public let defaultEventKitHander: DefaultEventKitHander = EventKitHandler(withParsers: EventDictionaryParser(), ReminderDictionaryParser(),
eventKitInterface: EventKitInterface())

Expand Down
110 changes: 110 additions & 0 deletions AutoMate-AppBuddy/IsInUITestHandler.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//
// IsInUITestHandler.swift
// AutoMate-AppBuddy
//
// Created by Bartosz Janda (PGS Software) on 29.06.2017.
// Copyright © 2017 PGS Software. All rights reserved.
//

import Foundation

// MARK: - IsInUITestHandler
/// Provides information whether the application is running under UI test environment.
///
/// Handler should be added to `LaunchEnvironmentManager`.
///
/// Used key: `AM_IS_IN_UI_TEST` / `AutoMateLaunchOptionKey.isInUITest`.
///
/// Supported values (case insensitive):
///
/// - `true`
/// - `yes`
/// - `1`
/// - `false`
/// - `no`
/// - `0`
///
/// **Example:**
///
/// ```swift
/// let launchManager = LaunchEnvironmentManager()
/// let isInUITest = IsInUITestHandler()
/// launchManager.add(handler: isInUITest, for: .isInUITest)
/// launchManager.setup()
/// ```
///
/// Later in the code, you can check whether the application is running in UI test environment, by using below example:
///
/// **Example:**
///
/// ```swift
/// if isInUITest.inUITest {
/// ...
/// }
/// ```
///
/// - note:
/// `defaultIsInUITestHandler` singleton could be used intead of creating new instance of the `IsInUITestHandler`.
///
/// - note:
/// Launch environment for the handler can be set by the `IsInUITestLaunchEnvironment`
/// from the [AutoMate](https://github.com/PGSSoft/AutoMate) project.
///
/// - note:
/// `IsInUITestHandler` should be used with the `AM_IS_IN_UI_TEST` key, but its implementation doesn't require to use it.
/// Any key provided to the `LaunchEnvironmentManager.add(handler:for:)` method will be handled correctly.
///
/// - seealso: `LaunchEnvironmentManager`
/// - seealso: `defaultIsInUITestHandler`
public class IsInUITestHandler: Handler {

// MARK: Properties
/// Indicates whether the application is running in UI test environment.
private(set) public var inUITest: Bool = false

// MARK: Initialization
/// Initialize `IsInUITestHandler`.
public init() { }

// MARK: Handler
/// Handles value for the `AM_IS_IN_UI_TEST` key and provides information whether the application was run in the UI test environment.
///
/// - note:
/// `IsInUITestHandler` should be used with the `AM_IS_IN_UI_TEST` key, but its implementation doesn't require to use it.
/// Any key provided to the `LaunchEnvironmentManager.add(handler:for:)` method will be handled correctly.
///
/// - requires:
/// Method support only given set of values (case insensitive):
///
/// - `true`
/// - `yes`
/// - `1`
/// - `false`
/// - `no`
/// - `0`
///
/// - Parameters:
/// - key: `AM_IS_IN_UI_TEST` / `AutoMateLaunchOptionKey.isInUITest`
/// - value: Value for the `key`.
public func handle(key: String, value: String) {
guard let inUITest = value.boolValue else {
assertionFailure("Cannot convert value for key \"\(key)\" to Bool")
return
}

self.inUITest = inUITest
}
}

// MARK: - Default IsInUITestHandler
/// Default `IsInUITestHandler` instance. Singleton which will store information whether the application is running in UI test environment.
///
/// **Example:**
/// ```swift
/// let launchManager = LaunchEnvironmentManager()
/// launchManager.add(handler: defaultIsInUITestHandler, for: .isInUITest)
/// launchManager.setup()
/// ```
///
/// - seealso: `IsInUITestHandler`
public let defaultIsInUITestHandler = IsInUITestHandler()
1 change: 1 addition & 0 deletions AutoMate-AppBuddy/LaunchEnvironmentManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Foundation
/// launchManager.add(handler: defaultEventKitHander, for: .events)
/// launchManager.add(handler: defaultEventKitHander, for: .reminders)
/// launchManager.add(handler: defaultContactsHander, for: .contacts)
/// launchManager.add(handler: defaultIsInUITestHandler, for: .isInUITest)
/// launchManager.add(handler: AnimationHandler(), for: .animation)
/// launchManager.setup()
/// ```
Expand Down
4 changes: 4 additions & 0 deletions AutoMate-AppBuddy/LaunchOptionsKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Foundation
/// - `contacts`: Used to manage contacs by the `ContactsHandler`.
/// - `events`: Used to manage events by the `EventKitHandler`.
/// - `reminders`: Used to manage reminders by the `EventKitHandler`.
/// - `isInUITest`: Used to manege UI test environment information by the `IsInUITestHandler`.
public enum AutoMateLaunchOptionKey: LaunchOptionKey {

/// Used to enable / disable animation, used by the `AnimationHandler`.
Expand All @@ -29,4 +30,7 @@ public enum AutoMateLaunchOptionKey: LaunchOptionKey {

/// Used to manage reminders by the `EventKitHandler`.
case reminders = "AM_REMINDERS_KEY"

/// Used to manege UI test environment information by the `IsInUITestHandler`.
case isInUITest = "AM_IS_IN_UI_TEST"
}
39 changes: 39 additions & 0 deletions AutoMate-AppBuddyTests/Test Cases/IsInUITestHandlerTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// IsInUITestHandlerTests.swift
// AutoMate-AppBuddy
//
// Created by Bartosz Janda (PGS Software) on 29.06.2017.
// Copyright © 2017 PGS Software. All rights reserved.
//

import XCTest
import AutoMate_AppBuddy

class IsInUITestHandlerTests: XCTestCase {

// MARK: Properties
var isInUITestHandler: IsInUITestHandler!

// MARK: Setup
override func setUp() {
super.setUp()
isInUITestHandler = IsInUITestHandler()
UIView.setAnimationsEnabled(true)
}

override func tearDown() {
UIView.setAnimationsEnabled(true)
super.tearDown()
}

// MARK: Tests
func testInUiTest() {
isInUITestHandler.handle(key: AutoMateLaunchOptionKey.isInUITest.rawValue, value: "true")
XCTAssertTrue(isInUITestHandler.inUITest)
}

func testNotInUiTest() {
isInUITestHandler.handle(key: AutoMateLaunchOptionKey.isInUITest.rawValue, value: "false")
XCTAssertFalse(isInUITestHandler.inUITest)
}
}
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
docs:
jazzy -c
rsync -ahvL --delete "assets" "docs"
rm -r build

# Push master, develop and tags to GitHub
push_github:
Expand Down
8 changes: 7 additions & 1 deletion docs/Classes/ContactsInterface.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<li class="nav-group-task">
<a href="../Structs/AnimationHandler.html">AnimationHandler</a>
</li>
<li class="nav-group-task">
<a href="../Classes/IsInUITestHandler.html">IsInUITestHandler</a>
</li>
<li class="nav-group-task">
<a href="../Structs/ContactsHandler.html">ContactsHandler</a>
</li>
Expand Down Expand Up @@ -99,6 +102,9 @@
<li class="nav-group-task">
<a href="../Other Global Variables.html#/s:v17AutoMate_AppBuddy21defaultEventKitHanderGCS_15EventKitHandlerVS_21EventDictionaryParserVS_24ReminderDictionaryParserCS_17EventKitInterface_">defaultEventKitHander</a>
</li>
<li class="nav-group-task">
<a href="../Other Global Variables.html#/s:v17AutoMate_AppBuddy24defaultIsInUITestHandlerCS_17IsInUITestHandler">defaultIsInUITestHandler</a>
</li>
</ul>
</li>
<li class="nav-group-name">
Expand Down Expand Up @@ -391,7 +397,7 @@ <h4>Parameters</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2017 <a class="link" href="https://github.com/PGSSoft/AutoMate-AppBuddy" target="_blank" rel="external">Joanna Bednarz and Bartosz Janda</a>. All rights reserved. (Last updated: 2017-06-26)</p>
<p>&copy; 2017 <a class="link" href="https://github.com/PGSSoft/AutoMate-AppBuddy" target="_blank" rel="external">Joanna Bednarz and Bartosz Janda</a>. All rights reserved. (Last updated: 2017-06-29)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.8.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
18 changes: 17 additions & 1 deletion docs/Classes/EventKitHandler.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<li class="nav-group-task">
<a href="../Structs/AnimationHandler.html">AnimationHandler</a>
</li>
<li class="nav-group-task">
<a href="../Classes/IsInUITestHandler.html">IsInUITestHandler</a>
</li>
<li class="nav-group-task">
<a href="../Structs/ContactsHandler.html">ContactsHandler</a>
</li>
Expand Down Expand Up @@ -99,6 +102,9 @@
<li class="nav-group-task">
<a href="../Other Global Variables.html#/s:v17AutoMate_AppBuddy21defaultEventKitHanderGCS_15EventKitHandlerVS_21EventDictionaryParserVS_24ReminderDictionaryParserCS_17EventKitInterface_">defaultEventKitHander</a>
</li>
<li class="nav-group-task">
<a href="../Other Global Variables.html#/s:v17AutoMate_AppBuddy24defaultIsInUITestHandlerCS_17IsInUITestHandler">defaultIsInUITestHandler</a>
</li>
</ul>
</li>
<li class="nav-group-name">
Expand Down Expand Up @@ -163,6 +169,11 @@ <h1>EventKitHandler</h1>
<span class="n">launchManager</span><span class="o">.</span><span class="nf">add</span><span class="p">(</span><span class="nv">handler</span><span class="p">:</span> <span class="n">eventsHander</span><span class="p">,</span> <span class="nv">for</span><span class="p">:</span> <span class="o">.</span><span class="n">reminders</span><span class="p">)</span>
<span class="n">launchManager</span><span class="o">.</span><span class="nf">setup</span><span class="p">()</span>
</code></pre>
<div class="aside aside-note">
<p class="aside-title">Note</p>
<p><code><a href="../Other Global Variables.html#/s:v17AutoMate_AppBuddy21defaultEventKitHanderGCS_15EventKitHandlerVS_21EventDictionaryParserVS_24ReminderDictionaryParserCS_17EventKitInterface_">defaultEventKitHander</a></code> singleton could be used intead of creating new instance of the <code>EventKitHandler</code>.</p>

</div>
<div class="aside aside-note">
<p class="aside-title">Note</p>
<p>Launch environment for the handler can be set by the <code>EventLaunchEnvironment</code>
Expand All @@ -184,6 +195,11 @@ <h1>EventKitHandler</h1>
<p class="aside-title">Seealso</p>
<p><code><a href="../Structs/LaunchEnvironmentResource.html">LaunchEnvironmentResource</a></code></p>

</div>
<div class="aside aside-seealso">
<p class="aside-title">Seealso</p>
<p><code><a href="../Other Global Variables.html#/s:v17AutoMate_AppBuddy21defaultEventKitHanderGCS_15EventKitHandlerVS_21EventDictionaryParserVS_24ReminderDictionaryParserCS_17EventKitInterface_">defaultEventKitHander</a></code></p>

</div>

</section>
Expand Down Expand Up @@ -466,7 +482,7 @@ <h4>Parameters</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2017 <a class="link" href="https://github.com/PGSSoft/AutoMate-AppBuddy" target="_blank" rel="external">Joanna Bednarz and Bartosz Janda</a>. All rights reserved. (Last updated: 2017-06-26)</p>
<p>&copy; 2017 <a class="link" href="https://github.com/PGSSoft/AutoMate-AppBuddy" target="_blank" rel="external">Joanna Bednarz and Bartosz Janda</a>. All rights reserved. (Last updated: 2017-06-29)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.8.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
Loading

0 comments on commit 61d5d8a

Please sign in to comment.