This repository has been archived by the owner on Jul 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
NavigationTest.kt
107 lines (95 loc) · 4.5 KB
/
NavigationTest.kt
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
package ch.epfl.sdp.mobile.test.state
import androidx.compose.ui.semantics.SemanticsProperties
import androidx.compose.ui.semantics.SemanticsProperties.Selected
import androidx.compose.ui.test.*
import androidx.compose.ui.test.SemanticsMatcher.Companion.expectValue
import androidx.compose.ui.test.SemanticsMatcher.Companion.keyIsDefined
import androidx.compose.ui.test.junit4.createComposeRule
import ch.epfl.sdp.mobile.application.ProfileDocument
import ch.epfl.sdp.mobile.application.authentication.AuthenticationFacade
import ch.epfl.sdp.mobile.application.chess.ChessFacade
import ch.epfl.sdp.mobile.application.social.SocialFacade
import ch.epfl.sdp.mobile.application.speech.SpeechFacade
import ch.epfl.sdp.mobile.state.Navigation
import ch.epfl.sdp.mobile.state.ProvideFacades
import ch.epfl.sdp.mobile.test.infrastructure.persistence.auth.SuspendingAuth
import ch.epfl.sdp.mobile.test.infrastructure.persistence.auth.buildAuth
import ch.epfl.sdp.mobile.test.infrastructure.persistence.auth.emptyAuth
import ch.epfl.sdp.mobile.test.infrastructure.persistence.store.buildStore
import ch.epfl.sdp.mobile.test.infrastructure.persistence.store.document
import ch.epfl.sdp.mobile.test.infrastructure.persistence.store.emptyStore
import ch.epfl.sdp.mobile.test.infrastructure.speech.FailingSpeechRecognizerFactory
import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
class NavigationTest {
@get:Rule val rule = createComposeRule()
@Test
fun loadingSection_isEmpty() {
val store = emptyStore()
val facade = AuthenticationFacade(SuspendingAuth, store)
val socialFacade = SocialFacade(SuspendingAuth, store)
val chessFacade = ChessFacade(SuspendingAuth, store)
val speechFacade = SpeechFacade(FailingSpeechRecognizerFactory)
rule.setContentWithLocalizedStrings {
ProvideFacades(facade, socialFacade, chessFacade, speechFacade) { Navigation() }
}
rule.onAllNodes(keyIsDefined(SemanticsProperties.Text)).assertCountEquals(0)
}
@Test
fun notAuthenticated_displaysAuthenticationScreen() = runTest {
val auth = emptyAuth()
val store = emptyStore()
val facade = AuthenticationFacade(auth, store)
val socialFacade = SocialFacade(auth, store)
val chessFacade = ChessFacade(SuspendingAuth, store)
val speechFacade = SpeechFacade(FailingSpeechRecognizerFactory)
val strings =
rule.setContentWithLocalizedStrings {
ProvideFacades(facade, socialFacade, chessFacade, speechFacade) { Navigation() }
}
// Do we see the authentication screen actions ?
rule.onNodeWithText(strings.authenticatePerformRegister).assertExists()
}
@Test
fun authenticated_displaysHome() = runTest {
val auth = emptyAuth()
val store = emptyStore()
val facade = AuthenticationFacade(auth, store)
val socialFacade = SocialFacade(auth, store)
val chessFacade = ChessFacade(SuspendingAuth, store)
val speechFacade = SpeechFacade(FailingSpeechRecognizerFactory)
val strings =
rule.setContentWithLocalizedStrings {
ProvideFacades(facade, socialFacade, chessFacade, speechFacade) { Navigation() }
}
facade.signUpWithEmail("email@epfl.ch", "name", "password")
// Do we see the bottom navigation ?
rule.onNodeWithText(strings.sectionSocial).assertExists()
rule.onNodeWithText(strings.sectionSettings).assertExists()
rule.onNodeWithText(strings.sectionPlay).assertExists()
}
@Test
fun updatingUsername_preservesHomeSection() = runTest {
val auth = buildAuth { user("email@epfl.ch", "password", "id") }
val store = buildStore {
collection("users") { document("id", ProfileDocument(name = "Alice")) }
}
val authFacade = AuthenticationFacade(auth, store)
val chessFacade = ChessFacade(auth, store)
val socialFacade = SocialFacade(auth, store)
val speechFacade = SpeechFacade(FailingSpeechRecognizerFactory)
val strings =
rule.setContentWithLocalizedStrings {
ProvideFacades(authFacade, socialFacade, chessFacade, speechFacade) { Navigation() }
}
authFacade.signInWithEmail("email@epfl.ch", "password")
// Move to the profile section.
rule.onNodeWithText(strings.sectionSettings).performClick()
rule.onAllNodesWithText(strings.sectionSettings).assertAny(expectValue(Selected, true))
// Update the username.
store.collection("users").document("id").update { this["name"] = "Bob" }
// Check that we're still in the right section.
rule.onAllNodesWithText(strings.sectionSettings).assertAny(expectValue(Selected, true))
}
}