Przeglądaj źródła

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 lat temu
rodzic
commit
e1b76c1fe2
No account linked to committer's email address

+ 1
- 0
lib/ios/RNNBackButtonOptions.h Wyświetl plik

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

+ 1
- 0
lib/ios/RNNBackButtonOptions.m Wyświetl plik

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

+ 13
- 3
lib/ios/TopBarPresenter.m Wyświetl plik

@@ -16,7 +16,7 @@
16 16
     [self setTitleAttributes:options.title];
17 17
     [self setLargeTitleAttributes:options.largeTitle];
18 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 22
 - (void)applyOptionsBeforePopping:(RNNTopBarOptions *)options {
@@ -48,7 +48,7 @@
48 48
     }
49 49
     
50 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,8 +111,18 @@
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 123
 	UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
124
+    backItem.accessibilityIdentifier = testID;
125
+    
116 126
     NSArray* stackChildren = self.navigationController.viewControllers;
117 127
     icon = color
118 128
     ? [[icon withTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]

+ 4
- 0
lib/src/interfaces/Options.ts Wyświetl plik

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

+ 13
- 1
playground/ios/NavigationTests/TopBarAppearancePresenterTest.m Wyświetl plik

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