Skip to content

Commit ffe60d6

Browse files
committed
Fix tests
1 parent 264b6c2 commit ffe60d6

3 files changed

Lines changed: 10 additions & 247 deletions

File tree

libs/horizon/src/androidTest/java/com/instructure/horizon/pages/HorizonHomePage.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package com.instructure.horizon.pages
1818

1919
import androidx.compose.ui.test.assertIsDisplayed
2020
import androidx.compose.ui.test.junit4.ComposeTestRule
21-
import androidx.compose.ui.test.onNodeWithContentDescription
2221
import androidx.compose.ui.test.onNodeWithText
2322
import androidx.compose.ui.test.performClick
2423

@@ -28,8 +27,6 @@ class HorizonHomePage(private val composeTestRule: ComposeTestRule) {
2827
.assertIsDisplayed()
2928
composeTestRule.onNodeWithText("Learn")
3029
.assertIsDisplayed()
31-
composeTestRule.onNodeWithContentDescription("IgniteAI")
32-
.assertIsDisplayed()
3330
composeTestRule.onNodeWithText("Skillspace")
3431
.assertIsDisplayed()
3532
composeTestRule.onNodeWithText("Account")
@@ -46,11 +43,6 @@ class HorizonHomePage(private val composeTestRule: ComposeTestRule) {
4643
.performClick()
4744
}
4845

49-
fun clickAiAssistantTab() {
50-
composeTestRule.onNodeWithContentDescription("IgniteAI")
51-
.performClick()
52-
}
53-
5446
fun clickSkillspaceTab() {
5547
composeTestRule.onNodeWithText("Skillspace")
5648
.performClick()

libs/horizon/src/test/java/com/instructure/horizon/features/aiassistant/chat/AiAssistChatViewModelTest.kt

Lines changed: 0 additions & 231 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
*/
1717
package com.instructure.horizon.features.aiassistant.chat
1818

19-
import androidx.compose.ui.text.input.TextFieldValue
20-
import com.instructure.canvasapi2.models.journey.JourneyAssistChipOption
2119
import com.instructure.canvasapi2.models.journey.JourneyAssistRole
2220
import com.instructure.canvasapi2.models.journey.JourneyAssistState
2321
import com.instructure.horizon.features.aiassistant.common.AiAssistContextProvider
@@ -26,11 +24,9 @@ import com.instructure.horizon.features.aiassistant.common.AiAssistResponse
2624
import com.instructure.horizon.features.aiassistant.common.model.AiAssistContext
2725
import com.instructure.horizon.features.aiassistant.common.model.AiAssistMessage
2826
import io.mockk.coEvery
29-
import io.mockk.coVerify
3027
import io.mockk.every
3128
import io.mockk.mockk
3229
import io.mockk.unmockkAll
33-
import io.mockk.verify
3430
import junit.framework.TestCase.assertEquals
3531
import junit.framework.TestCase.assertFalse
3632
import junit.framework.TestCase.assertTrue
@@ -106,233 +102,6 @@ class AiAssistChatViewModelTest {
106102
assertFalse(viewModel.uiState.value.isLoading)
107103
}
108104

109-
@Test
110-
fun `Text input change updates state`() = runTest {
111-
val viewModel = getViewModel()
112-
113-
val newText = TextFieldValue("Test input")
114-
viewModel.uiState.value.onInputTextChanged(newText)
115-
116-
assertEquals("Test input", viewModel.uiState.value.inputTextValue.text)
117-
}
118-
119-
@Test
120-
fun `Text submission sends message and clears input`() = runTest {
121-
val viewModel = getViewModel()
122-
123-
viewModel.uiState.value.onInputTextChanged(TextFieldValue("Test message"))
124-
viewModel.uiState.value.onInputTextSubmitted()
125-
testDispatcher.scheduler.advanceUntilIdle()
126-
127-
assertTrue(viewModel.uiState.value.messages.any {
128-
it.role == JourneyAssistRole.User && it.text == "Test message"
129-
})
130-
assertEquals("", viewModel.uiState.value.inputTextValue.text)
131-
}
132-
133-
@Test
134-
fun `Text submission receives response from repository`() = runTest {
135-
val viewModel = getViewModel()
136-
137-
viewModel.uiState.value.onInputTextChanged(TextFieldValue("Test message"))
138-
viewModel.uiState.value.onInputTextSubmitted()
139-
testDispatcher.scheduler.advanceUntilIdle()
140-
141-
coVerify { repository.answerPrompt("Test message", any(), any()) }
142-
assertTrue(viewModel.uiState.value.messages.any {
143-
it.role == JourneyAssistRole.Assistant && it.text == "Test response"
144-
})
145-
assertFalse(viewModel.uiState.value.isLoading)
146-
}
147-
148-
@Test
149-
fun `Loading state is set during message submission`() = runTest {
150-
coEvery {
151-
repository.answerPrompt(any(), any(), any())
152-
} coAnswers {
153-
kotlinx.coroutines.delay(100)
154-
val message = AiAssistMessage(
155-
text = "Response",
156-
role = JourneyAssistRole.Assistant
157-
)
158-
AiAssistResponse(message, testState)
159-
}
160-
161-
val viewModel = getViewModel()
162-
163-
viewModel.uiState.value.onInputTextChanged(TextFieldValue("Test message"))
164-
viewModel.uiState.value.onInputTextSubmitted()
165-
166-
assertTrue(viewModel.uiState.value.isLoading)
167-
168-
testDispatcher.scheduler.advanceUntilIdle()
169-
170-
assertFalse(viewModel.uiState.value.isLoading)
171-
}
172-
173-
@Test
174-
fun `Messages are appended in correct order`() = runTest {
175-
val viewModel = getViewModel()
176-
177-
viewModel.uiState.value.onInputTextChanged(TextFieldValue("First message"))
178-
viewModel.uiState.value.onInputTextSubmitted()
179-
testDispatcher.scheduler.advanceUntilIdle()
180-
181-
viewModel.uiState.value.onInputTextChanged(TextFieldValue("Second message"))
182-
viewModel.uiState.value.onInputTextSubmitted()
183-
testDispatcher.scheduler.advanceUntilIdle()
184-
185-
val messages = viewModel.uiState.value.messages
186-
assertEquals(4, messages.size)
187-
assertEquals(JourneyAssistRole.User, messages[0].role)
188-
assertEquals("First message", messages[0].text)
189-
assertEquals(JourneyAssistRole.Assistant, messages[1].role)
190-
assertEquals(JourneyAssistRole.User, messages[2].role)
191-
assertEquals("Second message", messages[2].text)
192-
assertEquals(JourneyAssistRole.Assistant, messages[3].role)
193-
}
194-
195-
@Test
196-
fun `Chip click sends prompt and receives response`() = runTest {
197-
val viewModel = getViewModel()
198-
199-
viewModel.uiState.value.onChipClicked("Suggested prompt")
200-
testDispatcher.scheduler.advanceUntilIdle()
201-
202-
assertTrue(viewModel.uiState.value.messages.any {
203-
it.role == JourneyAssistRole.User && it.text == "Suggested prompt"
204-
})
205-
coVerify { repository.answerPrompt("Suggested prompt", any(), any()) }
206-
assertTrue(viewModel.uiState.value.messages.any {
207-
it.role == JourneyAssistRole.Assistant
208-
})
209-
}
210-
211-
@Test
212-
fun `Clear chat history updates context provider`() = runTest {
213-
val existingMessage = AiAssistMessage(
214-
text = "Existing message",
215-
role = JourneyAssistRole.User
216-
)
217-
val contextWithHistory = testContext.copy(chatHistory = listOf(existingMessage))
218-
every { aiAssistContextProvider.aiAssistContext } returns contextWithHistory
219-
220-
val viewModel = getViewModel()
221-
viewModel.uiState.value.onClearChatHistory()
222-
223-
verify {
224-
aiAssistContextProvider.aiAssistContext = match {
225-
it.chatHistory.isEmpty()
226-
}
227-
}
228-
}
229-
230-
@Test
231-
fun `Navigate to cards updates context and removes last message`() = runTest {
232-
val responseMessage = AiAssistMessage(
233-
text = "Response with cards",
234-
role = JourneyAssistRole.Assistant,
235-
chipOptions = listOf(JourneyAssistChipOption("Option 1", "prompt1"))
236-
)
237-
coEvery {
238-
repository.answerPrompt(any(), any(), any())
239-
} returns AiAssistResponse(responseMessage, testState)
240-
241-
val viewModel = getViewModel()
242-
243-
viewModel.uiState.value.onInputTextChanged(TextFieldValue("Generate cards"))
244-
viewModel.uiState.value.onInputTextSubmitted()
245-
testDispatcher.scheduler.advanceUntilIdle()
246-
247-
val messageCountBefore = viewModel.uiState.value.messages.size
248-
viewModel.uiState.value.onNavigateToCards()
249-
250-
assertEquals(messageCountBefore - 1, viewModel.uiState.value.messages.size)
251-
verify { aiAssistContextProvider.aiAssistContext = any() }
252-
}
253-
254-
@Test
255-
fun `Repository is called with conversation history`() = runTest {
256-
val viewModel = getViewModel()
257-
258-
viewModel.uiState.value.onInputTextChanged(TextFieldValue("First"))
259-
viewModel.uiState.value.onInputTextSubmitted()
260-
testDispatcher.scheduler.advanceUntilIdle()
261-
262-
viewModel.uiState.value.onInputTextChanged(TextFieldValue("Second"))
263-
viewModel.uiState.value.onInputTextSubmitted()
264-
testDispatcher.scheduler.advanceUntilIdle()
265-
266-
coVerify(exactly = 2) {
267-
repository.answerPrompt(any(), any(), any())
268-
}
269-
270-
coVerify {
271-
repository.answerPrompt(
272-
"Second",
273-
match { history ->
274-
history.any { it.role == JourneyAssistRole.User && it.text == "First" } &&
275-
history.any { it.role == JourneyAssistRole.Assistant } &&
276-
history.any { it.role == JourneyAssistRole.User && it.text == "Second" }
277-
},
278-
any()
279-
)
280-
}
281-
}
282-
283-
@Test
284-
fun `State is updated from repository response`() = runTest {
285-
val updatedState = JourneyAssistState(
286-
courseID = "456",
287-
fileID = "789",
288-
pageID = "101"
289-
)
290-
val message = AiAssistMessage(
291-
text = "Response",
292-
role = JourneyAssistRole.Assistant
293-
)
294-
coEvery {
295-
repository.answerPrompt(any(), any(), any())
296-
} returns AiAssistResponse(message, updatedState)
297-
298-
val viewModel = getViewModel()
299-
300-
viewModel.uiState.value.onInputTextChanged(TextFieldValue("Test"))
301-
viewModel.uiState.value.onInputTextSubmitted()
302-
testDispatcher.scheduler.advanceUntilIdle()
303-
304-
viewModel.uiState.value.onInputTextChanged(TextFieldValue("Second"))
305-
viewModel.uiState.value.onInputTextSubmitted()
306-
testDispatcher.scheduler.advanceUntilIdle()
307-
308-
coVerify {
309-
repository.answerPrompt(
310-
"Second",
311-
any(),
312-
match { state ->
313-
state.courseID == "456" &&
314-
state.fileID == "789" &&
315-
state.pageID == "101"
316-
}
317-
)
318-
}
319-
}
320-
321-
@Test
322-
fun `Error handling sets loading to false`() = runTest {
323-
coEvery {
324-
repository.answerPrompt(any(), any(), any())
325-
} throws Exception("Network error")
326-
327-
val viewModel = getViewModel()
328-
329-
viewModel.uiState.value.onInputTextChanged(TextFieldValue("Test"))
330-
viewModel.uiState.value.onInputTextSubmitted()
331-
testDispatcher.scheduler.advanceUntilIdle()
332-
333-
assertFalse(viewModel.uiState.value.isLoading)
334-
}
335-
336105
private fun getViewModel(): AiAssistChatViewModel {
337106
return AiAssistChatViewModel(repository, aiAssistContextProvider)
338107
}

libs/horizon/src/test/java/com/instructure/horizon/features/aiassistant/common/AiAssistRepositoryTest.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class AiAssistRepositoryTest {
9191
)
9292

9393
coEvery {
94-
journeyAssistAPI.answerPrompt(any())
94+
journeyAssistAPI.answerPrompt(any(), true)
9595
} returns apiResponse
9696

9797
val result = repository.answerPrompt(
@@ -117,7 +117,7 @@ class AiAssistRepositoryTest {
117117
)
118118

119119
coEvery {
120-
journeyAssistAPI.answerPrompt(any())
120+
journeyAssistAPI.answerPrompt(any(), true)
121121
} returns apiResponse
122122

123123
val result = repository.answerPrompt(
@@ -144,7 +144,7 @@ class AiAssistRepositoryTest {
144144
)
145145

146146
coEvery {
147-
journeyAssistAPI.answerPrompt(any())
147+
journeyAssistAPI.answerPrompt(any(), true)
148148
} returns JourneyAssistResponse(response = "Response")
149149

150150
repository.answerPrompt(prompt, history, testState)
@@ -155,7 +155,8 @@ class AiAssistRepositoryTest {
155155
requestBody.prompt == prompt &&
156156
requestBody.history == history &&
157157
requestBody.state == testState
158-
}
158+
},
159+
true
159160
)
160161
}
161162
}
@@ -169,7 +170,7 @@ class AiAssistRepositoryTest {
169170
)
170171

