-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Communication
: Fix Tagging other Users does not work (#71)
- Loading branch information
1 parent
187c979
commit 2f2d1e9
Showing
8 changed files
with
246 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...s/www1/artemis/native_app/feature/metis/conversation/ConversationAutoCompletionE2eTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package de.tum.informatics.www1.artemis.native_app.feature.metis.conversation | ||
|
||
import de.tum.informatics.www1.artemis.native_app.core.common.test.EndToEndTest | ||
import de.tum.informatics.www1.artemis.native_app.core.common.test.DefaultTestTimeoutMillis | ||
import de.tum.informatics.www1.artemis.native_app.core.test.test_setup.DefaultTimeoutMillis | ||
import de.tum.informatics.www1.artemis.native_app.core.common.test.testServerUrl | ||
import de.tum.informatics.www1.artemis.native_app.core.model.account.User | ||
import de.tum.informatics.www1.artemis.native_app.feature.login.test.user1Username | ||
import de.tum.informatics.www1.artemis.native_app.feature.login.test.user2Username | ||
import de.tum.informatics.www1.artemis.native_app.feature.login.test.user3Username | ||
import de.tum.informatics.www1.artemis.native_app.feature.metistest.ConversationBaseTest | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Test | ||
import org.junit.experimental.categories.Category | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
import org.robolectric.util.Logger | ||
import kotlin.test.assertTrue | ||
import kotlin.test.assertEquals | ||
import kotlin.time.Duration.Companion.milliseconds | ||
|
||
|
||
@Category(EndToEndTest::class) | ||
@RunWith(RobolectricTestRunner::class) | ||
class ConversationAutoCompletionE2eTest : ConversationBaseTest() { | ||
|
||
@Test(timeout = DefaultTestTimeoutMillis) | ||
fun `test GIVEN users are registered in a course WHEN requesting auto complete users THEN the registered users are returned`() { | ||
val users = listOf( | ||
User(username = user1Username), | ||
User(username = user2Username), | ||
User(username = user3Username) | ||
) | ||
|
||
runTest(timeout = DefaultTimeoutMillis.milliseconds) { | ||
|
||
val typedText = "user" | ||
val autoCompleteSuggestions = conversationService.searchForCourseMembers( | ||
courseId = course.id!!, | ||
query = typedText, | ||
authToken = accessToken, | ||
serverUrl = testServerUrl | ||
).orThrow("Could not get auto-complete suggestions") | ||
|
||
Logger.info("Auto-complete suggestions: $autoCompleteSuggestions") | ||
|
||
assertEquals(users.size, autoCompleteSuggestions.size) | ||
|
||
users.forEach { user -> | ||
assertTrue( | ||
autoCompleteSuggestions.any { it.username == user.username }, | ||
"Auto-complete suggestions do not contain user $user" | ||
) | ||
} | ||
} | ||
} | ||
} |
146 changes: 146 additions & 0 deletions
146
...atics/www1/artemis/native_app/feature/metis/conversation/ui/reply/ReplyTextFieldUiTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package de.tum.informatics.www1.artemis.native_app.feature.metis.conversation.ui.reply | ||
|
||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.test.assertTextEquals | ||
import androidx.compose.ui.test.junit4.ComposeContentTestRule | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithTag | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performTextInput | ||
import androidx.compose.ui.test.performClick | ||
import androidx.compose.ui.test.performTextClearance | ||
import androidx.compose.ui.text.input.TextFieldValue | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import de.tum.informatics.www1.artemis.native_app.core.data.DataState | ||
import de.tum.informatics.www1.artemis.native_app.feature.metis.conversation.R | ||
import kotlinx.coroutines.CompletableDeferred | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flowOf | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class ReplyTextFieldUiTest { | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
private val autoCompleteHints = listOf( | ||
AutoCompleteCategory( | ||
R.string.markdown_textfield_autocomplete_category_users, listOf( | ||
AutoCompleteHint("User1", "<User1>", "1"), | ||
AutoCompleteHint("User2", "<User2>", "2"), | ||
AutoCompleteHint("User3", "<User3>", "3"), | ||
)) | ||
) | ||
|
||
private val hintProviderStub = object : ReplyAutoCompleteHintProvider { | ||
override val legalTagChars: List<Char> = listOf('@') | ||
override fun produceAutoCompleteHints(tagChar: Char, query: String): Flow<DataState<List<AutoCompleteCategory>>> { | ||
return flowOf(DataState.Success(autoCompleteHints)) | ||
} | ||
} | ||
|
||
@Before | ||
fun setUp() { | ||
composeTestRule.setContent { | ||
CompositionLocalProvider(LocalReplyAutoCompleteHintProvider provides hintProviderStub) { | ||
val text = remember { mutableStateOf(TextFieldValue()) } | ||
|
||
ReplyTextField( | ||
modifier = Modifier.fillMaxSize(), | ||
replyMode = ReplyMode.NewMessage( | ||
text, | ||
onUpdateTextUpstream = { text.value = it } | ||
) { | ||
CompletableDeferred() | ||
}, | ||
updateFailureState = {}, | ||
title = "TestChat" | ||
) | ||
} | ||
} | ||
|
||
// Click the unfocused textField to focus and expand the textField | ||
composeTestRule.onNodeWithTag(TEST_TAG_UNFOCUSED_TEXT_FIELD).performClick() | ||
} | ||
|
||
@Test | ||
fun `test GIVEN an empty reply textField WHEN doing nothing THEN the autoCompletion dialog is hidden`() { | ||
composeTestRule.assertAllAutoCompletionHintsHidden() | ||
} | ||
|
||
@Test | ||
fun `test GIVEN an empty reply textField WHEN entering the tag character @ THEN a list of autoCompletionHints for users shows`() { | ||
composeTestRule.onNodeWithTag(TEST_TAG_MARKDOWN_TEXTFIELD).performTextInput("@") | ||
composeTestRule.assertAllAutoCompletionHintsShown() | ||
} | ||
|
||
@Test | ||
fun `test GIVEN the autoCompletion dialog WHEN clicking an entry THEN the replacement is inserted into the textField and the dialog is hidden`() { | ||
composeTestRule.onNodeWithTag(TEST_TAG_MARKDOWN_TEXTFIELD).performTextInput("@") | ||
|
||
composeTestRule.onNodeWithText("User1").performClick() | ||
|
||
composeTestRule.onNodeWithTag(TEST_TAG_MARKDOWN_TEXTFIELD).assertTextEquals("<User1>") | ||
composeTestRule.assertAllAutoCompletionHintsHidden() | ||
} | ||
|
||
@Test | ||
fun `test GIVEN the textField WHEN entering a non-tag character THEN the autoCompletion dialog is hidden`() { | ||
composeTestRule.onNodeWithTag(TEST_TAG_MARKDOWN_TEXTFIELD).performTextInput("a") | ||
composeTestRule.assertAllAutoCompletionHintsHidden() | ||
} | ||
|
||
@Test | ||
fun `test GIVEN the autoCompletion dialog WHEN removing the tag character @ THEN the autoCompletion dialog is hidden`() { | ||
composeTestRule.onNodeWithTag(TEST_TAG_MARKDOWN_TEXTFIELD).performTextInput("@") | ||
composeTestRule.assertAllAutoCompletionHintsShown() | ||
|
||
composeTestRule.onNodeWithTag(TEST_TAG_MARKDOWN_TEXTFIELD).performTextClearance() | ||
composeTestRule.assertAllAutoCompletionHintsHidden() | ||
} | ||
|
||
@Test | ||
fun `test GIVEN the autoCompletion has been performed WHEN entering the tag character again THEN the autoCompletion dialog shows again`() { | ||
composeTestRule.onNodeWithTag(TEST_TAG_MARKDOWN_TEXTFIELD).performTextInput("@") | ||
composeTestRule.onNodeWithText("User1").performClick() | ||
composeTestRule.onNodeWithTag(TEST_TAG_MARKDOWN_TEXTFIELD).assertTextEquals("<User1>") | ||
composeTestRule.assertAllAutoCompletionHintsHidden() | ||
|
||
composeTestRule.onNodeWithTag(TEST_TAG_MARKDOWN_TEXTFIELD).performTextInput("@") | ||
composeTestRule.assertAllAutoCompletionHintsShown() | ||
} | ||
|
||
@Test | ||
fun `test GIVEN the textField WHEN entering a first and surname separated by a single whitespace THEN the dialog shows`() { | ||
composeTestRule.onNodeWithTag(TEST_TAG_MARKDOWN_TEXTFIELD).performTextInput("@FirstName SurName") | ||
composeTestRule.assertAllAutoCompletionHintsShown() | ||
} | ||
|
||
@Test | ||
fun `test GIVEN the textField WHEN entering a second whitespace THEN the dialog is hidden`() { | ||
composeTestRule.onNodeWithTag(TEST_TAG_MARKDOWN_TEXTFIELD).performTextInput("@FirstName SurName ") | ||
composeTestRule.assertAllAutoCompletionHintsHidden() | ||
} | ||
|
||
|
||
|
||
private fun ComposeContentTestRule.assertAllAutoCompletionHintsHidden() { | ||
onNodeWithText("User1").assertDoesNotExist() | ||
onNodeWithText("User2").assertDoesNotExist() | ||
onNodeWithText("User3").assertDoesNotExist() | ||
} | ||
|
||
private fun ComposeContentTestRule.assertAllAutoCompletionHintsShown() { | ||
onNodeWithText("User1").assertExists() | ||
onNodeWithText("User2").assertExists() | ||
onNodeWithText("User3").assertExists() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters