From 20de929b48bf15df560948a9dc4a4dbac53d0226 Mon Sep 17 00:00:00 2001 From: Francesco Romano Date: Thu, 20 Nov 2025 23:12:05 +0100 Subject: [PATCH 1/3] added tests to verify state preservation in TextNoteCanvasScreen --- .../java/com/example/cahier/CahierAppTest.kt | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/app/src/androidTest/java/com/example/cahier/CahierAppTest.kt b/app/src/androidTest/java/com/example/cahier/CahierAppTest.kt index b1eba1e..fc8d7a9 100644 --- a/app/src/androidTest/java/com/example/cahier/CahierAppTest.kt +++ b/app/src/androidTest/java/com/example/cahier/CahierAppTest.kt @@ -21,10 +21,15 @@ package com.example.cahier +import androidx.compose.ui.test.filterToOne +import androidx.compose.ui.test.hasSetTextAction import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onAllNodesWithContentDescription +import androidx.compose.ui.test.onChildren import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performImeAction +import androidx.compose.ui.test.performTextInput import androidx.compose.ui.test.performClick import androidx.test.ext.junit.runners.AndroidJUnit4 import dagger.hilt.android.testing.HiltAndroidRule @@ -32,6 +37,7 @@ import dagger.hilt.android.testing.HiltAndroidTest import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import androidx.compose.ui.test.hasText @RunWith(AndroidJUnit4::class) @HiltAndroidTest @@ -84,4 +90,31 @@ class CahierAppTest { composeTestRule.onNodeWithText("Title", useUnmergedTree = true).assertExists() composeTestRule.onNodeWithText("Note", useUnmergedTree = true).assertExists() } + + @Test + fun textNoteCanvasScreen_savedState() { + composeTestRule.waitUntil(timeoutMillis = 5000) { + composeTestRule + .onAllNodesWithContentDescription("Add note") + .fetchSemanticsNodes().size == 1 + } + + composeTestRule.onNodeWithContentDescription("Add note").performClick() + composeTestRule.onNodeWithContentDescription("Text note").performClick() + + val titleText = "My test title" + composeTestRule.onNode(hasSetTextAction() and hasText("Title")) + .performTextInput(titleText) + + val noteText = "This is a test note." + composeTestRule.onNode(hasSetTextAction() and hasText("Note")) + .performTextInput(noteText) + + // Recreate the activity + composeTestRule.activityRule.scenario.recreate() + + // Verify the text is still there + composeTestRule.onNodeWithText(titleText, useUnmergedTree = true).assertExists() + composeTestRule.onNodeWithText(noteText, useUnmergedTree = true).assertExists() + } } From 605d7fdaf4919f1fcbf39ef77274ab1cf32ce462 Mon Sep 17 00:00:00 2001 From: Francesco Romano Date: Thu, 20 Nov 2025 23:12:05 +0100 Subject: [PATCH 2/3] added tests to verify state preservation in TextNoteCanvasScreen # Conflicts: # app/src/androidTest/java/com/example/cahier/CahierAppTest.kt --- .../java/com/example/cahier/CahierAppTest.kt | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/androidTest/java/com/example/cahier/CahierAppTest.kt b/app/src/androidTest/java/com/example/cahier/CahierAppTest.kt index fc8d7a9..0b97b5a 100644 --- a/app/src/androidTest/java/com/example/cahier/CahierAppTest.kt +++ b/app/src/androidTest/java/com/example/cahier/CahierAppTest.kt @@ -21,14 +21,11 @@ package com.example.cahier -import androidx.compose.ui.test.filterToOne import androidx.compose.ui.test.hasSetTextAction import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onAllNodesWithContentDescription -import androidx.compose.ui.test.onChildren import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText -import androidx.compose.ui.test.performImeAction import androidx.compose.ui.test.performTextInput import androidx.compose.ui.test.performClick import androidx.test.ext.junit.runners.AndroidJUnit4 @@ -87,8 +84,14 @@ class CahierAppTest { composeTestRule.onNodeWithContentDescription("Add note").performClick() composeTestRule.onNodeWithContentDescription("Text note").performClick() - composeTestRule.onNodeWithText("Title", useUnmergedTree = true).assertExists() - composeTestRule.onNodeWithText("Note", useUnmergedTree = true).assertExists() + composeTestRule + .onNodeWithText(composeTestRule.activity.getString(R.string.title), + useUnmergedTree = true) + .assertExists() + composeTestRule + .onNodeWithText(composeTestRule.activity.getString(R.string.note), + useUnmergedTree = true) + .assertExists() } @Test @@ -103,11 +106,13 @@ class CahierAppTest { composeTestRule.onNodeWithContentDescription("Text note").performClick() val titleText = "My test title" - composeTestRule.onNode(hasSetTextAction() and hasText("Title")) + composeTestRule.onNode(hasSetTextAction() and + hasText(composeTestRule.activity.getString(R.string.title))) .performTextInput(titleText) val noteText = "This is a test note." - composeTestRule.onNode(hasSetTextAction() and hasText("Note")) + composeTestRule.onNode(hasSetTextAction() and + hasText(composeTestRule.activity.getString(R.string.note))) .performTextInput(noteText) // Recreate the activity From b1a06194ba6b4dc392822f199b97ebe688775481 Mon Sep 17 00:00:00 2001 From: Francesco Romano Date: Thu, 20 Nov 2025 23:12:05 +0100 Subject: [PATCH 3/3] added tests to verify state preservation in TextNoteCanvasScreen --- .../androidTest/java/com/example/cahier/CahierAppTest.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/src/androidTest/java/com/example/cahier/CahierAppTest.kt b/app/src/androidTest/java/com/example/cahier/CahierAppTest.kt index 0b97b5a..d43a3aa 100644 --- a/app/src/androidTest/java/com/example/cahier/CahierAppTest.kt +++ b/app/src/androidTest/java/com/example/cahier/CahierAppTest.kt @@ -51,7 +51,7 @@ class CahierAppTest { composeTestRule.waitUntil(timeoutMillis = 5000) { composeTestRule .onAllNodesWithContentDescription("Add note") - .fetchSemanticsNodes().size == 1 + .fetchSemanticsNodes().isNotEmpty() } composeTestRule.onNodeWithText("Home").assertExists() @@ -78,7 +78,7 @@ class CahierAppTest { composeTestRule.waitUntil(timeoutMillis = 5000) { composeTestRule .onAllNodesWithContentDescription("Add note") - .fetchSemanticsNodes().size == 1 + .fetchSemanticsNodes().isNotEmpty() } composeTestRule.onNodeWithContentDescription("Add note").performClick() @@ -99,7 +99,7 @@ class CahierAppTest { composeTestRule.waitUntil(timeoutMillis = 5000) { composeTestRule .onAllNodesWithContentDescription("Add note") - .fetchSemanticsNodes().size == 1 + .fetchSemanticsNodes().isNotEmpty() } composeTestRule.onNodeWithContentDescription("Add note").performClick() @@ -115,10 +115,8 @@ class CahierAppTest { hasText(composeTestRule.activity.getString(R.string.note))) .performTextInput(noteText) - // Recreate the activity composeTestRule.activityRule.scenario.recreate() - // Verify the text is still there composeTestRule.onNodeWithText(titleText, useUnmergedTree = true).assertExists() composeTestRule.onNodeWithText(noteText, useUnmergedTree = true).assertExists() }