forked from github/wulkanowy-mirror
Split login form for two fragments (#230)
This commit is contained in:

committed by
Mikołaj Pich

parent
2f87779647
commit
1b1f2ae3bb
@ -1,7 +1,7 @@
|
||||
package io.github.wulkanowy.data.repositories.remote
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.api.register.Pupil
|
||||
import io.github.wulkanowy.api.register.Student
|
||||
import io.reactivex.Single
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
@ -22,8 +22,8 @@ class StudentRemoteTest {
|
||||
|
||||
@Test
|
||||
fun testRemoteAll() {
|
||||
doReturn(Single.just(listOf(Pupil("", "", 1, "test", "", "", "", Api.LoginType.AUTO))))
|
||||
.`when`(mockApi).getPupils()
|
||||
doReturn(Single.just(listOf(Student("", "", 1, "test", "", "", Api.LoginType.AUTO))))
|
||||
.`when`(mockApi).getStudents()
|
||||
|
||||
val students = StudentRemote(mockApi).getStudents("", "", "").blockingGet()
|
||||
assertEquals(1, students.size)
|
||||
|
@ -6,7 +6,6 @@ import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.clearInvocations
|
||||
import org.mockito.Mockito.doReturn
|
||||
import org.mockito.Mockito.never
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
@ -32,25 +31,7 @@ class LoginPresenterTest {
|
||||
@Test
|
||||
fun initViewTest() {
|
||||
verify(loginView).initAdapter()
|
||||
verify(loginView).hideActionBar()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onPageSelectedTest() {
|
||||
presenter.onPageSelected(1)
|
||||
verify(loginView).notifyOptionsViewLoadData()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onPageSelectedNeverTest() {
|
||||
presenter.onPageSelected(0)
|
||||
verify(loginView, never()).notifyOptionsViewLoadData()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onSwitchFragmentTest() {
|
||||
presenter.onChildViewSwitchOptions()
|
||||
verify(loginView).switchView(1)
|
||||
verify(loginView).showActionBar(false)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -59,7 +40,6 @@ class LoginPresenterTest {
|
||||
doReturn(1).`when`(loginView).currentViewIndex
|
||||
presenter.onBackPressed { }
|
||||
verify(loginView).switchView(0)
|
||||
verify(loginView).hideActionBar()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -37,7 +37,7 @@ class LoginFormPresenterTest {
|
||||
fun initPresenter() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
clearInvocations(repository, loginFormView)
|
||||
presenter = LoginFormPresenter(TestSchedulersProvider(), errorHandler, repository, analytics)
|
||||
presenter = LoginFormPresenter(TestSchedulersProvider(), errorHandler, repository, analytics, false)
|
||||
presenter.onAttachView(loginFormView)
|
||||
}
|
||||
|
||||
@ -48,87 +48,70 @@ class LoginFormPresenterTest {
|
||||
|
||||
@Test
|
||||
fun emptyNicknameLoginTest() {
|
||||
presenter.attemptLogin("", "test123", "test", "https://fakelog.cf")
|
||||
presenter.attemptLogin("", "test123", "https://fakelog.cf")
|
||||
|
||||
verify(loginFormView).setErrorNicknameRequired()
|
||||
verify(loginFormView).setErrorNameRequired()
|
||||
verify(loginFormView, never()).setErrorPassRequired(false)
|
||||
verify(loginFormView, never()).setErrorSymbolRequire()
|
||||
verify(loginFormView, never()).setErrorPassInvalid(false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun emptyPassLoginTest() {
|
||||
presenter.attemptLogin("@", "", "test", "https://fakelog.cf")
|
||||
presenter.attemptLogin("@", "", "https://fakelog.cf")
|
||||
|
||||
verify(loginFormView, never()).setErrorNicknameRequired()
|
||||
verify(loginFormView, never()).setErrorNameRequired()
|
||||
verify(loginFormView).setErrorPassRequired(true)
|
||||
verify(loginFormView, never()).setErrorSymbolRequire()
|
||||
verify(loginFormView, never()).setErrorPassInvalid(false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun invalidPassLoginTest() {
|
||||
presenter.attemptLogin("@", "123", "test", "https://fakelog.cf")
|
||||
presenter.attemptLogin("@", "123", "https://fakelog.cf")
|
||||
|
||||
verify(loginFormView, never()).setErrorNicknameRequired()
|
||||
verify(loginFormView, never()).setErrorNameRequired()
|
||||
verify(loginFormView, never()).setErrorPassRequired(true)
|
||||
verify(loginFormView, never()).setErrorSymbolRequire()
|
||||
verify(loginFormView).setErrorPassInvalid(true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun emptySymbolLoginTest() {
|
||||
doReturn(Single.just(emptyList<Student>()))
|
||||
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
||||
presenter.attemptLogin("@", "123456", "", "https://fakelog.cf")
|
||||
presenter.attemptLogin("@", "123456", "", "https://fakelog.cf")
|
||||
|
||||
verify(loginFormView).setErrorSymbolRequire()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun loginTest() {
|
||||
val studentTest = Student(email = "test@", password = "123", endpoint = "https://fakelog.cf", loginType = "AUTO")
|
||||
doReturn(Single.just(listOf(studentTest)))
|
||||
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
||||
presenter.attemptLogin("@", "123456", "test", "https://fakelog.cf")
|
||||
presenter.attemptLogin("@", "123456", "https://fakelog.cf")
|
||||
|
||||
verify(loginFormView).hideSoftKeyboard()
|
||||
verify(loginFormView).showProgress(true)
|
||||
verify(loginFormView).showProgress(false)
|
||||
verify(loginFormView).showContent(false)
|
||||
verify(loginFormView).showContent(true)
|
||||
verify(loginFormView).switchOptionsView()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun loginEmptyTest() {
|
||||
doReturn(Single.just(emptyList<Student>()))
|
||||
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
||||
presenter.attemptLogin("@", "123456", "test", "https://fakelog.cf")
|
||||
presenter.attemptLogin("@", "123456", "https://fakelog.cf")
|
||||
|
||||
verify(loginFormView).hideSoftKeyboard()
|
||||
verify(loginFormView).showProgress(true)
|
||||
verify(loginFormView).showProgress(false)
|
||||
verify(loginFormView).showContent(false)
|
||||
verify(loginFormView).showContent(true)
|
||||
verify(loginFormView).showSymbolInput()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun loginEmptyTwiceTest() {
|
||||
doReturn(Single.just(emptyList<Student>()))
|
||||
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
||||
presenter.attemptLogin("@", "123456", "", "https://fakelog.cf")
|
||||
presenter.attemptLogin("@", "123456", "test", "https://fakelog.cf")
|
||||
presenter.attemptLogin("@", "123456", "https://fakelog.cf")
|
||||
presenter.attemptLogin("@", "123456", "https://fakelog.cf")
|
||||
|
||||
verify(loginFormView, times(2)).hideSoftKeyboard()
|
||||
verify(loginFormView, times(2)).showProgress(true)
|
||||
verify(loginFormView, times(2)).showProgress(false)
|
||||
verify(loginFormView, times(2)).showContent(false)
|
||||
verify(loginFormView, times(2)).showContent(true)
|
||||
verify(loginFormView, times(2)).showSymbolInput()
|
||||
verify(loginFormView).setErrorSymbolIncorrect()
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -136,7 +119,7 @@ class LoginFormPresenterTest {
|
||||
val testException = RuntimeException("test")
|
||||
doReturn(Single.error<List<Student>>(testException))
|
||||
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
||||
presenter.attemptLogin("@", "123456", "test", "https://fakelog.cf")
|
||||
presenter.attemptLogin("@", "123456", "https://fakelog.cf")
|
||||
|
||||
verify(loginFormView).hideSoftKeyboard()
|
||||
verify(loginFormView).showProgress(true)
|
||||
|
@ -1,4 +1,4 @@
|
||||
package io.github.wulkanowy.ui.modules.login.options
|
||||
package io.github.wulkanowy.ui.modules.login.studentselect
|
||||
|
||||
import io.github.wulkanowy.TestSchedulersProvider
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
@ -17,13 +17,13 @@ import org.mockito.Mockito.doReturn
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
class LoginOptionsPresenterTest {
|
||||
class LoginStudentSelectPresenterTest {
|
||||
|
||||
@Mock
|
||||
lateinit var errorHandler: LoginErrorHandler
|
||||
|
||||
@Mock
|
||||
lateinit var loginOptionsView: LoginOptionsView
|
||||
lateinit var loginStudentSelectView: LoginStudentSelectView
|
||||
|
||||
@Mock
|
||||
lateinit var studentRepository: StudentRepository
|
||||
@ -34,7 +34,7 @@ class LoginOptionsPresenterTest {
|
||||
@Mock
|
||||
lateinit var analytics: FirebaseAnalyticsHelper
|
||||
|
||||
private lateinit var presenter: LoginOptionsPresenter
|
||||
private lateinit var presenter: LoginStudentSelectPresenter
|
||||
|
||||
private val testStudent by lazy { Student(email = "test", password = "test123", endpoint = "https://fakelog.cf", loginType = "AUTO") }
|
||||
|
||||
@ -43,31 +43,15 @@ class LoginOptionsPresenterTest {
|
||||
@Before
|
||||
fun initPresenter() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
clearInvocations(studentRepository, loginOptionsView)
|
||||
clearInvocations(semesterRepository, loginOptionsView)
|
||||
presenter = LoginOptionsPresenter(errorHandler, studentRepository, semesterRepository, TestSchedulersProvider(), analytics)
|
||||
presenter.onAttachView(loginOptionsView)
|
||||
clearInvocations(studentRepository, loginStudentSelectView)
|
||||
clearInvocations(semesterRepository, loginStudentSelectView)
|
||||
presenter = LoginStudentSelectPresenter(errorHandler, studentRepository, semesterRepository, TestSchedulersProvider(), analytics)
|
||||
presenter.onAttachView(loginStudentSelectView, null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun initViewTest() {
|
||||
verify(loginOptionsView).initView()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun refreshDataTest() {
|
||||
doReturn(Single.just(listOf(testStudent))).`when`(studentRepository).cachedStudents
|
||||
presenter.onParentViewLoadData()
|
||||
verify(loginOptionsView).showActionBar(true)
|
||||
verify(loginOptionsView).updateData(listOf(LoginOptionsItem(testStudent)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun refreshDataErrorTest() {
|
||||
doReturn(Single.error<List<Student>>(testException)).`when`(studentRepository).cachedStudents
|
||||
presenter.onParentViewLoadData()
|
||||
verify(loginOptionsView).showActionBar(true)
|
||||
verify(errorHandler).dispatch(testException)
|
||||
verify(loginStudentSelectView).initView()
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -75,10 +59,10 @@ class LoginOptionsPresenterTest {
|
||||
doReturn(Single.just(1L)).`when`(studentRepository).saveStudent(testStudent)
|
||||
doReturn(Single.just(emptyList<Semester>())).`when`(semesterRepository).getSemesters(testStudent, true)
|
||||
doReturn(Completable.complete()).`when`(studentRepository).switchStudent(testStudent)
|
||||
presenter.onItemSelected(LoginOptionsItem(testStudent))
|
||||
verify(loginOptionsView).showContent(false)
|
||||
verify(loginOptionsView).showProgress(true)
|
||||
verify(loginOptionsView).openMainView()
|
||||
presenter.onItemSelected(LoginStudentSelectItem(testStudent))
|
||||
verify(loginStudentSelectView).showContent(false)
|
||||
verify(loginStudentSelectView).showProgress(true)
|
||||
verify(loginStudentSelectView).openMainView()
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -86,9 +70,9 @@ class LoginOptionsPresenterTest {
|
||||
doReturn(Single.error<Student>(testException)).`when`(studentRepository).saveStudent(testStudent)
|
||||
doReturn(Single.just(emptyList<Semester>())).`when`(semesterRepository).getSemesters(testStudent, true)
|
||||
doReturn(Completable.complete()).`when`(studentRepository).logoutStudent(testStudent)
|
||||
presenter.onItemSelected(LoginOptionsItem(testStudent))
|
||||
verify(loginOptionsView).showContent(false)
|
||||
verify(loginOptionsView).showProgress(true)
|
||||
presenter.onItemSelected(LoginStudentSelectItem(testStudent))
|
||||
verify(loginStudentSelectView).showContent(false)
|
||||
verify(loginStudentSelectView).showProgress(true)
|
||||
verify(errorHandler).dispatch(testException)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user