コード例 #1
0
  /** This test simulates a user submitting an empty form during registration. */
  @MediumTest
  public void testAttemptRegister_Fail() {
    Fragment currentFragment;

    // create a fake email in the sharedPreference, which
    // should be created in LoginActivity
    Utils.putPreference(getActivity(), Utils.PREFS_ACCOUNT_KEY, randomString(10) + "@anytaxi.hk");

    // create a new registration form
    currentFragment = rFragmentManager.findFragmentById(R.id.register_fragment_container);

    displayFragment(currentFragment, new Register_FormFragment(), true);

    EditText rField_FirstName = (EditText) getActivity().findViewById(R.id.register_first_name);
    EditText rField_LastName = (EditText) getActivity().findViewById(R.id.register_last_name);
    EditText rField_Phone = (EditText) getActivity().findViewById(R.id.register_phone);

    Button rConfirmBtn = (Button) getActivity().findViewById(R.id.register_confirm_btn);

    // simulate a user submitting the form with empty inputs
    rConfirmBtn.performClick();

    // errors should have been set for all fields
    assertNotNull("No error is shown in First Name.", rField_FirstName.getError());
    assertNotNull("No error is shown in Last Name.", rField_LastName.getError());
    assertNotNull("No error is shown in Phone.", rField_Phone.getError());

    // no other activity will start
    assertNull("A unintended activity has been started.", getStartedActivityIntent());
  }
コード例 #2
0
 private void checkInput() {
   addWatchers();
   if (nameText.getError() != null
       || brandBox.getError() != null
       || categoryBox.getError() != null
       || sizeText.getError() != null
       || priceText.getError() != null) {
     return;
   } else {
     ScanUtils.productName = nameText.getText().toString();
     ScanUtils.size = Double.parseDouble(sizeText.getText().toString());
     ScanUtils.price = (int) (Double.parseDouble(priceText.getText().toString()) * 100);
     ScanUtils.measurePos = unitSpinner.getSelectedItemPosition();
     ScanUtils.categoryName = categoryBox.getText().toString();
     ScanUtils.brandName = brandBox.getText().toString();
     clear();
     createProduct();
   }
 }
コード例 #3
0
  /** This test simulates a user submitting a valid form during registration. */
  @MediumTest
  public void testAttemptRegister_Succeed() throws Exception {
    Fragment currentFragment;

    // create a fake email in the sharedPreference, which
    // should be created in LoginActivity
    Utils.putPreference(getActivity(), Utils.PREFS_ACCOUNT_KEY, randomString(10) + "@anytaxi.hk");

    // create a new registration form
    currentFragment = rFragmentManager.findFragmentById(R.id.register_fragment_container);

    displayFragment(currentFragment, new Register_FormFragment(), true);

    EditText rField_FirstName = (EditText) getActivity().findViewById(R.id.register_first_name);
    EditText rField_LastName = (EditText) getActivity().findViewById(R.id.register_last_name);
    EditText rField_Phone = (EditText) getActivity().findViewById(R.id.register_phone);

    Button rConfirmBtn = (Button) getActivity().findViewById(R.id.register_confirm_btn);

    // create valid inputs for the fields
    rField_FirstName.setText("Valid");
    rField_LastName.setText("Test");
    rField_Phone.setText("69999999");

    // simulate a user submitting the form with empty inputs
    rConfirmBtn.performClick();

    // errors should have been set for all fields
    assertNull("Unexpected error is shown in First Name.", rField_FirstName.getError());
    assertNull("Unexpected error is shown in Last Name.", rField_LastName.getError());
    assertNull("Unexpected error is shown in Phone.", rField_Phone.getError());

    // ensure to have Internet connection
    assertTrue("No internet connection.", Utils.isOnline(getActivity()));
    Thread.sleep(5000);

    // RequestActivity should be started
    final Intent redirect = getStartedActivityIntent();
    assertNotNull("No activity is started.", redirect);
    assertEquals(redirect.getComponent().getShortClassName(), ".RequestActivity");
  }
コード例 #4
0
 @Override
 public void onPause() {
   super.onPause();
   addWatchers();
   ScanUtils.measurePos = unitSpinner.getSelectedItemPosition();
   if (nameText.getError() == null) {
     ScanUtils.productName = nameText.getText().toString();
   }
   if (sizeText.getError() == null) {
     ScanUtils.size = Double.parseDouble(sizeText.getText().toString());
   }
   if (priceText.getError() == null) {
     ScanUtils.price = (int) (Double.parseDouble(priceText.getText().toString()) * 100);
   }
   if (categoryBox.getError() == null) {
     ScanUtils.categoryName = categoryBox.getText().toString();
   }
   if (brandBox.getError() == null) {
     ScanUtils.brandName = brandBox.getText().toString();
   }
 }
コード例 #5
0
ファイル: Formulario4.java プロジェクト: ArmandoTorres/SGC
 public boolean validateForm() {
   if (layout != null) {
     for (View a : layout.getFocusables(RelativeLayout.FOCUS_BACKWARD)) {
       if (a instanceof AppCompatEditText) {
         EditText editText = (EditText) a;
         a.getOnFocusChangeListener().onFocusChange(editText, false);
         if (editText.getError() != null) {
           Toast.makeText(
                   ourInstance.context,
                   "Debe indicar la informacion para el campo " + editText.getHint(),
                   Toast.LENGTH_SHORT)
               .show();
           return false;
         }
       }
     }
   }
   return true;
 }
コード例 #6
0
  @SmallTest
  @Feature({"Sync"})
  public void testPassphraseCreation() throws Exception {
    setUpTestAccountAndSignIn();
    SyncTestUtil.waitForSyncActive();
    final SyncCustomizationFragment fragment = startSyncCustomizationFragment();
    ThreadUtils.runOnUiThreadBlocking(
        new Runnable() {
          @Override
          public void run() {
            fragment.onPassphraseTypeSelected(PassphraseType.CUSTOM_PASSPHRASE);
          }
        });
    getInstrumentation().waitForIdleSync();
    PassphraseCreationDialogFragment pcdf = getPassphraseCreationDialogFragment();
    AlertDialog dialog = (AlertDialog) pcdf.getDialog();
    Button okButton = dialog.getButton(Dialog.BUTTON_POSITIVE);
    EditText enterPassphrase = (EditText) dialog.findViewById(R.id.passphrase);
    EditText confirmPassphrase = (EditText) dialog.findViewById(R.id.confirm_passphrase);

    // Error if you try to submit empty passphrase.
    assertNull(confirmPassphrase.getError());
    clickButton(okButton);
    assertTrue(pcdf.isResumed());
    assertNotNull(enterPassphrase.getError());
    assertNull(confirmPassphrase.getError());

    // Error if you try to submit with only the first box filled.
    clearError(confirmPassphrase);
    setText(enterPassphrase, "foo");
    clickButton(okButton);
    assertTrue(pcdf.isResumed());
    assertNull(enterPassphrase.getError());
    assertNotNull(confirmPassphrase.getError());

    // Remove first box should only show empty error message
    setText(enterPassphrase, "");
    clickButton(okButton);
    assertNotNull(enterPassphrase.getError());
    assertNull(confirmPassphrase.getError());

    // Error if you try to submit with only the second box filled.
    clearError(confirmPassphrase);
    setText(confirmPassphrase, "foo");
    clickButton(okButton);
    assertTrue(pcdf.isResumed());
    assertNull(enterPassphrase.getError());
    assertNotNull(confirmPassphrase.getError());

    // No error if text doesn't match without button press.
    setText(enterPassphrase, "foo");
    clearError(confirmPassphrase);
    setText(confirmPassphrase, "bar");
    assertNull(enterPassphrase.getError());
    assertNull(confirmPassphrase.getError());

    // Error if you try to submit unmatching text.
    clearError(confirmPassphrase);
    clickButton(okButton);
    assertTrue(pcdf.isResumed());
    assertNull(enterPassphrase.getError());
    assertNotNull(confirmPassphrase.getError());

    // Success if text matches.
    setText(confirmPassphrase, "foo");
    clickButton(okButton);
    assertFalse(pcdf.isResumed());
  }
コード例 #7
0
 public void assertPresenceOfValidationMessage() {
   TextField textField =
       (TextField) solo.getCurrentActivity().findViewById("enquirer_name".hashCode());
   EditText nameField = (EditText) textField.findViewById(R.id.value);
   assertEquals("Enquirer name is required", nameField.getError().toString());
 }
コード例 #8
0
  public void attemptRegistration() {
    if (mAuthTask != null) {
      return;
    }

    // Reset errors.
    ET_email.setError(null);
    ET_password.setError(null);

    // Store values at the time of the login attempt.
    String email = ET_email.getText().toString();
    String password = ET_password.getText().toString();

    boolean cancel = false;
    View focusView = null;

    // Check for a valid password
    if (!isPasswordValid(password)) {
      ET_password.setError(
          "Invalid password. Passwords need:\n•at least 1 number\n•more than five characters");
      focusView = ET_password;
      cancel = true;
    }

    // Check for if both passwords entered is correct
    if (!ET_password.getText().toString().contentEquals(ET_confirmPassword.getText().toString())) {
      if (ET_password.getError() == null) ET_confirmPassword.setError("Passwords are not the same");
      focusView = ET_confirmPassword;
      cancel = true;
    }

    // TODO: change this later
    // Check for a valid email address.
    //        if (TextUtils.isEmpty(email)) {
    //            ET_email.setError(getString(R.string.error_field_required));
    //            focusView = ET_email;
    //            cancel = true;
    //        } else if (!isEmailValid(email)) {
    //            ET_email.setError(getString(R.string.error_invalid_email));
    //            focusView = ET_email;
    //            cancel = true;
    //        }

    if (cancel) {
      // There was an error; don't attempt login and focus the first
      // form field with an error.
      focusView.requestFocus();
    } else {
      // Show a progress spinner, and kick off a background task to
      // perform the user registration attempt
      showProgress(true);
      // mAuthTask = new UserLoginTask(email, password);
      // mAuthTask.execute((Void) null);

      final ParseUser user = new ParseUser();
      user.setUsername(ET_email.getText().toString());
      user.setPassword(ET_password.getText().toString());
      user.setEmail(ET_email.getText().toString());

      user.signUpInBackground(
          new SignUpCallback() {
            public void done(ParseException e) {
              if (e == null) {
                // Hooray! Registration successful
                Toast.makeText(
                        getActivity().getApplicationContext(),
                        "Registration successful",
                        Toast.LENGTH_SHORT)
                    .show();
                // TODO: Change this intent or even erase it and do something else after
                // registration successful
                Intent goToApplication = new Intent(getActivity(), TabActivity.class);
                goToApplication.putExtra(
                    TabConstants.FREELANCE_OR_COMPANY_KEY, TabConstants.FOR_FREELANCE);
                startActivity(goToApplication);
                showProgress(false);
                getActivity().finish();
              } else {
                // Sign up didn't succeed. Look at the ParseException
                // to figure out what went wrong
                Toast.makeText(
                        getActivity().getApplicationContext(),
                        "Signup unsuccessful: " + e.getMessage(),
                        Toast.LENGTH_SHORT)
                    .show();
                Log.e("LoginAndRegistration", e.getMessage());
                showProgress(false);
              }
            }
          });
    }
  }