mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-02-07 19:04:36 +01:00
Fill login credentials with default values upon fakelog selection (#255)
Resolves #245
This commit is contained in:
parent
82d7cf94e8
commit
5ba12cf8c6
@ -31,6 +31,15 @@ class LoginFormFragment : BaseFragment(), LoginFormView {
|
|||||||
fun newInstance() = LoginFormFragment()
|
fun newInstance() = LoginFormFragment()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val formNameValue: String
|
||||||
|
get() = loginFormName.text.toString()
|
||||||
|
|
||||||
|
override val formPassValue: String
|
||||||
|
get() = loginFormPass.text.toString()
|
||||||
|
|
||||||
|
override val formHostValue: String?
|
||||||
|
get() = resources.getStringArray(R.array.endpoints_values)[loginFormHost.selectedItemPosition]
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
return inflater.inflate(R.layout.fragment_login_form, container, false)
|
return inflater.inflate(R.layout.fragment_login_form, container, false)
|
||||||
}
|
}
|
||||||
@ -41,29 +50,26 @@ class LoginFormFragment : BaseFragment(), LoginFormView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun initView() {
|
override fun initView() {
|
||||||
loginFormSignIn.setOnClickListener {
|
|
||||||
presenter.attemptLogin(
|
|
||||||
loginFormName.text.toString(),
|
|
||||||
loginFormPass.text.toString(),
|
|
||||||
resources.getStringArray(R.array.endpoints_values)[loginFormHost.selectedItemPosition]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
loginFormName.setOnTextChangedListener { presenter.onNameTextChanged() }
|
loginFormName.setOnTextChangedListener { presenter.onNameTextChanged() }
|
||||||
loginFormPass.setOnTextChangedListener { presenter.onPassTextChanged() }
|
loginFormPass.setOnTextChangedListener { presenter.onPassTextChanged() }
|
||||||
|
loginFormHost.setOnItemSelectedListener { presenter.onHostSelected() }
|
||||||
|
loginFormSignIn.setOnClickListener { presenter.attemptLogin() }
|
||||||
|
|
||||||
loginFormPass.setOnEditorActionListener { _, id, _ ->
|
loginFormPass.setOnEditorActionListener { _, id, _ ->
|
||||||
if (id == IME_ACTION_DONE || id == IME_NULL) loginFormSignIn.callOnClick() else false
|
if (id == IME_ACTION_DONE || id == IME_NULL) loginFormSignIn.callOnClick() else false
|
||||||
}
|
}
|
||||||
|
|
||||||
loginFormHost.setOnItemSelectedListener { presenter.onHostSelected() }
|
|
||||||
|
|
||||||
context?.let {
|
context?.let {
|
||||||
loginFormHost.adapter = ArrayAdapter.createFromResource(it, R.array.endpoints_keys, android.R.layout.simple_spinner_item)
|
loginFormHost.adapter = ArrayAdapter.createFromResource(it, R.array.endpoints_keys, android.R.layout.simple_spinner_item)
|
||||||
.apply { setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) }
|
.apply { setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun setDefaultCredentials(name: String, pass: String) {
|
||||||
|
loginFormName.setText(name)
|
||||||
|
loginFormPass.setText(pass)
|
||||||
|
}
|
||||||
|
|
||||||
override fun setErrorNameRequired() {
|
override fun setErrorNameRequired() {
|
||||||
loginFormNameLayout.run {
|
loginFormNameLayout.run {
|
||||||
requestFocus()
|
requestFocus()
|
||||||
|
@ -35,6 +35,7 @@ class LoginFormPresenter @Inject constructor(
|
|||||||
view?.apply {
|
view?.apply {
|
||||||
clearPassError()
|
clearPassError()
|
||||||
clearNameError()
|
clearNameError()
|
||||||
|
if (formHostValue?.contains("fakelog") == true) setDefaultCredentials("jan@fakelog.cf", "jan123")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +47,11 @@ class LoginFormPresenter @Inject constructor(
|
|||||||
view?.clearNameError()
|
view?.clearNameError()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun attemptLogin(email: String, password: String, endpoint: String) {
|
fun attemptLogin() {
|
||||||
|
val email = view?.formNameValue.orEmpty()
|
||||||
|
val password = view?.formPassValue.orEmpty()
|
||||||
|
val endpoint = view?.formHostValue.orEmpty()
|
||||||
|
|
||||||
if (!validateCredentials(email, password)) return
|
if (!validateCredentials(email, password)) return
|
||||||
|
|
||||||
disposable.add(studentRepository.getStudents(email, password, endpoint)
|
disposable.add(studentRepository.getStudents(email, password, endpoint)
|
||||||
|
@ -7,6 +7,14 @@ interface LoginFormView : BaseView {
|
|||||||
|
|
||||||
fun initView()
|
fun initView()
|
||||||
|
|
||||||
|
val formNameValue: String
|
||||||
|
|
||||||
|
val formPassValue: String
|
||||||
|
|
||||||
|
val formHostValue: String?
|
||||||
|
|
||||||
|
fun setDefaultCredentials(name: String, pass: String)
|
||||||
|
|
||||||
fun setErrorNameRequired()
|
fun setErrorNameRequired()
|
||||||
|
|
||||||
fun setErrorPassRequired(focus: Boolean)
|
fun setErrorPassRequired(focus: Boolean)
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
<item>EduNet Miasta Tarnowa</item>
|
<item>EduNet Miasta Tarnowa</item>
|
||||||
<item>ResMan Rzeszów</item>
|
<item>ResMan Rzeszów</item>
|
||||||
<item>Fakelog</item>
|
<item>Fakelog</item>
|
||||||
<item>Fakelog lokalnie</item>
|
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="endpoints_values">
|
<string-array name="endpoints_values">
|
||||||
<item>https://vulcan.net.pl</item>
|
<item>https://vulcan.net.pl</item>
|
||||||
@ -16,6 +15,5 @@
|
|||||||
<item>https://umt.tarnow.pl</item>
|
<item>https://umt.tarnow.pl</item>
|
||||||
<item>https://resman.pl</item>
|
<item>https://resman.pl</item>
|
||||||
<item>https://fakelog.cf</item>
|
<item>https://fakelog.cf</item>
|
||||||
<item>http://fakelog.localhost:3000</item>
|
|
||||||
</string-array>
|
</string-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -10,6 +10,7 @@ import org.junit.Before
|
|||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.mockito.ArgumentMatchers.anyString
|
import org.mockito.ArgumentMatchers.anyString
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
import org.mockito.Mockito.clearInvocations
|
import org.mockito.Mockito.clearInvocations
|
||||||
import org.mockito.Mockito.doReturn
|
import org.mockito.Mockito.doReturn
|
||||||
import org.mockito.Mockito.never
|
import org.mockito.Mockito.never
|
||||||
@ -49,7 +50,10 @@ class LoginFormPresenterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun emptyNicknameLoginTest() {
|
fun emptyNicknameLoginTest() {
|
||||||
presenter.attemptLogin("", "test123", "https://fakelog.cf")
|
`when`(loginFormView.formNameValue).thenReturn("")
|
||||||
|
`when`(loginFormView.formPassValue).thenReturn("test123")
|
||||||
|
`when`(loginFormView.formHostValue).thenReturn("https://fakelog.cf")
|
||||||
|
presenter.attemptLogin()
|
||||||
|
|
||||||
verify(loginFormView).setErrorNameRequired()
|
verify(loginFormView).setErrorNameRequired()
|
||||||
verify(loginFormView, never()).setErrorPassRequired(false)
|
verify(loginFormView, never()).setErrorPassRequired(false)
|
||||||
@ -58,7 +62,10 @@ class LoginFormPresenterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun emptyPassLoginTest() {
|
fun emptyPassLoginTest() {
|
||||||
presenter.attemptLogin("@", "", "https://fakelog.cf")
|
`when`(loginFormView.formNameValue).thenReturn("@")
|
||||||
|
`when`(loginFormView.formPassValue).thenReturn("")
|
||||||
|
`when`(loginFormView.formHostValue).thenReturn("https://fakelog.cf")
|
||||||
|
presenter.attemptLogin()
|
||||||
|
|
||||||
verify(loginFormView, never()).setErrorNameRequired()
|
verify(loginFormView, never()).setErrorNameRequired()
|
||||||
verify(loginFormView).setErrorPassRequired(true)
|
verify(loginFormView).setErrorPassRequired(true)
|
||||||
@ -67,7 +74,10 @@ class LoginFormPresenterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun invalidPassLoginTest() {
|
fun invalidPassLoginTest() {
|
||||||
presenter.attemptLogin("@", "123", "https://fakelog.cf")
|
`when`(loginFormView.formNameValue).thenReturn("@")
|
||||||
|
`when`(loginFormView.formPassValue).thenReturn("123")
|
||||||
|
`when`(loginFormView.formHostValue).thenReturn("https://fakelog.cf")
|
||||||
|
presenter.attemptLogin()
|
||||||
|
|
||||||
verify(loginFormView, never()).setErrorNameRequired()
|
verify(loginFormView, never()).setErrorNameRequired()
|
||||||
verify(loginFormView, never()).setErrorPassRequired(true)
|
verify(loginFormView, never()).setErrorPassRequired(true)
|
||||||
@ -79,7 +89,11 @@ class LoginFormPresenterTest {
|
|||||||
val studentTest = Student(email = "test@", password = "123", endpoint = "https://fakelog.cf", loginType = "AUTO", studentName = "", schoolSymbol = "", schoolName = "", studentId = 0, isCurrent = false, symbol = "", registrationDate = now())
|
val studentTest = Student(email = "test@", password = "123", endpoint = "https://fakelog.cf", loginType = "AUTO", studentName = "", schoolSymbol = "", schoolName = "", studentId = 0, isCurrent = false, symbol = "", registrationDate = now())
|
||||||
doReturn(Single.just(listOf(studentTest)))
|
doReturn(Single.just(listOf(studentTest)))
|
||||||
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
||||||
presenter.attemptLogin("@", "123456", "https://fakelog.cf")
|
|
||||||
|
`when`(loginFormView.formNameValue).thenReturn("@")
|
||||||
|
`when`(loginFormView.formPassValue).thenReturn("123456")
|
||||||
|
`when`(loginFormView.formHostValue).thenReturn("https://fakelog.cf")
|
||||||
|
presenter.attemptLogin()
|
||||||
|
|
||||||
verify(loginFormView).hideSoftKeyboard()
|
verify(loginFormView).hideSoftKeyboard()
|
||||||
verify(loginFormView).showProgress(true)
|
verify(loginFormView).showProgress(true)
|
||||||
@ -92,7 +106,10 @@ class LoginFormPresenterTest {
|
|||||||
fun loginEmptyTest() {
|
fun loginEmptyTest() {
|
||||||
doReturn(Single.just(emptyList<Student>()))
|
doReturn(Single.just(emptyList<Student>()))
|
||||||
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
||||||
presenter.attemptLogin("@", "123456", "https://fakelog.cf")
|
`when`(loginFormView.formNameValue).thenReturn("@")
|
||||||
|
`when`(loginFormView.formPassValue).thenReturn("123456")
|
||||||
|
`when`(loginFormView.formHostValue).thenReturn("https://fakelog.cf")
|
||||||
|
presenter.attemptLogin()
|
||||||
|
|
||||||
verify(loginFormView).hideSoftKeyboard()
|
verify(loginFormView).hideSoftKeyboard()
|
||||||
verify(loginFormView).showProgress(true)
|
verify(loginFormView).showProgress(true)
|
||||||
@ -105,8 +122,11 @@ class LoginFormPresenterTest {
|
|||||||
fun loginEmptyTwiceTest() {
|
fun loginEmptyTwiceTest() {
|
||||||
doReturn(Single.just(emptyList<Student>()))
|
doReturn(Single.just(emptyList<Student>()))
|
||||||
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
||||||
presenter.attemptLogin("@", "123456", "https://fakelog.cf")
|
`when`(loginFormView.formNameValue).thenReturn("@")
|
||||||
presenter.attemptLogin("@", "123456", "https://fakelog.cf")
|
`when`(loginFormView.formPassValue).thenReturn("123456")
|
||||||
|
`when`(loginFormView.formHostValue).thenReturn("https://fakelog.cf")
|
||||||
|
presenter.attemptLogin()
|
||||||
|
presenter.attemptLogin()
|
||||||
|
|
||||||
verify(loginFormView, times(2)).hideSoftKeyboard()
|
verify(loginFormView, times(2)).hideSoftKeyboard()
|
||||||
verify(loginFormView, times(2)).showProgress(true)
|
verify(loginFormView, times(2)).showProgress(true)
|
||||||
@ -120,7 +140,10 @@ class LoginFormPresenterTest {
|
|||||||
val testException = RuntimeException("test")
|
val testException = RuntimeException("test")
|
||||||
doReturn(Single.error<List<Student>>(testException))
|
doReturn(Single.error<List<Student>>(testException))
|
||||||
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
||||||
presenter.attemptLogin("@", "123456", "https://fakelog.cf")
|
`when`(loginFormView.formNameValue).thenReturn("@")
|
||||||
|
`when`(loginFormView.formPassValue).thenReturn("123456")
|
||||||
|
`when`(loginFormView.formHostValue).thenReturn("https://fakelog.cf")
|
||||||
|
presenter.attemptLogin()
|
||||||
|
|
||||||
verify(loginFormView).hideSoftKeyboard()
|
verify(loginFormView).hideSoftKeyboard()
|
||||||
verify(loginFormView).showProgress(true)
|
verify(loginFormView).showProgress(true)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user