-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNavDrawerFeature.kt
More file actions
138 lines (116 loc) · 5.26 KB
/
NavDrawerFeature.kt
File metadata and controls
138 lines (116 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package com.digiventure.ventnote
import android.content.Intent
import androidx.compose.ui.test.*
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction
import androidx.test.espresso.intent.matcher.IntentMatchers.hasData
import com.digiventure.utils.BaseAcceptanceTest
import com.digiventure.ventnote.commons.TestTags
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.hamcrest.Matchers.allOf
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@HiltAndroidTest
class NavDrawerFeature : BaseAcceptanceTest() {
@get:Rule(order = 0)
val hiltRule = HiltAndroidRule(this)
@get:Rule(order = 1)
val composeTestRule = createAndroidComposeRule<MainActivity>()
@Before
fun setUp() {
hiltRule.inject()
Intents.init()
// Open the drawer
composeTestRule.onNodeWithTag(TestTags.NOTES_PAGE).assertIsDisplayed()
composeTestRule.onNodeWithTag(TestTags.MENU_ICON_BUTTON).performClick()
composeTestRule.waitForIdle()
composeTestRule.onNodeWithTag(TestTags.NAV_DRAWER, useUnmergedTree = true).assertIsDisplayed()
}
@After
fun tearDown() {
Intents.release()
}
@Test
fun initialState_showsMenuItems() {
composeTestRule.onNodeWithTag(TestTags.RATE_APP_TILE).assertIsDisplayed()
composeTestRule.onNodeWithTag(TestTags.MORE_APPS_TILE).assertIsDisplayed()
composeTestRule.onNodeWithTag(TestTags.APP_VERSION_TILE).assertIsDisplayed()
composeTestRule.onNodeWithTag(TestTags.THEME_TILE).assertIsDisplayed()
composeTestRule.onNodeWithTag(TestTags.COLOR_MODE_TILE).assertIsDisplayed()
composeTestRule.onNodeWithTag(TestTags.BACKUP_TILE).assertIsDisplayed()
}
@Test
fun rateApp_launchesPlayStore() {
composeTestRule.onNodeWithTag(TestTags.RATE_APP_TILE).performClick()
intended(allOf(
hasAction(Intent.ACTION_VIEW),
hasData("https://play.google.com/store/apps/details?id=com.digiventure.ventnote")
))
}
@Test
fun moreApps_launchesDeveloperPage() {
composeTestRule.onNodeWithTag(TestTags.MORE_APPS_TILE).performClick()
intended(allOf(
hasAction(Intent.ACTION_VIEW),
hasData("https://play.google.com/store/apps/developer?id=Mattrmost")
))
}
@Test
fun backupNavigation_navigatesToBackupPage() {
composeTestRule.onNodeWithTag(TestTags.BACKUP_TILE).performClick()
composeTestRule.waitForIdle()
// Use text or tag to verify backup page (usually has "Backup" title in header)
composeTestRule.onNodeWithText("Backup Notes").assertIsDisplayed()
}
@Test
fun themeColorChange_updatesTheme() {
// Verify we can click all theme colors
composeTestRule.onNodeWithTag(TestTags.THEME_COLOR_PURPLE).performClick()
composeTestRule.onNodeWithTag(TestTags.THEME_COLOR_CRIMSON).performClick()
composeTestRule.onNodeWithTag(TestTags.THEME_COLOR_CADMIUM_GREEN).performClick()
composeTestRule.onNodeWithTag(TestTags.THEME_COLOR_COBALT_BLUE).performClick()
// Clicks should not crash and should update internal state (hard to verify without custom matchers)
composeTestRule.onNodeWithTag(TestTags.THEME_TILE).assertIsDisplayed()
}
@Test
fun colorModeToggle_updatesMode() {
// Find the current mode by checking the subtitle text
val lightModeText = "switch to light mode"
val darkModeText = "switch to dark mode"
// Initial click to toggle (assuming default is light mode or whatever)
// We look for either text to be sure
val initialNode = composeTestRule.onNode(
hasText(lightModeText, ignoreCase = true) or hasText(darkModeText, ignoreCase = true)
)
initialNode.assertIsDisplayed()
val isInitiallyLight = try {
composeTestRule.onNodeWithText(darkModeText, ignoreCase = true).assertIsDisplayed()
true // It says "switch to dark", so it is currently light
} catch (_: Throwable) {
false
}
// Toggle
composeTestRule.onNodeWithTag(TestTags.COLOR_MODE_TILE).performClick()
composeTestRule.waitForIdle()
// Verify text swapped
if (isInitiallyLight) {
composeTestRule.onNodeWithText(lightModeText, ignoreCase = true).assertIsDisplayed()
} else {
composeTestRule.onNodeWithText(darkModeText, ignoreCase = true).assertIsDisplayed()
}
}
@Test
fun drawer_canBeClosed() {
// Click outside or use a specific close mechanism if available,
// but here we can just swipe or click the content area if accessible.
// Easiest is to just verify it closes on back press
androidx.test.platform.app.InstrumentationRegistry.getInstrumentation().sendKeyDownUpSync(android.view.KeyEvent.KEYCODE_BACK)
composeTestRule.waitForIdle()
composeTestRule.onNodeWithTag(TestTags.NAV_DRAWER).assertDoesNotExist()
}
}