Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding ability to enable/disable autocorrect/smart quotes/smart dashes
- Loading branch information
Harley Cooper
committed
Feb 8, 2018
1 parent
168c9e9
commit 37c3f44
Showing
11 changed files
with
327 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// KIFTextInputTraitsOverrides.h | ||
// KIF | ||
// | ||
// Created by Harley Cooper on 1/31/18. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
FOUNDATION_EXTERN void KIFSetAutocorrect(BOOL); | ||
FOUNDATION_EXTERN void KIFSetSmartQuotes(BOOL); | ||
FOUNDATION_EXTERN void KIFSetSmartDashes(BOOL); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// | ||
// KIFTextInputTraitsOverrides.m | ||
// KIF | ||
// | ||
// Created by Harley Cooper on 1/31/18. | ||
// | ||
|
||
#import <objc/runtime.h> | ||
#import "KIFTextInputTraitsOverrides.h" | ||
|
||
static IMP autocorrectOriginalImp; | ||
static IMP smartDashesOriginalImp; | ||
static IMP smartQuotesOriginalImp; | ||
|
||
void KIFSetAutocorrect(BOOL setAutocorrectOn) { | ||
if(!autocorrectOriginalImp) { | ||
autocorrectOriginalImp = class_getMethodImplementation([UITextField class], @selector(autocorrectionType)); | ||
} | ||
|
||
IMP autocorrectImp; | ||
if(setAutocorrectOn) { | ||
autocorrectImp = autocorrectOriginalImp; | ||
} else if(!setAutocorrectOn) { | ||
autocorrectImp = imp_implementationWithBlock(^(UITextField *_self) { | ||
return UITextAutocorrectionTypeNo; | ||
}); | ||
} | ||
struct objc_method_description autocorrectionTypeMethodDescription = protocol_getMethodDescription(@protocol(UITextInputTraits), @selector(autocorrectionType), NO, YES); | ||
class_replaceMethod([UITextField class], @selector(autocorrectionType), autocorrectImp, autocorrectionTypeMethodDescription.types); | ||
} | ||
|
||
void KIFSetSmartDashes(BOOL setSmartDashesOn) { | ||
// This #ifdef is necessary for versions of Xcode before Xcode 9. | ||
#ifdef __IPHONE_11_0 | ||
if (@available(iOS 11.0, *)) { | ||
if(!smartDashesOriginalImp) { | ||
smartDashesOriginalImp = class_getMethodImplementation([UITextField class], @selector(smartDashesType)); | ||
} | ||
|
||
IMP smartDashesImp; | ||
if(setSmartDashesOn) { | ||
smartDashesImp = smartDashesOriginalImp; | ||
} else if(!setSmartDashesOn) { | ||
smartDashesImp = imp_implementationWithBlock(^(UITextField *_self) { | ||
return UITextSmartDashesTypeNo; | ||
}); | ||
} | ||
struct objc_method_description smartDashesTypeMethodDescription = protocol_getMethodDescription(@protocol(UITextInputTraits), @selector(smartDashesType), NO, YES); | ||
class_replaceMethod([UITextField class], @selector(smartDashesType), smartDashesImp, smartDashesTypeMethodDescription.types); | ||
} | ||
#endif | ||
} | ||
|
||
void KIFSetSmartQuotes(BOOL setSmartQuotesOn) { | ||
// This #ifdef is necessary for versions of Xcode before Xcode 9. | ||
#ifdef __IPHONE_11_0 | ||
if (@available(iOS 11.0, *)) { | ||
if(!smartQuotesOriginalImp) { | ||
smartQuotesOriginalImp = class_getMethodImplementation([UITextField class], @selector(smartQuotesType)); | ||
} | ||
|
||
IMP smartQuotesImp; | ||
if(setSmartQuotesOn) { | ||
smartQuotesImp = smartQuotesOriginalImp; | ||
} else if(!setSmartQuotesOn) { | ||
smartQuotesImp = imp_implementationWithBlock(^(UITextField *_self) { | ||
return UITextSmartQuotesTypeNo; | ||
}); | ||
} | ||
struct objc_method_description smartQuotesMethodDescription = protocol_getMethodDescription(@protocol(UITextInputTraits), @selector(smartQuotesType), NO, YES); | ||
class_replaceMethod([UITextField class], @selector(smartQuotesType), smartQuotesImp, smartQuotesMethodDescription.types); | ||
} | ||
#endif | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// AutocorrectTests.m | ||
// KIF Tests | ||
// | ||
// Created by Harley Cooper on 2/7/18. | ||
// | ||
|
||
#import <KIF/KIF.h> | ||
|
||
@interface AutocorrectTests : KIFTestCase | ||
@end | ||
|
||
@implementation AutocorrectTests | ||
|
||
+ (void)setUp | ||
{ | ||
[KIFTestActor setEnableAutocorrect:YES]; | ||
[KIFTestActor setEnableSmartQuotes:YES]; | ||
[KIFTestActor setEnableSmartDashes:YES]; | ||
[super setUp]; | ||
} | ||
|
||
+ (void)tearDown | ||
{ | ||
[KIFTestActor setEnableAutocorrect:NO]; | ||
[KIFTestActor setEnableSmartQuotes:NO]; | ||
[KIFTestActor setEnableSmartDashes:NO]; | ||
[super tearDown]; | ||
} | ||
|
||
- (void)beforeEach | ||
{ | ||
[tester tapViewWithAccessibilityLabel:@"Tapping"]; | ||
} | ||
|
||
- (void)afterEach | ||
{ | ||
[tester tapViewWithAccessibilityLabel:@"Test Suite" traits:UIAccessibilityTraitButton]; | ||
} | ||
|
||
- (void)testClearingAndEnteringTypoIntoViewWithAccessibilityLabel | ||
{ | ||
[[tester validateEnteredText:NO] clearTextFromAndThenEnterText:@" teh " intoViewWithAccessibilityLabel:@"Greeting"]; | ||
[[viewTester usingValue:@" teh "] waitForAbsenceOfView]; | ||
} | ||
|
||
- (void)testClearingAndEnteringQuotesIntoViewWithAccessibilityLabel | ||
{ | ||
[tester clearTextFromAndThenEnterText:@"'\"'," intoViewWithAccessibilityLabel:@"Greeting" traits:UIAccessibilityTraitNone expectedResult:@"’”’,"]; | ||
} | ||
|
||
- (void)testClearingAndEnteringDashesIntoViewWithAccessibilityLabel | ||
{ | ||
[tester clearTextFromAndThenEnterText:@"--a" intoViewWithAccessibilityLabel:@"Greeting" traits:UIAccessibilityTraitNone expectedResult:@"—a"]; | ||
} | ||
|
||
@end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// AutocorrectTests_ViewTestActor.m | ||
// KIF Tests | ||
// | ||
// Created by Harley Cooper on 2/7/18. | ||
// | ||
|
||
#import <KIF/KIF.h> | ||
|
||
@interface AutocorrectTests_ViewTestActor : KIFTestCase | ||
@end | ||
|
||
|
||
@implementation AutocorrectTests_ViewTestActor | ||
|
||
+ (void)setUp | ||
{ | ||
[KIFTestActor setEnableAutocorrect:YES]; | ||
[KIFTestActor setEnableSmartQuotes:YES]; | ||
[KIFTestActor setEnableSmartDashes:YES]; | ||
[super setUp]; | ||
} | ||
|
||
+ (void)tearDown | ||
{ | ||
[KIFTestActor setEnableAutocorrect:NO]; | ||
[KIFTestActor setEnableSmartQuotes:NO]; | ||
[KIFTestActor setEnableSmartDashes:NO]; | ||
[super tearDown]; | ||
} | ||
|
||
- (void)beforeEach | ||
{ | ||
[[viewTester usingLabel:@"Tapping"] tap]; | ||
} | ||
|
||
- (void)afterEach | ||
{ | ||
[[[viewTester usingLabel:@"Test Suite"] usingTraits:UIAccessibilityTraitButton] tap]; | ||
} | ||
|
||
- (void)testClearingAndEnteringTypoIntoViewWithAccessibilityLabel | ||
{ | ||
[[[viewTester validateEnteredText:NO] usingLabel:@"Greeting"] clearAndEnterText:@" teh "]; | ||
[[viewTester usingValue:@" teh "] waitForAbsenceOfView]; | ||
} | ||
|
||
- (void)testClearingAndEnteringQuotesIntoViewWithAccessibilityLabel | ||
{ | ||
[[viewTester usingLabel:@"Greeting"] clearAndEnterText:@"'\"'," expectedResult:@"’”’,"]; | ||
} | ||
|
||
- (void)testClearingAndEnteringDashesIntoViewWithAccessibilityLabel | ||
{ | ||
[[viewTester usingLabel:@"Greeting"] clearAndEnterText:@"--a" expectedResult:@"—a"]; | ||
} | ||
|
||
|
||
@end | ||
|
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
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
Oops, something went wrong.