@@ -3,6 +3,8 @@ package com.willowtreeapps.namegame
33import com.willowtreeapps.common.*
44import com.willowtreeapps.common.repo.MockRepositoryFactory
55import com.willowtreeapps.common.repo.ProfileItemRepository
6+ import com.willowtreeapps.common.repo.generateQuestions
7+ import com.willowtreeapps.common.util.takeRandomDistinct
68import kotlinx.coroutines.runBlocking
79import org.junit.Assert.*
810import org.junit.Test
@@ -34,7 +36,7 @@ class ReducersTest {
3436 @Test
3537 fun `generate N distinct random rounds` () {
3638
37- val itemHolder = runBlocking { ProfileItemRepository (MockRepositoryFactory ().success()).fetchItems() }.response
39+ val itemHolder = runBlocking { ProfileItemRepository (MockRepositoryFactory ().success()).fetchItems(10 ) }.response
3840 val rounds = generateQuestions(itemHolder?.items!! , 10 )
3941
4042 assertEquals(10 , rounds.size)
@@ -43,39 +45,39 @@ class ReducersTest {
4345
4446 @Test
4547 fun `isLoadingProfiles set true` () {
46- val final = reducer(generateInitialTestState(), Actions .FetchingItemsStartedAction ())
48+ val final = reducer(generateInitialTestState(), Actions .FetchingItemsStartedAction ()) as AppState
4749
4850 assertTrue(final.isLoadingItems)
4951 }
5052
5153 @Test
5254 fun `isLoadingProfiles set false on success` () {
5355 val initial = generateInitialTestState().copy(isLoadingItems = true )
54- val final = reducer(initial, Actions .FetchingItemsSuccessAction (runBlocking { ProfileItemRepository (MockRepositoryFactory ().success()).fetchItems() }.response!! ))
56+ val final = reducer(initial, Actions .FetchingItemsSuccessAction (runBlocking { ProfileItemRepository (MockRepositoryFactory ().success()).fetchItems(10 ) }.response!! )) as AppState
5557
5658 assertFalse(final.isLoadingItems)
5759 }
5860
5961 @Test
6062 fun `isLoadingProfiles set false on failure` () {
6163 val initial = generateInitialTestState().copy(isLoadingItems = true )
62- val final = reducer(initial, Actions .FetchingItemsFailedAction (" Test failure" ))
64+ val final = reducer(initial, Actions .FetchingItemsFailedAction (" Test failure" )) as AppState
6365
6466 assertFalse(final.isLoadingItems)
6567 }
6668
6769 @Test
6870 fun `NextQuestionAction - increments currentRoundIndex` () {
6971 val initial = generateInitialTestState()
70- val final = reducer(initial, Actions .NextQuestionAction ())
72+ val final = reducer(initial, Actions .NextQuestionAction ()) as AppState
7173
7274 assertEquals(1 , final.currentQuestionIndex)
7375 }
7476
7577 @Test
7678 fun `NextQuestionAction - sets waitingForNextQuestion = false` () {
7779 val initial = generateInitialTestState()
78- val final = reducer(initial, Actions .NextQuestionAction ())
80+ val final = reducer(initial, Actions .NextQuestionAction ()) as AppState
7981
8082 assertEquals(false , final.waitingForNextQuestion)
8183 }
@@ -85,7 +87,7 @@ class ReducersTest {
8587 val initial = generateInitialTestState()
8688 val answer = initial.currentQuestionItem().displayName()
8789
88- val final = reducer(initial, Actions .NamePickedAction (answer))
90+ val final = reducer(initial, Actions .NamePickedAction (answer)) as AppState
8991
9092 assertEquals(Question .Status .CORRECT , final.currentQuestion?.status)
9193 }
@@ -95,7 +97,7 @@ class ReducersTest {
9597 val initial = generateInitialTestState()
9698 val answer = " wrong answer"
9799
98- val final = reducer(initial, Actions .NamePickedAction (answer))
100+ val final = reducer(initial, Actions .NamePickedAction (answer)) as AppState
99101
100102 assertEquals(Question .Status .INCORRECT , final.currentQuestion?.status)
101103 }
@@ -105,7 +107,7 @@ class ReducersTest {
105107 val initial = staticTestState(stanLee)
106108 val answer = justinTimberlake.displayName()
107109
108- val final = reducer(initial, Actions .NamePickedAction (answer))
110+ val final = reducer(initial, Actions .NamePickedAction (answer)) as AppState
109111
110112 assertEquals(Question .Status .INCORRECT , final.currentQuestion?.status)
111113 }
@@ -116,7 +118,7 @@ class ReducersTest {
116118 val initial = generateInitialTestState()
117119 val answer = " wrong answer"
118120
119- val final = reducer(initial, Actions .NamePickedAction (answer))
121+ val final = reducer(initial, Actions .NamePickedAction (answer)) as AppState
120122
121123 assertEquals(null , final.currentQuestion?.answerName)
122124 }
@@ -128,7 +130,7 @@ class ReducersTest {
128130 val initial = staticTestState(stanLee)
129131 val answer = " stan bee"
130132
131- val final = reducer(initial, Actions .NamePickedAction (answer))
133+ val final = reducer(initial, Actions .NamePickedAction (answer)) as AppState
132134
133135 assertEquals(" Stan Lee" , final.currentQuestion?.answerName)
134136 }
@@ -140,7 +142,7 @@ class ReducersTest {
140142 val initial = staticTestState(stanLee)
141143 val answer = " stan bee"
142144
143- val final = reducer(initial, Actions .NamePickedAction (answer))
145+ val final = reducer(initial, Actions .NamePickedAction (answer)) as AppState
144146
145147 assertEquals(Question .Status .CORRECT , final.currentQuestion?.status)
146148 }
@@ -150,7 +152,7 @@ class ReducersTest {
150152 fun `mark current round as TIMES when time is up` () {
151153 val initial = generateInitialTestState()
152154
153- val final = reducer(initial, Actions .TimesUpAction ())
155+ val final = reducer(initial, Actions .TimesUpAction ()) as AppState
154156
155157 assertEquals(Question .Status .TIMES_UP , final.currentQuestion?.status)
156158 }
@@ -159,7 +161,7 @@ class ReducersTest {
159161 fun `decrement timer` () {
160162 val initial = generateInitialTestState()
161163
162- val final = reducer(initial, Actions .DecrementCountDownAction ())
164+ val final = reducer(initial, Actions .DecrementCountDownAction ()) as AppState
163165
164166 assertEquals(initial.questionClock - 1 , final.questionClock)
165167 }
@@ -168,7 +170,7 @@ class ReducersTest {
168170 fun `start question timer with initial value` () {
169171 val initial = generateInitialTestState()
170172
171- val final = reducer(initial, Actions .StartQuestionTimerAction (10 ))
173+ val final = reducer(initial, Actions .StartQuestionTimerAction (10 )) as AppState
172174
173175 assertEquals(10 , final.questionClock)
174176 }
@@ -177,7 +179,7 @@ class ReducersTest {
177179 fun `ChangeNumQuestionsAction should update AppState` () {
178180 val initial = generateInitialTestState()
179181
180- val final = reducer(initial, Actions .ChangeNumQuestionsSettingsAction (10 ))
182+ val final = reducer(initial, Actions .ChangeNumQuestionsSettingsAction (10 )) as AppState
181183
182184 assertEquals(10 , final.settings.numQuestions)
183185 }
@@ -186,7 +188,7 @@ class ReducersTest {
186188 fun `ChangeMicrophoneModeAction should update settings` () {
187189 val initial = generateInitialTestState()
188190
189- val final = reducer(initial, Actions .ChangeMicrophoneModeSettingsAction (true ))
191+ val final = reducer(initial, Actions .ChangeMicrophoneModeSettingsAction (true )) as AppState
190192
191193 assertEquals(true , final.settings.microphoneMode)
192194 }
@@ -195,7 +197,7 @@ class ReducersTest {
195197 fun `WillowTreeSignInSuccess should update is state` () {
196198 val initial = generateInitialTestState()
197199
198- val final = reducer(initial, Actions .WillowTreeSignInSuccessAction ())
200+ val final = reducer(initial, Actions .WillowTreeSignInSuccessAction ()) as AppState
199201
200202 assertEquals(true , final.settings.isWillowTree)
201203 }
@@ -205,20 +207,20 @@ class ReducersTest {
205207 var initial = generateInitialTestState()
206208 initial = initial.copy(settings = initial.settings.copy(isWillowTree = true ))
207209
208- val final = reducer(initial, Actions .WillowTreeSignOutSuccessAction ())
210+ val final = reducer(initial, Actions .WillowTreeSignOutSuccessAction ()) as AppState
209211
210212 assertEquals(false , final.settings.isWillowTree)
211213 }
212214
213215 private fun generateInitialTestState (): AppState {
214- val initialState = reducer(AppState (), Actions .FetchingItemsSuccessAction (runBlocking { ProfileItemRepository (MockRepositoryFactory ().success()).fetchItems() }.response!! ))
216+ val initialState = reducer(AppState (), Actions .FetchingItemsSuccessAction (runBlocking { ProfileItemRepository (MockRepositoryFactory ().success()).fetchItems(10 ) }.response!! )) as AppState
215217 return initialState
216218 }
217219
218- val justinTimberlake = Item (ItemId (" 0" ), " " , " Justin" , " Timberlake" )
219- val bobEvans = Item (ItemId (" 1" ), " " , " Bob" , " Evans" )
220- val stanLee = Item (ItemId (" 2" ), " " , " Stan" , " Lee" )
221- val lukeSkywalker = Item (ItemId (" 3" ), " " , " Luke" , " Skywalker" )
220+ private val justinTimberlake = Item (ItemId (" 0" ), " " , " Justin" , " Timberlake" )
221+ private val bobEvans = Item (ItemId (" 1" ), " " , " Bob" , " Evans" )
222+ private val stanLee = Item (ItemId (" 2" ), " " , " Stan" , " Lee" )
223+ private val lukeSkywalker = Item (ItemId (" 3" ), " " , " Luke" , " Skywalker" )
222224
223225 fun staticTestState (correctAnswer : Item ): AppState {
224226
0 commit comments