Merge branch 'feature_login' into feature_integrate_login
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
noemi3 2020-01-07 11:08:42 +01:00
commit bfd75ad347
3 changed files with 42 additions and 11 deletions

View File

@ -32,7 +32,7 @@ class LoginActivityTest {
onView(withId(R.id.button))
.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()))
}
@ -40,13 +40,14 @@ class LoginActivityTest {
@Test
fun loginWithEmptyUsername() {
onView(withId(R.id.instanceServer))
.perform(typeText("instanceServer"))
.perform(typeText("https://wekan.com"))
onView(withId(R.id.password))
.perform(typeText("password"))
closeSoftKeyboard()
onView(withId(R.id.button))
.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()))
@ -55,15 +56,32 @@ class LoginActivityTest {
@Test
fun loginWithEmptyPassword() {
onView(withId(R.id.instanceServer))
.perform(typeText("instanceServer"))
.perform(typeText("https://wekan.com"))
onView(withId(R.id.username))
.perform(typeText("username"))
closeSoftKeyboard()
onView(withId(R.id.button))
.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)))
.check(matches(isDisplayed()))
}
}

View File

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

View File

@ -24,4 +24,9 @@
<item>Relax</item>
<item>Corteza</item>
</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>