Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.bober.notesapp

import com.bober.notesapp.presentation.NotesEndToEndTest
import com.bober.notesapp.presentation.notes.NoteScreenTest
import org.junit.runner.RunWith
import org.junit.runners.Suite

@RunWith(Suite::class)
@Suite.SuiteClasses(
NoteScreenTest::class,
NotesEndToEndTest::class
)
class AllInstrumentationTests
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.bober.notesapp.presentation

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.filterToOne
import androidx.compose.ui.test.hasSetTextAction
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onAllNodesWithText
import androidx.compose.ui.test.onChildren
import androidx.compose.ui.test.onNodeWithContentDescription
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.compose.ui.test.performTextReplacement
import com.bober.notesapp.core.util.TestTags
import com.bober.notesapp.di.AppModule
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import org.junit.Before
import org.junit.Rule
import org.junit.Test

@HiltAndroidTest
@UninstallModules(AppModule::class)
class NotesEndToEndTest {

@get:Rule(order = 0)
val hiltRule = HiltAndroidRule(this)

@get:Rule(order = 1)
val composeRule = createAndroidComposeRule<MainActivity>()

@Before
fun setUp(){
hiltRule.inject()
}

@Test
fun saveNewNote_editAfterwards() {

composeRule.onNodeWithContentDescription("Add Note").performClick()

composeRule.onNodeWithTag(TestTags.TITLE_TEXT_FIELD, useUnmergedTree = true)
.onChildren()
.filterToOne(hasSetTextAction())
.performTextInput("Test Title")

composeRule.onNodeWithTag(TestTags.CONTENT_TEXT_FIELD, useUnmergedTree = true)
.onChildren()
.filterToOne(hasSetTextAction())
.performTextInput("Test Content")

composeRule.onNodeWithContentDescription("Save note").performClick()

composeRule.onNodeWithText("Test Title")
.assertIsDisplayed()
.performClick()

composeRule.onNodeWithTag(TestTags.TITLE_TEXT_FIELD, useUnmergedTree = true)
.onChildren()
.filterToOne(hasSetTextAction())
.assertTextEquals("Test Title")
.performTextReplacement("Test Title 2")

composeRule.onNodeWithContentDescription("Save note").performClick()

composeRule.onNodeWithText("Test Title 2").assertIsDisplayed()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.bober.notesapp.core.util.TestTags
import com.bober.notesapp.di.AppModule
import com.bober.notesapp.domain.model.Note
import com.bober.notesapp.domain.repository.NoteRepository
import com.bober.notesapp.presentation.MainActivity
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import javax.inject.Inject

@HiltAndroidTest
@UninstallModules(AppModule::class)
Expand All @@ -31,9 +35,11 @@ class NoteScreenTest {
@get:Rule(order = 1)
val composeRule = createAndroidComposeRule<MainActivity>()

@Inject
lateinit var repository: NoteRepository

@Before
fun setUp(){

hiltRule.inject()
}

Expand Down Expand Up @@ -66,4 +72,19 @@ class NoteScreenTest {
composeRule.onNodeWithContentDescription("Add Note").performClick()
composeRule.onNodeWithText("Enter title...").assertIsDisplayed()
}

@Test
fun deleteNote_isRemovedFromDatabase() = runBlocking {
val note = Note(title = "test", content = "content", timestamp = 1L, color = 1, id = 1)
repository.insertNote(note)

composeRule.onNodeWithText("test").assertIsDisplayed()

composeRule.onNodeWithContentDescription("Delete note test").performClick()

composeRule.onNodeWithText("test").assertDoesNotExist()

val dbNote = repository.getNoteById(1)
assert(dbNote == null)
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/com/bober/notesapp/core/util/TestTags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ object TestTags {

const val ORDER_SECTION = "ORDER_SECTION"
const val TITLE_RADIO_BUTTON = "TITLE_RADIO_BUTTON"
const val TITLE_TEXT_FIELD = "TITLE_TEXT_FIELD"
const val CONTENT_TEXT_FIELD = "CONTENT_TEXT_FIELD"
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
import com.bober.notesapp.core.util.TestTags
import com.bober.notesapp.domain.model.Note
import com.bober.notesapp.presentation.add_edit_note.components.TransparentHintTextField
import kotlinx.coroutines.flow.collectLatest
Expand Down Expand Up @@ -165,7 +167,8 @@ fun AddEditNoteScreenContent(
onFocusChange = { onEvent(AddEditNoteEvent.ChangeTitleFocus(it)) },
isHintVisible = titleState.isHintVisible,
singleLine = true,
textStyle = MaterialTheme.typography.headlineMedium
textStyle = MaterialTheme.typography.headlineMedium,
modifier = Modifier.testTag(TestTags.TITLE_TEXT_FIELD)
)
Spacer(modifier = Modifier.height(16.dp))
TransparentHintTextField(
Expand All @@ -175,7 +178,9 @@ fun AddEditNoteScreenContent(
onFocusChange = { onEvent(AddEditNoteEvent.ChangeContentFocus(it)) },
isHintVisible = contentState.isHintVisible,
textStyle = MaterialTheme.typography.bodyLarge,
modifier = Modifier.fillMaxHeight()
modifier = Modifier
.fillMaxHeight()
.testTag(TestTags.CONTENT_TEXT_FIELD)
)
}
}
Expand Down
Loading