add tests
This commit is contained in:
parent
b84d86acfb
commit
16df4918e2
@ -5,13 +5,7 @@
|
|||||||
<SelectionState runConfigName="app">
|
<SelectionState runConfigName="app">
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
</SelectionState>
|
</SelectionState>
|
||||||
<SelectionState runConfigName="testOtpTextField">
|
<SelectionState runConfigName="EmailValidationTest">
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
|
||||||
</SelectionState>
|
|
||||||
<SelectionState runConfigName="preivewTimerText">
|
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
|
||||||
</SelectionState>
|
|
||||||
<SelectionState runConfigName="PreviewBaseTimerText">
|
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
</SelectionState>
|
</SelectionState>
|
||||||
</selectionStates>
|
</selectionStates>
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
<option value="$PROJECT_DIR$/app" />
|
<option value="$PROJECT_DIR$/app" />
|
||||||
</set>
|
</set>
|
||||||
</option>
|
</option>
|
||||||
|
<option name="resolveExternalAnnotations" value="false" />
|
||||||
</GradleProjectSettings>
|
</GradleProjectSettings>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK" />
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK" />
|
||||||
|
@ -2,23 +2,39 @@ package com.example.netwrok_datastore
|
|||||||
|
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import com.example.netwrok_datastore.domain.validator.EmailValidator
|
||||||
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
|
|
||||||
import org.junit.Assert.*
|
import org.junit.Assert.*
|
||||||
|
import org.junit.runners.Parameterized
|
||||||
|
import org.junit.runners.Parameterized.Parameters
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instrumented test, which will execute on an Android device.
|
* Instrumented test, which will execute on an Android device.
|
||||||
*
|
*
|
||||||
* See [testing documentation](http://d.android.com/tools/testing).
|
* See [testing documentation](http://d.android.com/tools/testing).
|
||||||
*/
|
*/
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(Parameterized::class)
|
||||||
class ExampleInstrumentedTest {
|
class EmailValidationTest(val email: String, val resultTest: Boolean) {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun useAppContext() {
|
fun testValidationEmail(){
|
||||||
// Context of the app under test.
|
|
||||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
val result = EmailValidator().validate(email)
|
||||||
assertEquals("com.example.netwrok_datastore", appContext.packageName)
|
assertEquals(result, resultTest)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
companion object{
|
||||||
|
@JvmStatic
|
||||||
|
@Parameters
|
||||||
|
fun getData() = listOf(
|
||||||
|
arrayOf("test", false),
|
||||||
|
arrayOf("@", false),
|
||||||
|
arrayOf("test@", true),
|
||||||
|
arrayOf("test.ru", false)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ import com.example.netwrok_datastore.data.AuthRepository
|
|||||||
import com.example.netwrok_datastore.data.local.LocalStorage
|
import com.example.netwrok_datastore.data.local.LocalStorage
|
||||||
import com.example.netwrok_datastore.data.remote.NetworkResponse
|
import com.example.netwrok_datastore.data.remote.NetworkResponse
|
||||||
import com.example.netwrok_datastore.data.remote.dto.request.RegistrationRequest
|
import com.example.netwrok_datastore.data.remote.dto.request.RegistrationRequest
|
||||||
|
import com.example.netwrok_datastore.domain.validator.EmailValidator
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
|
|
||||||
@ -13,6 +14,7 @@ class AuthUseCase(private val localStorage: LocalStorage,
|
|||||||
suspend fun registration(registrationRequest: RegistrationRequest): Flow<NetworkResponse> = flow{
|
suspend fun registration(registrationRequest: RegistrationRequest): Flow<NetworkResponse> = flow{
|
||||||
try {
|
try {
|
||||||
emit(NetworkResponse.Loading)
|
emit(NetworkResponse.Loading)
|
||||||
|
if (!EmailValidator().validate(registrationRequest.email)) emit(NetworkResponse.Error("Validation Error"))
|
||||||
val result = authRepository.registration(registrationRequest)
|
val result = authRepository.registration(registrationRequest)
|
||||||
localStorage.setToken(result.second)
|
localStorage.setToken(result.second)
|
||||||
emit(NetworkResponse.Success(result))
|
emit(NetworkResponse.Success(result))
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.example.netwrok_datastore.domain.validator
|
||||||
|
|
||||||
|
class EmailValidator: Validator {
|
||||||
|
override fun <T> validate(value: T): Boolean {
|
||||||
|
val email = value as String
|
||||||
|
return email.contains("@")
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package com.example.netwrok_datastore.domain.validator
|
||||||
|
|
||||||
|
interface Validator {
|
||||||
|
fun <T> validate(value: T): Boolean
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user