diff options
author | fupduck <fupduck@riseup.net> | 2018-02-06 05:53:09 -0800 |
---|---|---|
committer | fupduck <fupduck@riseup.net> | 2018-02-06 05:53:09 -0800 |
commit | edd34192484f4eb618fdcc2a68b18168c155d63c (patch) | |
tree | d884f63e74911d2ea2cf7bc864414a623e15a2b3 /app/src/androidTest/legacy/UserStatusTestController.java | |
parent | c0848bac7ac44f4b09f9e5d66ab71f079cb0f514 (diff) | |
parent | d2d61a16fd2a3ea0fd42073de98d1311b184444d (diff) |
Merge branch '#8832_update_ics-openvpn' into '0.9.8'
#8832 update ics openvpn
See merge request leap/bitmask_android!33
Diffstat (limited to 'app/src/androidTest/legacy/UserStatusTestController.java')
-rw-r--r-- | app/src/androidTest/legacy/UserStatusTestController.java | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/app/src/androidTest/legacy/UserStatusTestController.java b/app/src/androidTest/legacy/UserStatusTestController.java new file mode 100644 index 00000000..3b0daf9a --- /dev/null +++ b/app/src/androidTest/legacy/UserStatusTestController.java @@ -0,0 +1,83 @@ +package se.leap.bitmaskclient.test; + +import android.view.*; + +import com.robotium.solo.*; + +import se.leap.bitmaskclient.R; + +import static junit.framework.Assert.assertTrue; + +public class UserStatusTestController { + private final Solo solo; + + public UserStatusTestController(Solo solo) { + this.solo = solo; + } + + void clickUserSessionButton() { + solo.clickOnView(getUserSessionButton()); + } + + View getUserSessionButton() throws IllegalStateException { + View view = solo.getView(R.id.user_status_button); + if(view == null) + throw new IllegalStateException(); + + return view; + } + + void logIn(String username, String password, boolean expectSuccess) { + solo.enterText(0, username); + solo.enterText(1, password); + // https://stackoverflow.com/questions/33560746/how-to-test-alertdialog-item-click-in-robotium-for-android-studio + solo.clickOnView(solo.getView(android.R.id.button1)); + assertTrue(solo.waitForDialogToClose()); + + if (expectSuccess) { + assertLoggedIn(); + } else { + solo.waitForText(solo.getString(R.string.cancel)); + assertTrue(solo.waitForText(solo.getString(R.string.login_button))); + } + } + + void logIn(String username, String password) { + logIn(username, password, true); + } + + private void assertLoggedIn() { + String log_out = solo.getString(R.string.logout_button); + assertTrue(solo.waitForText(log_out)); + } + + void assertLoggedOut() { + String log_in = solo.getString(R.string.login_button); + assertTrue(solo.waitForText(log_in)); + } + + void logOut() { + assertLoggedIn(); + clickUserSessionButton(); + + solo.clickOnActionBarItem(R.string.logout_button); + solo.waitForDialogToClose(); + assertLoggedOut(); + } + + boolean assertErrorLogInDialogAppears() { + assertTrue(solo.waitForDialogToOpen()); + + String username_hint = solo.getEditText(0).getHint().toString(); + String correct_username_hint = solo.getString(R.string.username_hint); + String password_hint = solo.getEditText(1).getHint().toString(); + String correct_password_hint = solo.getString(R.string.password_hint); + String user_message = solo.getText(0).toString(); + String riseup_user_message = solo.getString(R.string.login_riseup_warning); + + return username_hint.equalsIgnoreCase(correct_username_hint) + && password_hint.equalsIgnoreCase(correct_password_hint) + && !user_message.equalsIgnoreCase(riseup_user_message) + && !user_message.isEmpty(); + } +} |