@@ -21,6 +21,7 @@ import org.oppia.android.app.model.EphemeralState
21
21
import org.oppia.android.app.model.EphemeralState.StateTypeCase.COMPLETED_STATE
22
22
import org.oppia.android.app.model.EphemeralState.StateTypeCase.PENDING_STATE
23
23
import org.oppia.android.app.model.EphemeralState.StateTypeCase.TERMINAL_STATE
24
+ import org.oppia.android.app.model.EventLog.Context.ActivityContextCase.REACH_INVESTED_ENGAGEMENT
24
25
import org.oppia.android.app.model.Exploration
25
26
import org.oppia.android.app.model.ExplorationCheckpoint
26
27
import org.oppia.android.app.model.Fraction
@@ -1972,6 +1973,226 @@ class ExplorationProgressControllerTest {
1972
1973
}
1973
1974
}
1974
1975
1976
+ @Test
1977
+ fun testPlayNewExp_firstCard_notFinished_doesNotLogReachInvestedEngagementEvent () {
1978
+ logIntoAnalyticsReadyAdminProfile()
1979
+
1980
+ startPlayingNewExploration(TEST_TOPIC_ID_0 , TEST_STORY_ID_0 , TEST_EXPLORATION_ID_2 )
1981
+ waitForGetCurrentStateSuccessfulLoad()
1982
+
1983
+ val hasEngagementEvent = fakeAnalyticsEventLogger.hasEventLogged {
1984
+ it.context.activityContextCase == REACH_INVESTED_ENGAGEMENT
1985
+ }
1986
+ assertThat(hasEngagementEvent).isFalse()
1987
+ }
1988
+
1989
+ @Test
1990
+ fun testPlayNewExp_finishFirstCard_moveToSecond_doesNotLogReachInvestedEngagementEvent () {
1991
+ logIntoAnalyticsReadyAdminProfile()
1992
+
1993
+ startPlayingNewExploration(TEST_TOPIC_ID_0 , TEST_STORY_ID_0 , TEST_EXPLORATION_ID_2 )
1994
+ waitForGetCurrentStateSuccessfulLoad()
1995
+ playThroughPrototypeState1AndMoveToNextState()
1996
+
1997
+ val hasEngagementEvent = fakeAnalyticsEventLogger.hasEventLogged {
1998
+ it.context.activityContextCase == REACH_INVESTED_ENGAGEMENT
1999
+ }
2000
+ assertThat(hasEngagementEvent).isFalse()
2001
+ }
2002
+
2003
+ @Test
2004
+ fun testPlayNewExp_finishThreeCards_doNotProceed_doesNotLogReachInvestedEngagementEvent () {
2005
+ logIntoAnalyticsReadyAdminProfile()
2006
+
2007
+ startPlayingNewExploration(TEST_TOPIC_ID_0 , TEST_STORY_ID_0 , TEST_EXPLORATION_ID_2 )
2008
+ waitForGetCurrentStateSuccessfulLoad()
2009
+ playThroughPrototypeState1AndMoveToNextState()
2010
+ playThroughPrototypeState2AndMoveToNextState()
2011
+ submitPrototypeState3Answer()
2012
+
2013
+ val hasEngagementEvent = fakeAnalyticsEventLogger.hasEventLogged {
2014
+ it.context.activityContextCase == REACH_INVESTED_ENGAGEMENT
2015
+ }
2016
+ assertThat(hasEngagementEvent).isFalse()
2017
+ }
2018
+
2019
+ @Test
2020
+ fun testPlayNewExp_finishThreeCards_moveToFour_logsReachInvestedEngagementEvent () {
2021
+ logIntoAnalyticsReadyAdminProfile()
2022
+
2023
+ startPlayingNewExploration(TEST_TOPIC_ID_0 , TEST_STORY_ID_0 , TEST_EXPLORATION_ID_2 )
2024
+ waitForGetCurrentStateSuccessfulLoad()
2025
+ playThroughPrototypeState1AndMoveToNextState()
2026
+ playThroughPrototypeState2AndMoveToNextState()
2027
+ playThroughPrototypeState3AndMoveToNextState()
2028
+
2029
+ val hasEngagementEvent = fakeAnalyticsEventLogger.hasEventLogged {
2030
+ it.context.activityContextCase == REACH_INVESTED_ENGAGEMENT
2031
+ }
2032
+ val eventLog = fakeAnalyticsEventLogger.getMostRecentEvent()
2033
+ assertThat(hasEngagementEvent).isTrue()
2034
+ assertThat(eventLog).hasReachedInvestedEngagementContextThat {
2035
+ hasStateNameThat().isEqualTo(" ItemSelectionMinOne" )
2036
+ }
2037
+ }
2038
+
2039
+ @Test
2040
+ fun testPlayNewExp_finishFourCards_moveToFive_logsReachInvestedEngagementEventOnlyOnce () {
2041
+ logIntoAnalyticsReadyAdminProfile()
2042
+
2043
+ startPlayingNewExploration(TEST_TOPIC_ID_0 , TEST_STORY_ID_0 , TEST_EXPLORATION_ID_2 )
2044
+ waitForGetCurrentStateSuccessfulLoad()
2045
+ playThroughPrototypeState1AndMoveToNextState()
2046
+ playThroughPrototypeState2AndMoveToNextState()
2047
+ playThroughPrototypeState3AndMoveToNextState()
2048
+ playThroughPrototypeState4AndMoveToNextState()
2049
+
2050
+ // The engagement event should only be logged once during a play session, even if the user
2051
+ // continues past that point.
2052
+ val engagementEventCount = fakeAnalyticsEventLogger.countEvents {
2053
+ it.context.activityContextCase == REACH_INVESTED_ENGAGEMENT
2054
+ }
2055
+ assertThat(engagementEventCount).isEqualTo(1 )
2056
+ }
2057
+
2058
+ @Test
2059
+ fun testPlayNewExp_firstTwo_startOver_playFirst_doesNotLogReachInvestedEngagementEvent () {
2060
+ logIntoAnalyticsReadyAdminProfile()
2061
+ startPlayingNewExploration(TEST_TOPIC_ID_0 , TEST_STORY_ID_0 , TEST_EXPLORATION_ID_2 )
2062
+ waitForGetCurrentStateSuccessfulLoad()
2063
+ playThroughPrototypeState1AndMoveToNextState()
2064
+ playThroughPrototypeState2AndMoveToNextState()
2065
+
2066
+ // Restart the exploration.
2067
+ restartExploration(TEST_TOPIC_ID_0 , TEST_STORY_ID_0 , TEST_EXPLORATION_ID_2 )
2068
+ waitForGetCurrentStateSuccessfulLoad()
2069
+ playThroughPrototypeState1AndMoveToNextState()
2070
+
2071
+ // No engagement event should be logged, even though 3 total states were completed from the
2072
+ // first and second sessions (cumulatively).
2073
+ val hasEngagementEvent = fakeAnalyticsEventLogger.hasEventLogged {
2074
+ it.context.activityContextCase == REACH_INVESTED_ENGAGEMENT
2075
+ }
2076
+ assertThat(hasEngagementEvent).isFalse()
2077
+ }
2078
+
2079
+ @Test
2080
+ fun testPlayNewExp_firstTwo_startOver_playThreeAndMove_logsReachInvestedEngagementEvent () {
2081
+ logIntoAnalyticsReadyAdminProfile()
2082
+ startPlayingNewExploration(TEST_TOPIC_ID_0 , TEST_STORY_ID_0 , TEST_EXPLORATION_ID_2 )
2083
+ waitForGetCurrentStateSuccessfulLoad()
2084
+ playThroughPrototypeState1AndMoveToNextState()
2085
+ playThroughPrototypeState2AndMoveToNextState()
2086
+
2087
+ // Restart the exploration.
2088
+ restartExploration(TEST_TOPIC_ID_0 , TEST_STORY_ID_0 , TEST_EXPLORATION_ID_2 )
2089
+ waitForGetCurrentStateSuccessfulLoad()
2090
+ playThroughPrototypeState1AndMoveToNextState()
2091
+ playThroughPrototypeState2AndMoveToNextState()
2092
+ playThroughPrototypeState3AndMoveToNextState()
2093
+
2094
+ // An engagement event should be logged since the new session uniquely finished 3 states.
2095
+ val hasEngagementEvent = fakeAnalyticsEventLogger.hasEventLogged {
2096
+ it.context.activityContextCase == REACH_INVESTED_ENGAGEMENT
2097
+ }
2098
+ val eventLog = fakeAnalyticsEventLogger.getMostRecentEvent()
2099
+ assertThat(hasEngagementEvent).isTrue()
2100
+ assertThat(eventLog).hasReachedInvestedEngagementContextThat {
2101
+ hasStateNameThat().isEqualTo(" ItemSelectionMinOne" )
2102
+ }
2103
+ }
2104
+
2105
+ @Test
2106
+ fun testResumeExp_stateOneTwoDone_finishThreeAndMoveForward_noLogReachInvestedEngagementEvent () {
2107
+ logIntoAnalyticsReadyAdminProfile()
2108
+ startPlayingNewExploration(TEST_TOPIC_ID_0 , TEST_STORY_ID_0 , TEST_EXPLORATION_ID_2 )
2109
+ waitForGetCurrentStateSuccessfulLoad()
2110
+ playThroughPrototypeState1AndMoveToNextState()
2111
+ playThroughPrototypeState2AndMoveToNextState()
2112
+
2113
+ // End, then resume the exploration and complete the third state.
2114
+ endExploration()
2115
+ val checkPoint = retrieveExplorationCheckpoint(TEST_EXPLORATION_ID_2 )
2116
+ resumeExploration(TEST_TOPIC_ID_0 , TEST_STORY_ID_0 , TEST_EXPLORATION_ID_2 , checkPoint)
2117
+ playThroughPrototypeState3AndMoveToNextState()
2118
+
2119
+ // Despite the first three states now being completed, this isn't an engagement event since the
2120
+ // user hasn't finished three states within *one* session.
2121
+ val hasEngagementEvent = fakeAnalyticsEventLogger.hasEventLogged {
2122
+ it.context.activityContextCase == REACH_INVESTED_ENGAGEMENT
2123
+ }
2124
+ assertThat(hasEngagementEvent).isFalse()
2125
+ }
2126
+
2127
+ @Test
2128
+ fun testResumeExp_stateOneTwoDone_finishThreeMoreAndMove_logsReachInvestedEngagementEvent () {
2129
+ logIntoAnalyticsReadyAdminProfile()
2130
+ startPlayingNewExploration(TEST_TOPIC_ID_0 , TEST_STORY_ID_0 , TEST_EXPLORATION_ID_2 )
2131
+ waitForGetCurrentStateSuccessfulLoad()
2132
+ playThroughPrototypeState1AndMoveToNextState()
2133
+ playThroughPrototypeState2AndMoveToNextState()
2134
+
2135
+ // End, then resume the exploration and complete the third state.
2136
+ endExploration()
2137
+ val checkPoint = retrieveExplorationCheckpoint(TEST_EXPLORATION_ID_2 )
2138
+ resumeExploration(TEST_TOPIC_ID_0 , TEST_STORY_ID_0 , TEST_EXPLORATION_ID_2 , checkPoint)
2139
+ playThroughPrototypeState3AndMoveToNextState()
2140
+ playThroughPrototypeState4AndMoveToNextState()
2141
+ playThroughPrototypeState5AndMoveToNextState()
2142
+
2143
+ // An engagement event should be logged now since the user completed 3 new states in the current
2144
+ // session.
2145
+ val hasEngagementEvent = fakeAnalyticsEventLogger.hasEventLogged {
2146
+ it.context.activityContextCase == REACH_INVESTED_ENGAGEMENT
2147
+ }
2148
+ val eventLog = fakeAnalyticsEventLogger.getMostRecentEvent()
2149
+ assertThat(hasEngagementEvent).isTrue()
2150
+ assertThat(eventLog).hasReachedInvestedEngagementContextThat {
2151
+ hasStateNameThat().isEqualTo(" NumberInput" )
2152
+ }
2153
+ }
2154
+
2155
+ @Test
2156
+ fun testResumeExp_finishThree_thenAnotherThreeAfterResume_logsInvestedEngagementEventTwice () {
2157
+ logIntoAnalyticsReadyAdminProfile()
2158
+ startPlayingNewExploration(TEST_TOPIC_ID_0 , TEST_STORY_ID_0 , TEST_EXPLORATION_ID_2 )
2159
+ waitForGetCurrentStateSuccessfulLoad()
2160
+ playThroughPrototypeState1AndMoveToNextState()
2161
+ playThroughPrototypeState2AndMoveToNextState()
2162
+ playThroughPrototypeState3AndMoveToNextState()
2163
+
2164
+ // End, then resume the exploration and complete the third state.
2165
+ endExploration()
2166
+ val checkPoint = retrieveExplorationCheckpoint(TEST_EXPLORATION_ID_2 )
2167
+ resumeExploration(TEST_TOPIC_ID_0 , TEST_STORY_ID_0 , TEST_EXPLORATION_ID_2 , checkPoint)
2168
+ playThroughPrototypeState4AndMoveToNextState()
2169
+ playThroughPrototypeState5AndMoveToNextState()
2170
+ playThroughPrototypeState6AndMoveToNextState()
2171
+
2172
+ // Playing enough states for the engagement event before and after resuming should result in it
2173
+ // being logged twice (once for each session).
2174
+ val engagementEventCount = fakeAnalyticsEventLogger.countEvents {
2175
+ it.context.activityContextCase == REACH_INVESTED_ENGAGEMENT
2176
+ }
2177
+ assertThat(engagementEventCount).isEqualTo(2 )
2178
+ }
2179
+
2180
+ @Test
2181
+ fun testPlayNewExp_getToEngagementEvent_playOtherExpAndDoSame_logsEngagementEventAgain () {
2182
+ logIntoAnalyticsReadyAdminProfile()
2183
+
2184
+ // Play through the full prototype exploration twice.
2185
+ playThroughPrototypeExplorationInNewSession()
2186
+ playThroughPrototypeExplorationInNewSession()
2187
+
2188
+ // Playing through two complete exploration sessions should result in the engagement event being
2189
+ // logged twice (once for each session).
2190
+ val engagementEventCount = fakeAnalyticsEventLogger.countEvents {
2191
+ it.context.activityContextCase == REACH_INVESTED_ENGAGEMENT
2192
+ }
2193
+ assertThat(engagementEventCount).isEqualTo(2 )
2194
+ }
2195
+
1975
2196
@Test
1976
2197
fun testSubmitAnswer_correctAnswer_logsEndCardAndSubmitAnswerEvents () {
1977
2198
logIntoAnalyticsReadyAdminProfile()
@@ -2325,6 +2546,12 @@ class ExplorationProgressControllerTest {
2325
2546
return waitForGetCurrentStateSuccessfulLoad()
2326
2547
}
2327
2548
2549
+ private fun playThroughPrototypeExplorationInNewSession () {
2550
+ startPlayingNewExploration(TEST_TOPIC_ID_0 , TEST_STORY_ID_0 , TEST_EXPLORATION_ID_2 )
2551
+ playThroughPrototypeExploration()
2552
+ endExploration()
2553
+ }
2554
+
2328
2555
private fun playThroughPrototypeExploration (): EphemeralState {
2329
2556
playThroughPrototypeState1AndMoveToNextState()
2330
2557
playThroughPrototypeState2AndMoveToNextState()
0 commit comments