-
-
Save nheagy/5b6f751bb37db74645fd6bc880bf0ee4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/WordPress/Classes/Utility/WPFeedbackGenerators.swift b/WordPress/Classes/Utility/WPFeedbackGenerators.swift | |
index 04a9ac9..228c9d2 100644 | |
--- a/WordPress/Classes/Utility/WPFeedbackGenerators.swift | |
+++ b/WordPress/Classes/Utility/WPFeedbackGenerators.swift | |
@@ -28,7 +28,11 @@ class WPNotificationFeedbackGenerator: NSObject { | |
return | |
} | |
- let generator = UINotificationFeedbackGenerator() | |
+ notificationOccurred(notificationType, withGenerator: UINotificationFeedbackGenerator()) | |
+ } | |
+ | |
+ @available(iOS 10, *) | |
+ internal class func notificationOccurred(notificationType: WPNotificationFeedbackType, withGenerator generator: UINotificationFeedbackGenerator) { | |
generator.notificationOccurred(notificationType.systemFeedbackType) | |
} | |
} | |
@@ -63,13 +67,16 @@ class WPImpactFeedbackGenerator: NSObject { | |
super.init() | |
} | |
- /// call when your UI element impacts something else | |
func impactOccurred() { | |
guard #available(iOS 10, *) else { | |
return | |
} | |
- let generator = UIImpactFeedbackGenerator(style: style.systemFeedbackStyle) | |
+ impactOccurredWithGenerator(UIImpactFeedbackGenerator(style: style.systemFeedbackStyle)) | |
+ } | |
+ | |
+ @available(iOS 10, *) | |
+ internal func impactOccurredWithGenerator(generator: UIImpactFeedbackGenerator) { | |
generator.impactOccurred() | |
} | |
} | |
diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj | |
index 0f6fa18..b866064 100644 | |
--- a/WordPress/WordPress.xcodeproj/project.pbxproj | |
+++ b/WordPress/WordPress.xcodeproj/project.pbxproj | |
@@ -104,9 +104,11 @@ | |
173BCE751CEB369900AE8817 /* Domains.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 173BCE741CEB369900AE8817 /* Domains.storyboard */; }; | |
173BCE771CEB3D8200AE8817 /* DomainsServiceRemote.swift in Sources */ = {isa = PBXBuildFile; fileRef = 173BCE761CEB3D8200AE8817 /* DomainsServiceRemote.swift */; }; | |
173BCE791CEB780800AE8817 /* Domain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 173BCE781CEB780800AE8817 /* Domain.swift */; }; | |
+ 173CE3921DAE3F6B00875CD2 /* WPFeedbackGeneratorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 173CE3911DAE3F6B00875CD2 /* WPFeedbackGeneratorTests.m */; }; | |
1746D7771D2165AE00B11D77 /* ForcePopoverPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1746D7761D2165AE00B11D77 /* ForcePopoverPresenter.swift */; }; | |
1751E5911CE0E552000CA08D /* KeyValueDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1751E5901CE0E552000CA08D /* KeyValueDatabase.swift */; }; | |
1751E5931CE23801000CA08D /* NSAttributedString+StyledHTML.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1751E5921CE23801000CA08D /* NSAttributedString+StyledHTML.swift */; }; | |
+ 175DBCD61DAE41A6003CBFBE /* WPFeedbackGeneratorMappingTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 175DBCD51DAE41A6003CBFBE /* WPFeedbackGeneratorMappingTest.swift */; }; | |
176579F71C63A40F0000978E /* PurchaseButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 176579F61C63A40F0000978E /* PurchaseButton.swift */; }; | |
1767494E1D3633A000B8D1D1 /* ThemeBrowserSearchHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1767494D1D3633A000B8D1D1 /* ThemeBrowserSearchHeaderView.swift */; }; | |
178EDE701C74CE7F008C5C14 /* PlanPostPurchaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 178EDE6F1C74CE7F008C5C14 /* PlanPostPurchaseViewController.swift */; }; | |
@@ -1096,9 +1098,11 @@ | |
173BCE741CEB369900AE8817 /* Domains.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Domains.storyboard; sourceTree = "<group>"; }; | |
173BCE761CEB3D8200AE8817 /* DomainsServiceRemote.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DomainsServiceRemote.swift; sourceTree = "<group>"; }; | |
173BCE781CEB780800AE8817 /* Domain.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Domain.swift; sourceTree = "<group>"; }; | |
+ 173CE3911DAE3F6B00875CD2 /* WPFeedbackGeneratorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WPFeedbackGeneratorTests.m; sourceTree = "<group>"; }; | |
1746D7761D2165AE00B11D77 /* ForcePopoverPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForcePopoverPresenter.swift; sourceTree = "<group>"; }; | |
1751E5901CE0E552000CA08D /* KeyValueDatabase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyValueDatabase.swift; sourceTree = "<group>"; }; | |
1751E5921CE23801000CA08D /* NSAttributedString+StyledHTML.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSAttributedString+StyledHTML.swift"; sourceTree = "<group>"; }; | |
+ 175DBCD51DAE41A6003CBFBE /* WPFeedbackGeneratorMappingTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WPFeedbackGeneratorMappingTest.swift; sourceTree = "<group>"; }; | |
176579F61C63A40F0000978E /* PurchaseButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PurchaseButton.swift; sourceTree = "<group>"; }; | |
1767494D1D3633A000B8D1D1 /* ThemeBrowserSearchHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ThemeBrowserSearchHeaderView.swift; sourceTree = "<group>"; }; | |
178EDE6F1C74CE7F008C5C14 /* PlanPostPurchaseViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = PlanPostPurchaseViewController.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; | |
@@ -3277,6 +3281,8 @@ | |
E1E1AA8E1B7DF54B001C8645 /* WPMapFilterReduceTest.m */, | |
E19A10C91B010AA0006192B0 /* WPURLRequestTest.m */, | |
5981FE041AB8A89A0009E080 /* WPUserAgentTests.m */, | |
+ 173CE3911DAE3F6B00875CD2 /* WPFeedbackGeneratorTests.m */, | |
+ 175DBCD51DAE41A6003CBFBE /* WPFeedbackGeneratorMappingTest.swift */, | |
); | |
name = Utility; | |
sourceTree = "<group>"; | |
@@ -6343,6 +6349,7 @@ | |
59FBD5621B5684F300734466 /* ThemeServiceTests.m in Sources */, | |
85F8E19D1B018698000859BB /* PushAuthenticationServiceTests.swift in Sources */, | |
931D270019EDAE8600114F17 /* CoreDataMigrationTests.m in Sources */, | |
+ 173CE3921DAE3F6B00875CD2 /* WPFeedbackGeneratorTests.m in Sources */, | |
E6B9B8AA1B94E1FE0001B92F /* ReaderPostTest.m in Sources */, | |
85D790AC1AE5D95E0033AE83 /* MixpanelProxyTests.m in Sources */, | |
931D26F619ED7F7000114F17 /* BlogServiceTest.m in Sources */, | |
@@ -6351,6 +6358,7 @@ | |
B5882C471D5297D1008E0EAA /* NotificationTests.swift in Sources */, | |
E15618FD16DB8677006532C4 /* UIKitTestHelper.m in Sources */, | |
5960967F1CF7959300848496 /* PostTests.swift in Sources */, | |
+ 175DBCD61DAE41A6003CBFBE /* WPFeedbackGeneratorMappingTest.swift in Sources */, | |
E124CE721C86D27100F7BA99 /* StoreTests.swift in Sources */, | |
B5744A1E1C3D8FA700A3B8DC /* InteractiveNotificationsHandlerTests.m in Sources */, | |
B5EFB1C91B333C5A007608A3 /* NotificationSettingsServiceTests.swift in Sources */, | |
diff --git a/WordPress/WordPressTest/WPFeedbackGeneratorMappingTest.swift b/WordPress/WordPressTest/WPFeedbackGeneratorMappingTest.swift | |
index 9248adb..c395d15 100644 | |
--- a/WordPress/WordPressTest/WPFeedbackGeneratorMappingTest.swift | |
+++ b/WordPress/WordPressTest/WPFeedbackGeneratorMappingTest.swift | |
@@ -1,9 +1,27 @@ | |
-// | |
-// WPFeedbackGeneratorMappingTest.swift | |
-// WordPress | |
-// | |
-// Created by James Frost on 12/10/2016. | |
-// Copyright © 2016 WordPress. All rights reserved. | |
-// | |
- | |
-import Foundation | |
+import XCTest | |
+@testable import WordPress | |
+ | |
+@available(iOS 10, *) | |
+class WPFeedbackGeneratorMappingTest: XCTestCase { | |
+ func testNotificationFeedbackGeneratorMapping() { | |
+ let successType = WPNotificationFeedbackType.Success | |
+ XCTAssertEqual(successType.rawValue, successType.systemFeedbackType.rawValue) | |
+ | |
+ let warningType = WPNotificationFeedbackType.Warning | |
+ XCTAssertEqual(warningType.rawValue, warningType.systemFeedbackType.rawValue) | |
+ | |
+ let errorType = WPNotificationFeedbackType.Error | |
+ XCTAssertEqual(errorType.rawValue, errorType.systemFeedbackType.rawValue) | |
+ } | |
+ | |
+ func testImpactFeedbackGeneratorMapping() { | |
+ let lightStyle = WPImpactFeedbackStyle.Light | |
+ XCTAssertEqual(lightStyle.rawValue, lightStyle.systemFeedbackStyle.rawValue) | |
+ | |
+ let mediumStyle = WPImpactFeedbackStyle.Medium | |
+ XCTAssertEqual(mediumStyle.rawValue, mediumStyle.systemFeedbackStyle.rawValue) | |
+ | |
+ let heavyStyle = WPImpactFeedbackStyle.Heavy | |
+ XCTAssertEqual(heavyStyle.rawValue, heavyStyle.systemFeedbackStyle.rawValue) | |
+ } | |
+} | |
diff --git a/WordPress/WordPressTest/WPFeedbackGeneratorTests.m b/WordPress/WordPressTest/WPFeedbackGeneratorTests.m | |
index 15ddfa5..32ad4de 100644 | |
--- a/WordPress/WordPressTest/WPFeedbackGeneratorTests.m | |
+++ b/WordPress/WordPressTest/WPFeedbackGeneratorTests.m | |
@@ -1,9 +1,58 @@ | |
-// | |
-// WPFeedbackGeneratorTests.m | |
-// WordPress | |
-// | |
-// Created by James Frost on 12/10/2016. | |
-// Copyright © 2016 WordPress. All rights reserved. | |
-// | |
- | |
-#import <Foundation/Foundation.h> | |
+#import <XCTest/XCTest.h> | |
+#import <OCMock/OCMock.h> | |
+#import "WordPress-Swift.h" | |
+ | |
+ | |
+@interface WPFeedbackGeneratorTest : XCTestCase | |
+ | |
+@end | |
+ | |
+@implementation WPFeedbackGeneratorTest | |
+ | |
+- (void)setUp | |
+{ | |
+ [super setUp]; | |
+} | |
+ | |
+- (void)tearDown | |
+{ | |
+ [super tearDown]; | |
+} | |
+ | |
+- (void (^)(NSInvocation *))noopBlock | |
+{ | |
+ return ^(NSInvocation *invocation){}; | |
+} | |
+ | |
+- (void)testNotificationFeedbackTriggersTaptic | |
+{ | |
+ id generatorMock = OCMClassMock([UINotificationFeedbackGenerator class]); | |
+ | |
+ [WPNotificationFeedbackGenerator notificationOccurred:WPNotificationFeedbackTypeSuccess withGenerator:generatorMock]; | |
+ OCMVerify([generatorMock notificationOccurred:UINotificationFeedbackTypeSuccess]); | |
+ | |
+ [WPNotificationFeedbackGenerator notificationOccurred:WPNotificationFeedbackTypeWarning withGenerator:generatorMock]; | |
+ OCMVerify([generatorMock notificationOccurred:UINotificationFeedbackTypeWarning]); | |
+ | |
+ [WPNotificationFeedbackGenerator notificationOccurred:WPNotificationFeedbackTypeError withGenerator:generatorMock]; | |
+ OCMVerify([generatorMock notificationOccurred:UINotificationFeedbackTypeError]); | |
+} | |
+ | |
+- (void)testImpactFeedbackTriggersTaptic | |
+{ | |
+ UIImpactFeedbackGenerator *mockGenerator = OCMClassMock([UIImpactFeedbackGenerator class]); | |
+ | |
+ WPImpactFeedbackGenerator *lightGenerator =[[WPImpactFeedbackGenerator alloc] initWithStyle:WPImpactFeedbackStyleLight]; | |
+ [lightGenerator impactOccurredWithGenerator:mockGenerator]; | |
+ OCMVerify([mockGenerator impactOccurred]); | |
+ | |
+ WPImpactFeedbackGenerator *mediumGenerator =[[WPImpactFeedbackGenerator alloc] initWithStyle:WPImpactFeedbackStyleMedium]; | |
+ [mediumGenerator impactOccurredWithGenerator:mockGenerator]; | |
+ OCMVerify([mockGenerator impactOccurred]); | |
+ | |
+ WPImpactFeedbackGenerator *heavyGenerator =[[WPImpactFeedbackGenerator alloc] initWithStyle:WPImpactFeedbackStyleHeavy]; | |
+ [heavyGenerator impactOccurredWithGenerator:mockGenerator]; | |
+ OCMVerify([mockGenerator impactOccurred]); | |
+} | |
+ | |
+@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment