-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from Factotum-sdp/end/first_sprint
End/first sprint
- Loading branch information
Showing
39 changed files
with
944 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
app/src/androidTest/java/com/github/factotum_sdp/factotum/ui/login/LoginFragmentTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.github.factotum_sdp.factotum.ui.login | ||
|
||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.action.ViewActions.* | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.matcher.ViewMatchers.* | ||
import androidx.test.ext.junit.rules.ActivityScenarioRule | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.github.factotum_sdp.factotum.MainActivity | ||
import com.github.factotum_sdp.factotum.R | ||
import org.hamcrest.Matchers.not | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class LoginFragmentTest { | ||
|
||
private val usernameInput = onView(withId(R.id.username)) | ||
private val passwordInput = onView(withId(R.id.password)) | ||
private val loginButton = onView(withId(R.id.login)) | ||
private val signUp = onView(withId(R.id.signup)) | ||
|
||
@get:Rule | ||
var testRule = ActivityScenarioRule( | ||
MainActivity::class.java | ||
) | ||
|
||
@Test | ||
fun loginFormInitialStateIsEmpty() { | ||
usernameInput.check(matches(withText(""))) | ||
passwordInput.check(matches(withText(""))) | ||
loginButton.check(matches(not(isEnabled()))) | ||
} | ||
|
||
@Test | ||
fun loginFormWithoutPassword() { | ||
usernameInput.perform(typeText("[email protected]")) | ||
loginButton.check(matches(not(isEnabled()))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/github/factotum_sdp/factotum/data/LoginDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.github.factotum_sdp.factotum.data | ||
|
||
import com.github.factotum_sdp.factotum.data.model.LoggedInUser | ||
import java.io.IOException | ||
|
||
/** | ||
* Class that handles authentication w/ login credentials and retrieves user information. | ||
*/ | ||
class LoginDataSource { | ||
|
||
fun login(username: String, password: String): Result<LoggedInUser> { | ||
try { | ||
val fakeUser = LoggedInUser(java.util.UUID.randomUUID().toString(), username) | ||
return Result.Success(fakeUser) | ||
} catch (e: Throwable) { | ||
return Result.Error(IOException("Error logging in", e)) | ||
} | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/github/factotum_sdp/factotum/data/LoginRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.github.factotum_sdp.factotum.data | ||
|
||
import com.github.factotum_sdp.factotum.data.model.LoggedInUser | ||
|
||
/** | ||
* Class that requests authentication and user information from the remote data source and | ||
* maintains an in-memory cache of login status and user credentials information. | ||
*/ | ||
|
||
class LoginRepository(val dataSource: LoginDataSource) { | ||
|
||
// in-memory cache of the loggedInUser object | ||
var user: LoggedInUser? = null | ||
private set | ||
|
||
val isLoggedIn: Boolean | ||
get() = user != null | ||
|
||
init { | ||
// If user credentials will be cached in local storage, it is recommended it be encrypted | ||
// @see https://developer.android.com/training/articles/keystore | ||
user = null | ||
} | ||
|
||
fun login(username: String, password: String): Result<LoggedInUser> { | ||
// handle login | ||
val result = dataSource.login(username, password) | ||
|
||
if (result is Result.Success) { | ||
setLoggedInUser(result.data) | ||
} | ||
|
||
return result | ||
} | ||
|
||
private fun setLoggedInUser(loggedInUser: LoggedInUser) { | ||
this.user = loggedInUser | ||
// If user credentials will be cached in local storage, it is recommended it be encrypted | ||
// @see https://developer.android.com/training/articles/keystore | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/github/factotum_sdp/factotum/data/Result.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.github.factotum_sdp.factotum.data | ||
|
||
/** | ||
* A generic class that holds a value with its loading status. | ||
* @param <T> | ||
*/ | ||
sealed class Result<out T : Any> { | ||
|
||
data class Success<out T : Any>(val data: T) : Result<T>() | ||
data class Error(val exception: Exception) : Result<Nothing>() | ||
|
||
override fun toString(): String { | ||
return when (this) { | ||
is Success<*> -> "Success[data=$data]" | ||
is Error -> "Error[exception=$exception]" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/github/factotum_sdp/factotum/data/model/LoggedInUser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.github.factotum_sdp.factotum.data.model | ||
|
||
/** | ||
* Data class that captures user information for logged in users retrieved from LoginRepository | ||
*/ | ||
data class LoggedInUser( | ||
val userId: String, | ||
val displayName: String | ||
) |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/github/factotum_sdp/factotum/ui/login/LoggedInUserView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.github.factotum_sdp.factotum.ui.login | ||
|
||
/** | ||
* User details post authentication that is exposed to the UI | ||
*/ | ||
data class LoggedInUserView( | ||
val displayName: String | ||
//... other data fields that may be accessible to the UI | ||
) |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/github/factotum_sdp/factotum/ui/login/LoginFormState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.github.factotum_sdp.factotum.ui.login | ||
|
||
/** | ||
* Data validation state of the login form. | ||
*/ | ||
data class LoginFormState( | ||
val usernameError: Int? = null, | ||
val passwordError: Int? = null, | ||
val isDataValid: Boolean = false | ||
) |
Oops, something went wrong.