add login and board_list #26

Manually merged
norangebit merged 38 commits from feature_integrate_login into develop 2020-01-14 19:53:09 +00:00
3 changed files with 42 additions and 11 deletions
Showing only changes of commit bfd75ad347 - Show all commits

View File

@ -32,7 +32,7 @@ class LoginActivityTest {
onView(withId(R.id.button)) onView(withId(R.id.button))
.perform(click()) .perform(click())
onView(withText("Riempire tutti i campi")) onView(withText(R.string.login_empty_field))
.inRoot(withDecorView(not(activityRule.activity.window.decorView))) .inRoot(withDecorView(not(activityRule.activity.window.decorView)))
.check(matches(isDisplayed())) .check(matches(isDisplayed()))
} }
@ -40,13 +40,14 @@ class LoginActivityTest {
@Test @Test
fun loginWithEmptyUsername() { fun loginWithEmptyUsername() {
onView(withId(R.id.instanceServer)) onView(withId(R.id.instanceServer))
.perform(typeText("instanceServer")) .perform(typeText("https://wekan.com"))
onView(withId(R.id.password)) onView(withId(R.id.password))
.perform(typeText("password")) .perform(typeText("password"))
closeSoftKeyboard() closeSoftKeyboard()
onView(withId(R.id.button)) onView(withId(R.id.button))
.perform(click()) .perform(click())
onView(withText("Riempire tutti i campi"))
onView(withText(R.string.login_empty_field))
.inRoot(withDecorView(not(activityRule.activity.window.decorView))) .inRoot(withDecorView(not(activityRule.activity.window.decorView)))
.check(matches(isDisplayed())) .check(matches(isDisplayed()))
@ -55,15 +56,32 @@ class LoginActivityTest {
@Test @Test
fun loginWithEmptyPassword() { fun loginWithEmptyPassword() {
onView(withId(R.id.instanceServer)) onView(withId(R.id.instanceServer))
.perform(typeText("instanceServer")) .perform(typeText("https://wekan.com"))
onView(withId(R.id.username)) onView(withId(R.id.username))
.perform(typeText("username")) .perform(typeText("username"))
closeSoftKeyboard() closeSoftKeyboard()
onView(withId(R.id.button)) onView(withId(R.id.button))
.perform(click()) .perform(click())
onView(withText("Riempire tutti i campi"))
onView(withText(R.string.login_empty_field))
.inRoot(withDecorView(not(activityRule.activity.window.decorView)))
.check(matches(isDisplayed()))
}
@Test
fun loginWithUnformedInstance(){
onView(withId(R.id.instanceServer))
.perform(typeText("not an URL"))
onView(withId(R.id.username))
.perform(typeText("username"))
onView(withId(R.id.password))
.perform(typeText("password"))
closeSoftKeyboard()
onView(withId(R.id.button))
.perform(click())
onView(withText(R.string.login_unformed_instance))
.inRoot(withDecorView(not(activityRule.activity.window.decorView))) .inRoot(withDecorView(not(activityRule.activity.window.decorView)))
.check(matches(isDisplayed())) .check(matches(isDisplayed()))
} }
} }

View File

@ -3,6 +3,7 @@ package it.unisannio.ding.ids.wedroid.app.view
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.webkit.URLUtil
import android.widget.Toast import android.widget.Toast
import it.unisannio.ding.ids.wedroid.app.R import it.unisannio.ding.ids.wedroid.app.R
import it.unisannio.ding.ids.wedroid.app.util.SharedPreferenceHelper import it.unisannio.ding.ids.wedroid.app.util.SharedPreferenceHelper
@ -32,17 +33,24 @@ class LoginActivity : AppCompatActivity() {
fun loginButton(v: View) { fun loginButton(v: View) {
if (username.text.isBlank() || instanceServer.text.isBlank() || password.text.isBlank()) { if (username.text.isBlank() || instanceServer.text.isBlank() || password.text.isBlank()) {
Toast.makeText(this, "Riempire tutti i campi", Toast.LENGTH_LONG) Toast.makeText(this, R.string.login_empty_field, Toast.LENGTH_LONG)
.show() .show()
return return
} }
val userNameText = username.text.toString() val userNameText = username.text.toString()
val passwordText = password.text.toString() val passwordText = password.text.toString()
val instanceServerText = instanceServer.text.toString()
if (!URLUtil.isValidUrl(instanceServerText)){
Toast.makeText(this, R.string.login_unformed_instance, Toast.LENGTH_LONG)
.show()
return
}
val service = Retrofit.Builder() val service = Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create())
.baseUrl(instanceServer.text.toString()) .baseUrl(instanceServerText)
.build() .build()
.create(LoginService::class.java) .create(LoginService::class.java)
@ -50,7 +58,7 @@ class LoginActivity : AppCompatActivity() {
override fun onFailure(call: Call<UserPrototype>, t: Throwable) { override fun onFailure(call: Call<UserPrototype>, t: Throwable) {
Toast.makeText( Toast.makeText(
applicationContext, applicationContext,
"Controlla la tua connessione internet", R.string.login_network_error,
Toast.LENGTH_LONG Toast.LENGTH_LONG
).show() ).show()
} }
@ -60,7 +68,7 @@ class LoginActivity : AppCompatActivity() {
if (response.code() != 200) { if (response.code() != 200) {
Toast.makeText( Toast.makeText(
applicationContext, applicationContext,
"Credenziali non corrette", R.string.login_wrong_field,
Toast.LENGTH_LONG Toast.LENGTH_LONG
).show() ).show()
return return
@ -72,7 +80,7 @@ class LoginActivity : AppCompatActivity() {
Toast.makeText( Toast.makeText(
applicationContext, applicationContext,
"Login effettuato con successo", R.string.login_success,
Toast.LENGTH_LONG Toast.LENGTH_LONG
).show() ).show()

View File

@ -24,4 +24,9 @@
<item>Relax</item> <item>Relax</item>
<item>Corteza</item> <item>Corteza</item>
</string-array> </string-array>
<string name="login_empty_field">Riempire tutti i campi</string>
<string name="login_unformed_instance">Formato URL non valido</string>
<string name="login_network_error">Controlla la tua connessione internet</string>
<string name="login_wrong_field">Credenziali non corrette</string>
<string name="login_success">Login effettuato con successo</string>
</resources> </resources>