Skip to content

Commit

Permalink
Testing add notes
Browse files Browse the repository at this point in the history
  • Loading branch information
leandroBorgesFerreira committed Jul 8, 2023
1 parent eed4b8b commit bc9a297
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 25 deletions.
14 changes: 14 additions & 0 deletions .idea/androidTestResultsUserPreferences.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 30 additions & 1 deletion .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ androidx-espresso-core = { module = "androidx.test.espresso:espresso-core", vers
androidx-junit = { module = "androidx.test.ext:junit", version.ref = "junit" }
androidx-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "ktx" }
androidx-material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "materialIconsExtended" }
androidx-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4", version.ref = "junit4-compose" }
androidx-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest", version.ref = "junit4-compose" }
appCompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appCompat" }
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coilVersion" }
coil-video = { module = "io.coil-kt:coil-video", version.ref = "coilVersion" }
Expand All @@ -36,5 +34,7 @@ room-testing = { group = "androidx.room", name = "room-testing", version.ref = "
viewmodel-compose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "compose" }
runtime-compose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "compose" }
navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigation-compose" }
androidx-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4", version.ref = "junit4-compose" }
androidx-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest", version.ref = "junit4-compose" }

[plugins]
7 changes: 5 additions & 2 deletions sample/app_sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ dependencies {
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.test.manifest)
// androidTestImplementation(libs.androidx.ui.test.junit4)
// debugImplementation(libs.androidx.ui.test.manifest)

androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.4.3")
debugImplementation("androidx.compose.ui:ui-test-manifest:1.4.3")
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
package br.com.leandroferreira.app_sample

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import br.com.leandroferreira.app_sample.navigation.NavigationGraph
import org.junit.Rule
import org.junit.Test
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.espresso.Espresso
import br.com.leandroferreira.app_sample.navigation.NavigationActivity
import java.lang.Thread.sleep

class NoteMenuAndroidTest {

@get:Rule
val composeTestRule = createAndroidComposeRule<NavigationActivity>()
val composeTestRule = createComposeRule()

@Test
fun myTest() {
composeTestRule.setContent {
NavigationGraph()
}

composeTestRule.onNodeWithTag("addNote").performClick()

composeTestRule.onNodeWithTag("noteEditionScreenTitle").assertIsDisplayed()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.navigation.NavController
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
Expand All @@ -32,7 +33,6 @@ class NavigationActivity : AppCompatActivity() {

@Composable
fun NavigationGraph() {

val navController = rememberNavController()
val context = LocalContext.current
val database = StoryTellerDatabase.database(context)
Expand All @@ -48,11 +48,11 @@ fun NavigationGraph() {
composable(Destinations.CHOOSE_NOTE.id) {
val chooseNoteViewModel = notesInjection.provideChooseNoteViewModel()

ChooseNoteScreen(chooseNoteViewModel = chooseNoteViewModel) { noteId, noteTitle ->
navController.navigate(
"${Destinations.NOTE_DETAILS.id}/$noteId/$noteTitle"
)
}
ChooseNoteScreen(
chooseNoteViewModel = chooseNoteViewModel,
navigateToNote = navController::navigateToNote,
newNote = navController::navigateToNewNote
)
}

composable(
Expand All @@ -74,13 +74,36 @@ fun NavigationGraph() {
}
)
} else {
throw IllegalArgumentException("Wrong route!")
throw IllegalArgumentException("The arguments for this route are wrong!")
}
}

composable(route = Destinations.NOTE_DETAILS.id) {
NoteDetailsScreen(
documentId = null,
title = null,
noteDetailsViewModel = notesInjection.provideNoteDetailsViewModel(),
navigateBack = {
navController.navigateUp()
}
)
}
}
}
}

private fun NavController.navigateToNote(id: String, title: String) {
navigate(
"${Destinations.NOTE_DETAILS.id}/$id/$title"
)
}

private fun NavController.navigateToNewNote() {
navigate(
Destinations.NOTE_DETAILS.id
)
}

enum class Destinations(val id: String) {
NOTE_DETAILS("note_details"),
CHOOSE_NOTE("choose_note"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTag
import androidx.compose.ui.unit.dp
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
Expand Down Expand Up @@ -72,6 +74,9 @@ fun NoteDetailsScreen(
TopAppBar(
title = {
Text(
modifier = Modifier.semantics {
testTag = "noteEditionScreenTitle"
},
text = title?.takeIf { it.isNotBlank() }
?: stringResource(id = R.string.note),
color = MaterialTheme.colorScheme.onPrimary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTag
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import br.com.leandroferreira.resourcers.R
import br.com.leandroferreira.utils.ResultData
import br.com.leandroferreira.note_menu.ui.dto.DocumentCard
import br.com.leandroferreira.note_menu.viewmodel.ChooseNoteViewModel
Expand All @@ -59,7 +63,8 @@ private fun previewDrawers(): Map<String, StoryUnitDrawer> =
@Composable
fun ChooseNoteScreen(
chooseNoteViewModel: ChooseNoteViewModel,
navigateToNote: (String?, String?) -> Unit
navigateToNote: (String, String) -> Unit,
newNote: () -> Unit
) {
chooseNoteViewModel.requestDocuments()

Expand All @@ -80,20 +85,23 @@ fun ChooseNoteScreen(
.clickable(onClick = chooseNoteViewModel::editMenu)
.padding(10.dp),
imageVector = Icons.Default.MoreVert,
contentDescription = "",// stringResource(R.string.more_options),
contentDescription = stringResource(R.string.more_options),
tint = MaterialTheme.colorScheme.onPrimary
)
}
)
},
floatingActionButton = {
FloatingActionButton(
modifier = Modifier.semantics {
testTag = "addNote"
},
containerColor = MaterialTheme.colorScheme.primary,
onClick = { navigateToNote(null, null) },
onClick = newNote,
content = {
Icon(
imageVector = Icons.Default.Add,
contentDescription = ""// stringResource(R.string.add_note)
contentDescription = stringResource(R.string.add_note)
)
}
)
Expand Down Expand Up @@ -141,7 +149,7 @@ private fun Notes(
) {
when (val documents =
chooseNoteViewModel.documentsState.collectAsStateWithLifecycle().value) {
is br.com.leandroferreira.utils.ResultData.Complete -> {
is ResultData.Complete -> {
Column(modifier = Modifier.fillMaxWidth()) {
val data = documents.data

Expand All @@ -168,7 +176,7 @@ private fun Notes(
}
}

is br.com.leandroferreira.utils.ResultData.Error -> {
is ResultData.Error -> {
Box(modifier = Modifier.fillMaxSize()) {
Text(
modifier = Modifier.align(Alignment.Center),
Expand All @@ -177,7 +185,7 @@ private fun Notes(
}
}

is br.com.leandroferreira.utils.ResultData.Loading, is br.com.leandroferreira.utils.ResultData.Idle -> {
is ResultData.Loading, is ResultData.Idle -> {
Box(modifier = Modifier.fillMaxSize()) {
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
}
Expand Down Expand Up @@ -265,12 +273,12 @@ private fun MockDataScreen(chooseNoteViewModel: ChooseNoteViewModel) {
) {
Text(
modifier = Modifier.padding(8.dp),
text = ""// stringResource(R.string.you_dont_have_notes)
text = stringResource(R.string.you_dont_have_notes)
)
Button(onClick = {
chooseNoteViewModel.addMockData(context)
}) {
Text(text = "")// stringResource(R.string.add_sample_notes))
Text(text = stringResource(R.string.add_sample_notes))
}
}
}
Expand Down

0 comments on commit bc9a297

Please sign in to comment.