Skip to content
Merged
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
44 changes: 40 additions & 4 deletions app/src/androidTest/java/com/example/cahier/CahierAppTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@

package com.example.cahier

import androidx.compose.ui.test.hasSetTextAction
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onAllNodesWithContentDescription
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
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
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
Expand All @@ -48,7 +51,7 @@ class CahierAppTest {
composeTestRule.waitUntil(timeoutMillis = 5000) {
composeTestRule
.onAllNodesWithContentDescription("Add note")
.fetchSemanticsNodes().size == 1
.fetchSemanticsNodes().isNotEmpty()
}

composeTestRule.onNodeWithText("Home").assertExists()
Expand All @@ -75,13 +78,46 @@ class CahierAppTest {
composeTestRule.waitUntil(timeoutMillis = 5000) {
composeTestRule
.onAllNodesWithContentDescription("Add note")
.fetchSemanticsNodes().size == 1
.fetchSemanticsNodes().isNotEmpty()
}

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
fun textNoteCanvasScreen_savedState() {
composeTestRule.waitUntil(timeoutMillis = 5000) {
composeTestRule
.onAllNodesWithContentDescription("Add note")
.fetchSemanticsNodes().isNotEmpty()
}

composeTestRule.onNodeWithContentDescription("Add note").performClick()
composeTestRule.onNodeWithContentDescription("Text note").performClick()

val titleText = "My test 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(composeTestRule.activity.getString(R.string.note)))
.performTextInput(noteText)

composeTestRule.activityRule.scenario.recreate()

composeTestRule.onNodeWithText(titleText, useUnmergedTree = true).assertExists()
composeTestRule.onNodeWithText(noteText, useUnmergedTree = true).assertExists()
}
}
Loading