-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(iOS): Obj-C convenience accessors on CAPPluginCall (#4309)
- Loading branch information
Showing
6 changed files
with
136 additions
and
29 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
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,106 @@ | ||
#import <XCTest/XCTest.h> | ||
#import <Capacitor/Capacitor.h> | ||
#import <Capacitor/CAPBridgedJSTypes.h> | ||
// forward declaration of internal capacitor classes that are exposed in the swift header via the @testable import. | ||
@interface CAPWebViewAssetHandler: NSObject | ||
@end | ||
@interface CapacitorBridge: NSObject | ||
@end | ||
@interface CAPWebViewDelegationHandler: NSObject | ||
@end | ||
// import that will fail without the declarations | ||
#import "CapacitorTests-Swift.h" | ||
|
||
// interface for this class | ||
@interface PluginCallAccessorTests : XCTestCase | ||
@property (strong, nonatomic) CAPPluginCall* call; | ||
@end | ||
|
||
@implementation PluginCallAccessorTests | ||
|
||
- (void)setUp { | ||
[super setUp]; | ||
NSDate* date = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate:632854800]; | ||
NSISO8601DateFormatter *formatter = [[NSISO8601DateFormatter alloc] init]; | ||
NSDictionary* options = @{@"testString":@"foo", | ||
@"testDict": @{@"testSubkey":@"sub value"}, | ||
@"testFloat": @3.14159, | ||
@"testDateObject": date, | ||
@"testDateString": [formatter stringFromDate:date], | ||
@"testBoolTrue": @TRUE, | ||
@"testBoolFalse": @FALSE}; | ||
[self setCall:[[CAPPluginCall alloc] initWithCallbackId:@"test" options:options success:NULL error:NULL]]; | ||
} | ||
|
||
- (void)testStringAccessor { | ||
NSString* value = [[self call] getString:@"testString" defaultValue:NULL]; | ||
XCTAssertEqual(value, @"foo"); | ||
|
||
value = [[self call] getString:@"badString" defaultValue:NULL]; | ||
XCTAssertNil(value); | ||
|
||
value = [[self call] getString:@"badString" defaultValue:@"default"]; | ||
XCTAssertEqual(value, @"default"); | ||
} | ||
|
||
- (void)testDateObjectAccessor { | ||
NSDate* value = [[self call] getDate:@"testDateObject" defaultValue:NULL]; | ||
XCTAssertEqual([value timeIntervalSinceReferenceDate], 632854800); | ||
|
||
value = [[self call] getDate:@"badString" defaultValue:NULL]; | ||
XCTAssertNil(value); | ||
|
||
NSDate *defaultDate = [NSDate date]; | ||
value = [[self call] getDate:@"badString" defaultValue:defaultDate]; | ||
XCTAssertEqual(value, defaultDate); | ||
} | ||
|
||
- (void)testDateStringAccessor { | ||
NSDate* objectValue = [[self call] getDate:@"testDateObject" defaultValue:NULL]; | ||
NSDate* stringValue = [[self call] getDate:@"testDateString" defaultValue:NULL]; | ||
XCTAssertNotNil(objectValue); | ||
XCTAssertNotNil(stringValue); | ||
XCTAssertEqual(objectValue, stringValue); | ||
} | ||
|
||
- (void)testObjectAccessor { | ||
NSDictionary* value = [[self call] getObject:@"testDict" defaultValue:NULL]; | ||
XCTAssertEqual([value objectForKey:@"testSubkey"], @"sub value"); | ||
|
||
value = [[self call] getObject:@"badString" defaultValue:NULL]; | ||
XCTAssertNil(value); | ||
|
||
value = [[self call] getObject:@"badString" defaultValue:@{@"defaultKey":@"default"}]; | ||
XCTAssertEqual([value objectForKey:@"defaultKey"], @"default"); | ||
} | ||
|
||
- (void)testNumberAccessor { | ||
NSNumber* value = [[self call] getNumber:@"testFloat" defaultValue:NULL]; | ||
XCTAssertNotNil(value); | ||
XCTAssertTrue([value isEqualToNumber:@3.14159]); | ||
|
||
value = [[self call] getNumber:@"badString" defaultValue:NULL]; | ||
XCTAssertNil(value); | ||
|
||
value = [[self call] getNumber:@"badString" defaultValue:@100]; | ||
XCTAssertEqual([value intValue], 100); | ||
|
||
value = [[self call] getNumber:@"testBoolTrue" defaultValue:NULL]; | ||
XCTAssertNotNil(value); | ||
XCTAssertEqual([value boolValue], TRUE); | ||
} | ||
|
||
- (void)testBoolAccessor { | ||
BOOL value = [[self call] getBool:@"testBoolTrue" defaultValue:false]; | ||
XCTAssertTrue(value); | ||
|
||
value = [[self call] getBool:@"testBoolFalse" defaultValue:true]; | ||
XCTAssertFalse(value); | ||
|
||
value = [[self call] getBool:@"badString" defaultValue:true]; | ||
XCTAssertTrue(value); | ||
|
||
value = [[self call] getBool:@"badString" defaultValue:false]; | ||
XCTAssertFalse(value); | ||
} | ||
@end |