Browse Source

Updates to the test app to make it easier to test the auth emulator.

Rosalyn Tan 5 năm trước cách đây
mục cha
commit
fb7c829352

+ 2 - 0
FirebaseAuth/Tests/Sample/Sample/MainViewController+Internal.h

@@ -47,6 +47,8 @@ typedef void (^TestAutomationCallback)(NSError *_Nullable error);
 
 @property(nonatomic) BOOL isNewUserToggleOn;
 
+@property(nonatomic) BOOL isEmulatorEnabled;
+
 @property(nonatomic) ActionCodeRequestType actionCodeRequestType;
 
 @property(nonatomic) NSURL *actionCodeContinueURL;

+ 25 - 0
FirebaseAuth/Tests/Sample/Sample/MainViewController.m

@@ -45,6 +45,8 @@ NS_ASSUME_NONNULL_BEGIN
 
 static NSString *const kSectionTitleSettings = @"Settings";
 
+static NSString *const kUseEmulatorTitle = @"Use emulator";
+
 static NSString *const kSectionTitleUserDetails = @"User Defaults";
 
 static NSString *const kSwitchToInMemoryUserTitle = @"Switch to in memory user";
@@ -218,6 +220,9 @@ static NSDictionary<NSString *, NSString *> *parseURL(NSString *urlString) {
       [StaticContentTableViewSection sectionWithTitle:kSectionTitleSettings cells:@[
         [StaticContentTableViewCell cellWithTitle:kSectionTitleSettings
                                            action:^{ [weakSelf presentSettings]; }],
+        [StaticContentTableViewCell cellWithTitle:kUseEmulatorTitle
+                                            value:_isEmulatorEnabled ? @"Enabled" : @"Disabled"
+                                           action:^{[weakSelf useEmulator]; }],
         [StaticContentTableViewCell cellWithTitle:kNewOrExistingUserToggleTitle
                                             value:_isNewUserToggleOn ? @"Enabled" : @"Disabled"
                                            action:^{
@@ -596,6 +601,26 @@ static NSDictionary<NSString *, NSString *> *parseURL(NSString *urlString) {
   }
 }
 
+- (void)useEmulator {
+  [self showTextInputPromptWithMessage:@"Host:"
+                       completionBlock:^(BOOL userPressedOK, NSString *_Nullable host) {
+  if (!userPressedOK || !host.length) {
+    return;
+  }
+  [self showTextInputPromptWithMessage:@"Port:"
+                      completionBlock:^(BOOL userPressedOK, NSString *_Nullable port) {
+      if (!userPressedOK || !port.length) {
+        return;
+      }
+    [[FIRAuth auth] useEmulatorWithHost:host port:[port integerValue]];
+    if (!self->_isEmulatorEnabled) {
+      self->_isEmulatorEnabled = true;
+      [self updateTable];
+    }
+    }];
+  }];
+}
+
 - (void)log:(NSString *)string {
   dispatch_async(dispatch_get_main_queue(), ^{
     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];