forked from microsoft/AdaptiveCards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [iOS] updated action test * [iOS] Added vertical constraint to public API and mocks for unit testing * [iOS] added title width constraint to public api
- Loading branch information
1 parent
4d0356f
commit 2ed5ff7
Showing
11 changed files
with
260 additions
and
18 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
114 changes: 114 additions & 0 deletions
114
source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCardsTests/AdaptiveCardsActionsTest.mm
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,114 @@ | ||
// | ||
// AdaptiveCardsActionsTest.mm | ||
// AdaptiveCardsActionsTest | ||
// | ||
// Copyright © 2021 Microsoft. All rights reserved. | ||
// | ||
|
||
#import "ACOBaseActionElementPrivate.h" | ||
#import "ACOHostConfigPrivate.h" | ||
#import "ACRButton.h" | ||
#import "ACRViewPrivate.h" | ||
#import "BaseActionElement.h" | ||
#import "Mocks/MockACRView.h" | ||
#import "Mocks/MockContext.h" | ||
#import "OpenUrlAction.h" | ||
#import <UIKit/UIKit.h> | ||
#import <XCTest/XCTest.h> | ||
|
||
@interface AdaptiveCardsActionsTest : XCTestCase | ||
|
||
@end | ||
|
||
using namespace AdaptiveCards; | ||
|
||
@implementation AdaptiveCardsActionsTest { | ||
MockACRView *_rootView; | ||
} | ||
|
||
- (void)setUp | ||
{ | ||
// Put setup code here. This method is called before the invocation of each test method in the class. | ||
_rootView = [[MockACRView alloc] initWithFrame:CGRectMake(0, 0, 20, 30)]; | ||
} | ||
|
||
- (void)tearDown | ||
{ | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
} | ||
|
||
- (ACOBaseActionElement *)buildSimpleAction | ||
{ | ||
std::shared_ptr<OpenUrlAction> action = std::make_shared<OpenUrlAction>(); | ||
action->SetTitle("Hello"); | ||
action->SetUrl("https://www.bing.com"); | ||
ACOBaseActionElement *acoAction = [ACOBaseActionElement getACOActionElementFromAdaptiveElement:action]; | ||
return acoAction; | ||
} | ||
|
||
- (ACRButton *)buildAButton:(ACOBaseActionElement *)acoAction | ||
{ | ||
ACOHostConfig *acoConfig = [[ACOHostConfig alloc] init]; | ||
return (ACRButton *)[ACRButton rootView:_rootView baseActionElement:acoAction title:acoAction.title andHostConfig:acoConfig]; | ||
} | ||
|
||
- (void)testACRButtonPublicConstraints | ||
{ | ||
ACRButton *button = [self buildAButton:[self buildSimpleAction]]; | ||
XCTAssertNotNil(button); | ||
XCTAssertNotNil(button.heightConstraint); | ||
XCTAssertNil(button.titleWidthConstraint); | ||
} | ||
|
||
- (void)testACRButtonPublicConstraintsWithImageView | ||
{ | ||
std::string iconURL = "https://adaptivecards.io/content/cats/1.png"; | ||
NSString *iconURLObjc = [NSString stringWithCString:iconURL.c_str() encoding:NSUTF8StringEncoding]; | ||
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:iconURLObjc]]]; | ||
ACOBaseActionElement *action = [self buildSimpleAction]; | ||
action.element->SetIconUrl(iconURL); | ||
NSString *key = iconURLObjc; | ||
[_rootView getImageMap][key] = image; | ||
ACRButton *button = [self buildAButton:action]; | ||
XCTAssertNotNil(button.heightConstraint); | ||
XCTAssertNotNil(button.titleWidthConstraint); | ||
} | ||
|
||
- (void)testACRButtonPublicConstraintsWithImageViewWithKey | ||
{ | ||
std::string iconURL = "https://adaptivecards.io/content/cats/1.png"; | ||
NSString *iconURLObjc = [NSString stringWithCString:iconURL.c_str() encoding:NSUTF8StringEncoding]; | ||
|
||
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:iconURLObjc]]]; | ||
UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; | ||
ACOBaseActionElement *acoAction = [self buildSimpleAction]; | ||
acoAction.element->SetIconUrl(iconURL); | ||
NSNumber *number = [NSNumber numberWithUnsignedLongLong:(unsigned long long)acoAction.element.get()]; | ||
NSString *key = [number stringValue]; | ||
[_rootView setImageView:key view:imageView]; | ||
ACRButton *button = [self buildAButton:acoAction]; | ||
XCTAssertNotNil(button.heightConstraint); | ||
XCTAssertNotNil(button.titleWidthConstraint); | ||
} | ||
|
||
- (void)testACRButtonPublicConstraintsWithIconPlacements | ||
{ | ||
std::string iconURL = "https://adaptivecards.io/content/cats/1.png"; | ||
NSString *iconURLObjc = [NSString stringWithCString:iconURL.c_str() encoding:NSUTF8StringEncoding]; | ||
|
||
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:iconURLObjc]]]; | ||
UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; | ||
ACOBaseActionElement *acoAction = [self buildSimpleAction]; | ||
acoAction.element->SetIconUrl(iconURL); | ||
NSNumber *number = [NSNumber numberWithUnsignedLongLong:(unsigned long long)acoAction.element.get()]; | ||
NSString *key = [number stringValue]; | ||
_rootView.mockContext = [[MockContext alloc] init]; | ||
[_rootView setImageView:key view:imageView]; | ||
[_rootView.mockContext setMockValueForAllHasActionIcons:YES]; | ||
ACRButton *button = [self buildAButton:acoAction]; | ||
XCTAssertNil(button.heightConstraint); | ||
XCTAssertNil(button.titleWidthConstraint); | ||
} | ||
|
||
@end | ||
|
16 changes: 16 additions & 0 deletions
16
source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCardsTests/Mocks/MockACRView.h
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,16 @@ | ||
// | ||
// MockACRView.h | ||
// AdaptiveCardsTests | ||
// | ||
// Copyright © 2021 Microsoft. All rights reserved. | ||
// | ||
|
||
#import "ACRViewPrivate.h" | ||
#import "MockContext.h" | ||
|
||
@interface MockACRView : ACRView | ||
|
||
@property MockContext *mockContext; | ||
|
||
@end | ||
|
28 changes: 28 additions & 0 deletions
28
source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCardsTests/Mocks/MockACRView.mm
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,28 @@ | ||
// | ||
// MockACRView.m | ||
// AdaptiveCardsTests | ||
// | ||
// Copyright © 2021 Microsoft. All rights reserved. | ||
// | ||
|
||
#import "MockACRView.h" | ||
#import "MockContext.h" | ||
#import <Foundation/Foundation.h> | ||
|
||
@implementation MockACRView | ||
|
||
- (instancetype)initWithFrame:(CGRect)frame | ||
{ | ||
self = [super initWithFrame:frame]; | ||
return self; | ||
} | ||
|
||
- (void)setMockContext:(MockContext *)context | ||
{ | ||
if (context) { | ||
[self setContext:context]; | ||
_mockContext = context; | ||
} | ||
} | ||
|
||
@end |
14 changes: 14 additions & 0 deletions
14
source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCardsTests/Mocks/MockContext.h
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,14 @@ | ||
// | ||
// MockContext.h | ||
// AdaptiveCards | ||
// | ||
// Copyright © 2021 Microsoft. All rights reserved. | ||
// | ||
|
||
#import "ACORenderContext.h" | ||
|
||
@interface MockContext : ACORenderContext | ||
|
||
- (void)setMockValueForAllHasActionIcons:(BOOL)value; | ||
|
||
@end |
24 changes: 24 additions & 0 deletions
24
source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCardsTests/Mocks/MockContext.mm
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,24 @@ | ||
// | ||
// MockContext.m | ||
// AdaptiveCardsTests | ||
// | ||
// Copyright © 2021 Microsoft. All rights reserved. | ||
// | ||
|
||
#import "MockContext.h" | ||
|
||
@implementation MockContext { | ||
BOOL _mockValueForAllHasActionIcons; | ||
} | ||
|
||
- (void)setMockValueForAllHasActionIcons:(BOOL)value | ||
{ | ||
_mockValueForAllHasActionIcons = value; | ||
} | ||
|
||
- (BOOL)allHasActionIcons | ||
{ | ||
return _mockValueForAllHasActionIcons; | ||
} | ||
|
||
@end |