Skip to content

Commit e1b76c1

Browse files
yogevbdguyca
andauthored
Add topBar.backButton.testID option (#5993)
* Add topBar.backButton.testID option * f * Update Options.ts Co-authored-by: Guy Carmeli <[email protected]>
1 parent 4ce0e89 commit e1b76c1

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

lib/ios/RNNBackButtonOptions.h

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
@property (nonatomic, strong) Text* fontFamily;
88
@property (nonatomic, strong) Number* fontSize;
99
@property (nonatomic, strong) Text* transition;
10+
@property (nonatomic, strong) Text* testID;
1011
@property (nonatomic, strong) Color* color;
1112
@property (nonatomic, strong) Bool* showTitle;
1213
@property (nonatomic, strong) Bool* visible;

lib/ios/RNNBackButtonOptions.m

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ - (instancetype)initWithDict:(NSDictionary *)dict {
1111
self.color = [ColorParser parse:dict key:@"color"];
1212
self.showTitle = [BoolParser parse:dict key:@"showTitle"];
1313
self.visible = [BoolParser parse:dict key:@"visible"];
14+
self.testID = [TextParser parse:dict key:@"testID"];
1415
self.fontFamily = [TextParser parse:dict key:@"fontFamily"];
1516
self.fontSize = [NumberParser parse:dict key:@"fontSize"];
1617

lib/ios/TopBarPresenter.m

+13-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ - (void)applyOptions:(RNNTopBarOptions *)options {
1616
[self setTitleAttributes:options.title];
1717
[self setLargeTitleAttributes:options.largeTitle];
1818
[self showBorder:![options.noBorder getWithDefaultValue:NO]];
19-
[self setBackButtonOptions:[options.backButton.icon getWithDefaultValue:nil] withColor:[options.backButton.color getWithDefaultValue:nil] title:[options.backButton.title getWithDefaultValue:nil] showTitle:[options.backButton.showTitle getWithDefaultValue:YES] fontFamily:[options.backButton.fontFamily getWithDefaultValue:nil] fontSize:[options.backButton.fontSize getWithDefaultValue:nil]];
19+
[self setBackButtonOptions:options.backButton];
2020
}
2121

2222
- (void)applyOptionsBeforePopping:(RNNTopBarOptions *)options {
@@ -48,7 +48,7 @@ - (void)mergeOptions:(RNNTopBarOptions *)options withDefault:(RNNTopBarOptions *
4848
}
4949

5050
if (options.backButton.hasValue) {
51-
[self setBackButtonOptions:[withDefault.backButton.icon getWithDefaultValue:nil] withColor:[withDefault.backButton.color getWithDefaultValue:nil] title:[withDefault.backButton.title getWithDefaultValue:nil] showTitle:[withDefault.backButton.showTitle getWithDefaultValue:YES] fontFamily:[withDefault.backButton.fontFamily getWithDefaultValue:nil] fontSize:[options.backButton.fontSize getWithDefaultValue:nil]];
51+
[self setBackButtonOptions:withDefault.backButton];
5252
}
5353
}
5454

@@ -111,8 +111,18 @@ - (void)setLargeTitleAttributes:(RNNLargeTitleOptions *)largeTitleOptions {
111111
}
112112
}
113113

114-
- (void)setBackButtonOptions:(UIImage *)icon withColor:(UIColor *)color title:(NSString *)title showTitle:(BOOL)showTitle fontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize {
114+
- (void)setBackButtonOptions:(RNNBackButtonOptions *)backButtonOptions {
115+
UIImage* icon = [backButtonOptions.icon getWithDefaultValue:nil];
116+
UIColor* color = [backButtonOptions.color getWithDefaultValue:nil];
117+
NSString* title = [backButtonOptions.title getWithDefaultValue:nil];
118+
BOOL showTitle = [backButtonOptions.showTitle getWithDefaultValue:YES];
119+
NSString* fontFamily = [backButtonOptions.fontFamily getWithDefaultValue:nil];
120+
NSNumber* fontSize = [backButtonOptions.fontSize getWithDefaultValue:nil];
121+
NSString* testID = [backButtonOptions.testID getWithDefaultValue:nil];
122+
115123
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
124+
backItem.accessibilityIdentifier = testID;
125+
116126
NSArray* stackChildren = self.navigationController.viewControllers;
117127
icon = color
118128
? [[icon withTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]

lib/src/interfaces/Options.ts

+4
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ export interface OptionsTopBarBackButton {
272272
* Set subtitle font family
273273
*/
274274
fontFamily?: FontFamily;
275+
/**
276+
* Set testID for reference in E2E tests
277+
*/
278+
testID?: string;
275279
}
276280

277281
export interface OptionsTopBarBackground {

playground/ios/NavigationTests/TopBarAppearancePresenterTest.m

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#import <ReactNativeNavigation/TopBarAppearancePresenter.h>
44
#import "UIViewController+RNNOptions.h"
55
#import <ReactNativeNavigation/RNNStackController.h>
6+
#import <ReactNativeNavigation/RNNComponentViewController.h>
67

78
@interface TopBarAppearancePresenterTest : XCTestCase
89

@@ -11,11 +12,13 @@ @interface TopBarAppearancePresenterTest : XCTestCase
1112
@implementation TopBarAppearancePresenterTest {
1213
TopBarAppearancePresenter* _uut;
1314
RNNStackController* _stack;
15+
RNNComponentViewController* _componentViewController;
1416
}
1517

1618
- (void)setUp {
1719
[super setUp];
18-
_stack = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions] presenter:_uut eventEmitter:nil childViewControllers:@[]];
20+
_componentViewController = [[RNNComponentViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil];
21+
_stack = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions] presenter:_uut eventEmitter:nil childViewControllers:@[_componentViewController]];
1922
_uut = [[TopBarAppearancePresenter alloc] initWithNavigationController:_stack];
2023
}
2124

@@ -32,5 +35,14 @@ - (void)testMergeOptions_shouldMergeWithDefault {
3235
XCTAssertEqual(font.pointSize, 21);
3336
}
3437

38+
- (void)testApplyOptions_shouldSetBackButtonTestID {
39+
RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
40+
options.topBar.backButton.testID = [Text withValue:@"TestID"];
41+
42+
[_uut applyOptions:options.topBar];
43+
XCTAssertTrue([_componentViewController.navigationItem.backBarButtonItem.accessibilityIdentifier isEqualToString:@"TestID"]);
44+
}
45+
46+
3547

3648
@end

0 commit comments

Comments
 (0)