diff options
author | Fup Duck <fupduck@sacknagel.com> | 2018-02-06 18:34:13 +0100 |
---|---|---|
committer | Fup Duck <fupduck@sacknagel.com> | 2018-02-06 18:34:13 +0100 |
commit | b4b18f1d52956cf067f87d75d8f3f06c9be48afe (patch) | |
tree | 9191273c611e39afe7aa3401408dfa0dbc67b544 /app/src/androidTest/legacy/UserStatusTestController.java | |
parent | 6be60844db062575055752b554dbf14941e8e185 (diff) | |
parent | edd34192484f4eb618fdcc2a68b18168c155d63c (diff) |
Merge branch 'leap_0.9.8' into 8828_memory_leap_eip
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(); + } +} |