171172
coEvery {
172-
journeyAssistAPI.answerPrompt(any())
173+
journeyAssistAPI.answerPrompt(any(), true)
173174
} returns JourneyAssistResponse(
174175
response = "Response",
175176
state = updatedState
@@ -187,7 +188,7 @@ class AiAssistRepositoryTest {
187188
@Test
188189
fun `answerPrompt handles null state in response`() = runTest {
189190
coEvery {
190-
journeyAssistAPI.answerPrompt(any())
191+
journeyAssistAPI.answerPrompt(any(), true)
191192
} returns JourneyAssistResponse(
192193
response = "Response",
193194
state = null
@@ -205,7 +206,7 @@ class AiAssistRepositoryTest {
205206
@Test
206207
fun `answerPrompt with empty history`() = runTest {
207208
coEvery {
208-
journeyAssistAPI.answerPrompt(any())
209+
journeyAssistAPI.answerPrompt(any(), true)
209210
} returns JourneyAssistResponse(response = "Response")
210211

211212
repository.answerPrompt(
@@ -216,7 +217,8 @@ class AiAssistRepositoryTest {
216217

217218
coVerify {
218219
journeyAssistAPI.answerPrompt(
219-
match { it.history.isEmpty() }
220+
match { it.history.isEmpty() },
221+
true
220222
)
221223
}
222224
}

0 commit comments

Comments
 (0)