Browse Source

Add topBar.backButton.testID option (#5993)

* Add topBar.backButton.testID option

* f

* Update Options.ts

Co-authored-by: Guy Carmeli <guyca@users.noreply.github.com>
Yogev Ben David 5 years ago
parent
commit
e1b76c1fe2
No account linked to committer's email address

+ 1
- 0
lib/ios/RNNBackButtonOptions.h View File

7
 @property (nonatomic, strong) Text* fontFamily;
7
 @property (nonatomic, strong) Text* fontFamily;
8
 @property (nonatomic, strong) Number* fontSize;
8
 @property (nonatomic, strong) Number* fontSize;
9
 @property (nonatomic, strong) Text* transition;
9
 @property (nonatomic, strong) Text* transition;
10
+@property (nonatomic, strong) Text* testID;
10
 @property (nonatomic, strong) Color* color;
11
 @property (nonatomic, strong) Color* color;
11
 @property (nonatomic, strong) Bool* showTitle;
12
 @property (nonatomic, strong) Bool* showTitle;
12
 @property (nonatomic, strong) Bool* visible;
13
 @property (nonatomic, strong) Bool* visible;

+ 1
- 0
lib/ios/RNNBackButtonOptions.m View File

11
     self.color = [ColorParser parse:dict key:@"color"];
11
     self.color = [ColorParser parse:dict key:@"color"];
12
     self.showTitle = [BoolParser parse:dict key:@"showTitle"];
12
     self.showTitle = [BoolParser parse:dict key:@"showTitle"];
13
     self.visible = [BoolParser parse:dict key:@"visible"];
13
     self.visible = [BoolParser parse:dict key:@"visible"];
14
+    self.testID = [TextParser parse:dict key:@"testID"];
14
     self.fontFamily = [TextParser parse:dict key:@"fontFamily"];
15
     self.fontFamily = [TextParser parse:dict key:@"fontFamily"];
15
     self.fontSize = [NumberParser parse:dict key:@"fontSize"];
16
     self.fontSize = [NumberParser parse:dict key:@"fontSize"];
16
     
17
     

+ 13
- 3
lib/ios/TopBarPresenter.m View File

16
     [self setTitleAttributes:options.title];
16
     [self setTitleAttributes:options.title];
17
     [self setLargeTitleAttributes:options.largeTitle];
17
     [self setLargeTitleAttributes:options.largeTitle];
18
     [self showBorder:![options.noBorder getWithDefaultValue:NO]];
18
     [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];
20
 }
20
 }
21
 
21
 
22
 - (void)applyOptionsBeforePopping:(RNNTopBarOptions *)options {
22
 - (void)applyOptionsBeforePopping:(RNNTopBarOptions *)options {
48
     }
48
     }
49
     
49
     
50
     if (options.backButton.hasValue) {
50
     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];
52
     }
52
     }
53
 }
53
 }
54
 
54
 
111
     }
111
     }
112
 }
112
 }
113
 
113
 
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
+    
115
 	UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
123
 	UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
124
+    backItem.accessibilityIdentifier = testID;
125
+    
116
     NSArray* stackChildren = self.navigationController.viewControllers;
126
     NSArray* stackChildren = self.navigationController.viewControllers;
117
     icon = color
127
     icon = color
118
     ? [[icon withTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
128
     ? [[icon withTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]

+ 4
- 0
lib/src/interfaces/Options.ts View File

272
    * Set subtitle font family
272
    * Set subtitle font family
273
    */
273
    */
274
   fontFamily?: FontFamily;
274
   fontFamily?: FontFamily;
275
+  /**
276
+   * Set testID for reference in E2E tests
277
+   */
278
+  testID?: string;
275
 }
279
 }
276
 
280
 
277
 export interface OptionsTopBarBackground {
281
 export interface OptionsTopBarBackground {

+ 13
- 1
playground/ios/NavigationTests/TopBarAppearancePresenterTest.m View File

3
 #import <ReactNativeNavigation/TopBarAppearancePresenter.h>
3
 #import <ReactNativeNavigation/TopBarAppearancePresenter.h>
4
 #import "UIViewController+RNNOptions.h"
4
 #import "UIViewController+RNNOptions.h"
5
 #import <ReactNativeNavigation/RNNStackController.h>
5
 #import <ReactNativeNavigation/RNNStackController.h>
6
+#import <ReactNativeNavigation/RNNComponentViewController.h>
6
 
7
 
7
 @interface TopBarAppearancePresenterTest : XCTestCase
8
 @interface TopBarAppearancePresenterTest : XCTestCase
8
 
9
 
11
 @implementation TopBarAppearancePresenterTest {
12
 @implementation TopBarAppearancePresenterTest {
12
 	TopBarAppearancePresenter* _uut;
13
 	TopBarAppearancePresenter* _uut;
13
 	RNNStackController* _stack;
14
 	RNNStackController* _stack;
15
+	RNNComponentViewController* _componentViewController;
14
 }
16
 }
15
 
17
 
16
 - (void)setUp {
18
 - (void)setUp {
17
     [super setUp];
19
     [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]];
19
 	_uut = [[TopBarAppearancePresenter alloc] initWithNavigationController:_stack];
22
 	_uut = [[TopBarAppearancePresenter alloc] initWithNavigationController:_stack];
20
 }
23
 }
21
 
24
 
32
 	XCTAssertEqual(font.pointSize, 21);
35
 	XCTAssertEqual(font.pointSize, 21);
33
 }
36
 }
34
 
37
 
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
+
35
 
47
 
36
 @end
48
 @end