-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: Task 6 completed #6
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3071d12
feat (accessibility): icons setup, rows union
Gribbirg df4d54d
docs: wakatime badge add
Gribbirg 4c863ea
feat(accessibility): divkit screen
Gribbirg 4f63586
fix: sizes for big font size
Gribbirg 580854d
feat: animated toolbar to core/ui and add to other screens
Gribbirg 51135ea
fix: animated app bar colors on theme changed
Gribbirg a040fd6
test: for utils
Gribbirg 4f56af3
test: for network
Gribbirg 6f112b2
test: for db
Gribbirg 30ec7b1
test: for data
Gribbirg b22d091
test: for settings feature
Gribbirg 74bdd22
test: for edit item feature
Gribbirg 5efbd2c
test: for ist feature
Gribbirg f3a2eb9
test: ui testing
Gribbirg 4222db1
feat: update items using semantics actions
Gribbirg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,93 @@ | ||
package ru.gribbirg.todoapp | ||
|
||
import androidx.compose.ui.test.ExperimentalTestApi | ||
import androidx.compose.ui.test.hasTestTag | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onChildAt | ||
import androidx.compose.ui.test.onNodeWithTag | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performClick | ||
import androidx.compose.ui.test.performTextInput | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import ru.gribbirg.edit.testing.EditFeatureTestingTags | ||
import ru.gribbirg.list.testing.ListFeatureTestingTags | ||
import ru.gribbirg.todoapp.app.TestApplication | ||
import ru.gribbirg.todoapp.di.TestAppComponent | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class AppUiTest { | ||
|
||
private val dispatcher = Dispatchers.IO | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
private lateinit var appComponent: TestAppComponent | ||
|
||
@Before | ||
fun setContent() { | ||
val context = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext | ||
appComponent = (context as TestApplication).testAppComponent | ||
runBlocking { | ||
appComponent.loginRepo.registerUser("1") | ||
} | ||
composeTestRule.setContent { | ||
TodoComposeApp(appComponent) | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalTestApi::class) | ||
@Test | ||
fun addItem() { | ||
CoroutineScope(dispatcher).launch { | ||
delay(1000) | ||
composeTestRule.awaitIdle() | ||
composeTestRule.waitUntilAtLeastOneExists( | ||
hasTestTag( | ||
ListFeatureTestingTags.getItemRowId( | ||
"1" | ||
) | ||
) | ||
) | ||
|
||
composeTestRule.onNodeWithTag(ListFeatureTestingTags.ADD_BUTTON).performClick() | ||
composeTestRule.onNodeWithTag(EditFeatureTestingTags.TEXT_FIELD) | ||
.performTextInput("Test task") | ||
composeTestRule.onNodeWithTag(EditFeatureTestingTags.SAVE_BUTTON).performClick() | ||
|
||
composeTestRule.onNodeWithText("Test task").assertExists() | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalTestApi::class) | ||
@Test | ||
fun deleteItem() { | ||
CoroutineScope(dispatcher).launch { | ||
delay(1000) | ||
composeTestRule.awaitIdle() | ||
composeTestRule.waitUntilAtLeastOneExists( | ||
hasTestTag( | ||
ListFeatureTestingTags.getItemRowId( | ||
"1" | ||
) | ||
) | ||
) | ||
|
||
composeTestRule.onNodeWithTag(ListFeatureTestingTags.getItemRowId("1")).onChildAt(2) | ||
.performClick() | ||
composeTestRule.onNodeWithTag(EditFeatureTestingTags.DELETE_BUTTON).performClick() | ||
|
||
composeTestRule.onNodeWithTag("1").assertDoesNotExist() | ||
} | ||
} | ||
} |
24 changes: 0 additions & 24 deletions
24
app/src/androidTest/java/ru/gribbirg/todoapp/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
app/src/androidTest/java/ru/gribbirg/todoapp/app/TestApplication.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,13 @@ | ||
package ru.gribbirg.todoapp.app | ||
|
||
import android.app.Application | ||
import ru.gribbirg.todoapp.di.DaggerTestAppComponent | ||
import ru.gribbirg.todoapp.di.TestAppComponent | ||
|
||
class TestApplication : Application() { | ||
internal val testAppComponent: TestAppComponent by lazy { | ||
DaggerTestAppComponent | ||
.factory() | ||
.create(applicationContext) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/androidTest/java/ru/gribbirg/todoapp/app/TestRunner.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,15 @@ | ||
package ru.gribbirg.todoapp.app | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import androidx.test.runner.AndroidJUnitRunner | ||
|
||
class TestRunner : AndroidJUnitRunner() { | ||
override fun newApplication( | ||
cl: ClassLoader?, | ||
className: String?, | ||
context: Context? | ||
): Application { | ||
return super.newApplication(cl, TestApplication::class.java.name, context) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
app/src/androidTest/java/ru/gribbirg/todoapp/di/TestAppComponent.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,45 @@ | ||
package ru.gribbirg.todoapp.di | ||
|
||
import android.content.Context | ||
import dagger.BindsInstance | ||
import dagger.Component | ||
import ru.gribbirg.data.di.DataScope | ||
import ru.gribbirg.domain.repositories.LoginRepository | ||
import ru.gribbirg.network.di.modules.ApiClientScope | ||
import ru.gribbirg.todoapp.di.modules.AboutFeatureModule | ||
import ru.gribbirg.todoapp.di.modules.DataModule | ||
import ru.gribbirg.todoapp.di.modules.EditFeatureModule | ||
import ru.gribbirg.todoapp.di.modules.ListFeatureModule | ||
import ru.gribbirg.todoapp.di.modules.TestAppModule | ||
import ru.gribbirg.todoapp.di.modules.TestDataModule | ||
import ru.gribbirg.todoapp.di.modules.TestNetworkModule | ||
import ru.gribbirg.todoapp.di.modules.UtilsModule | ||
import ru.gribbirg.utils.di.modules.AppSettingsScope | ||
|
||
|
||
@Component( | ||
modules = [ | ||
DataModule::class, | ||
ListFeatureModule::class, | ||
EditFeatureModule::class, | ||
UtilsModule::class, | ||
AboutFeatureModule::class, | ||
TestNetworkModule::class, | ||
TestAppModule::class, | ||
TestDataModule::class, | ||
] | ||
) | ||
@DataScope | ||
@AppScope | ||
@ApiClientScope | ||
@AppSettingsScope | ||
internal interface TestAppComponent : AppComponent { | ||
@Component.Factory | ||
interface Factory { | ||
fun create( | ||
@BindsInstance context: Context | ||
): TestAppComponent | ||
} | ||
|
||
val loginRepo: LoginRepository | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/androidTest/java/ru/gribbirg/todoapp/di/modules/TestAppModule.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,12 @@ | ||
package ru.gribbirg.todoapp.di.modules | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import ru.gribbirg.todoapp.di.AppComponent | ||
import ru.gribbirg.todoapp.di.TestAppComponent | ||
|
||
@Module | ||
internal interface TestAppModule { | ||
@Binds | ||
fun appComponent(testAppComponent: TestAppComponent): AppComponent | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/androidTest/java/ru/gribbirg/todoapp/di/modules/TestDataModule.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,16 @@ | ||
package ru.gribbirg.todoapp.di.modules | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import ru.gribbirg.data.di.DataFactory | ||
import ru.gribbirg.data.di.DataScope | ||
import ru.gribbirg.domain.repositories.LoginRepository | ||
|
||
@Module | ||
interface TestDataModule { | ||
companion object { | ||
@Provides | ||
@DataScope | ||
fun loginRepo(factory: DataFactory): LoginRepository = factory.createLoginRepository() | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/androidTest/java/ru/gribbirg/todoapp/di/modules/TestNetworkModule.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,14 @@ | ||
package ru.gribbirg.todoapp.di.modules | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import io.ktor.client.engine.HttpClientEngine | ||
import ru.gribbirg.todoapp.network.mockEngine | ||
|
||
@Module | ||
internal interface TestNetworkModule { | ||
companion object { | ||
@Provides | ||
fun httpClientEngine(): HttpClientEngine = mockEngine | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
app/src/androidTest/java/ru/gribbirg/todoapp/network/MockHttpEngine.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,100 @@ | ||
package ru.gribbirg.todoapp.network | ||
|
||
import io.ktor.client.engine.mock.MockEngine | ||
import io.ktor.client.engine.mock.respond | ||
import io.ktor.http.HttpHeaders | ||
import io.ktor.http.HttpMethod | ||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.http.headers | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
import ru.gribbirg.domain.model.todo.TodoImportance | ||
import ru.gribbirg.domain.model.todo.TodoItem | ||
import ru.gribbirg.network.dto.TodoItemResponseDto | ||
import ru.gribbirg.network.dto.TodoListResponseDto | ||
import ru.gribbirg.network.dto.toNetworkDto | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
|
||
internal val mockEngine = | ||
MockEngine { request -> | ||
when (request.url.pathSegments.last()) { | ||
"list" -> when (request.method) { | ||
HttpMethod.Get, HttpMethod.Patch -> respond( | ||
content = Json.encodeToString( | ||
TodoListResponseDto( | ||
status = "ok", | ||
revision = 1, | ||
list = items | ||
) | ||
), | ||
status = HttpStatusCode.OK, | ||
headers = headers, | ||
) | ||
|
||
HttpMethod.Post -> respond( | ||
content = Json.encodeToString( | ||
TodoItemResponseDto( | ||
status = "ok", | ||
revision = 2, | ||
element = extraItem, | ||
) | ||
), | ||
status = HttpStatusCode.OK, | ||
headers = headers | ||
) | ||
|
||
HttpMethod.Put -> respond( | ||
content = Json.encodeToString( | ||
TodoItemResponseDto( | ||
status = "ok", | ||
revision = 2, | ||
element = firstEdited, | ||
) | ||
), | ||
status = HttpStatusCode.OK, | ||
headers = headers | ||
) | ||
|
||
else -> respond( | ||
content = "", | ||
status = HttpStatusCode.NotFound, | ||
headers = headers | ||
) | ||
} | ||
|
||
else -> respond( | ||
content = "", | ||
status = HttpStatusCode.NotFound, | ||
headers = headers | ||
) | ||
} | ||
} | ||
|
||
|
||
private val headers = headers { | ||
append( | ||
HttpHeaders.ContentType, | ||
"application/json; charset=utf-8" | ||
) | ||
} | ||
|
||
val items = List(5) { | ||
TodoItem( | ||
id = it.toString(), | ||
text = "Дело $it ".repeat(it * 5 + 1), | ||
importance = TodoImportance.entries[it % 3], | ||
deadline = if (it % 3 == 0) | ||
null | ||
else LocalDate.now().plusDays((-100L..100L).random()), | ||
completed = it % 4 == 0, | ||
creationDate = LocalDateTime.now().minusDays((-0L..100L).random()), | ||
editDate = LocalDateTime.now().minusDays((-0L..100L).random()), | ||
).toNetworkDto("1") | ||
} | ||
|
||
val extraItem = TodoItem( | ||
id = "-1", | ||
).toNetworkDto("1") | ||
|
||
val firstEdited = items.first().copy(text = "New text") |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
задержка избыточна, тк следующей строкой дожидаешься окончания всех корутин. ниже также