diff --git a/CHANGES.md b/CHANGES.md index 12274a3e4c..08eafff2d3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -45,6 +45,7 @@ Bugfix 🐛: - Fix issue with media path (#1227) - Add user to direct chat by user id (#1065) - Use correct URL for SSO connection (#1178) + - Emoji completion :tada: does not completes to 🎉 like on web (#1285) Translations 🗣: - diff --git a/matrix-sdk-android/src/sharedTest/java/im/vector/matrix/android/test/shared/TestRules.kt b/matrix-sdk-android/src/sharedTest/java/im/vector/matrix/android/test/shared/TestRules.kt index 77408322c1..bf073ecbc3 100644 --- a/matrix-sdk-android/src/sharedTest/java/im/vector/matrix/android/test/shared/TestRules.kt +++ b/matrix-sdk-android/src/sharedTest/java/im/vector/matrix/android/test/shared/TestRules.kt @@ -18,7 +18,7 @@ package im.vector.matrix.android.test.shared import net.lachlanmckee.timberjunit.TimberTestRule -fun createTimberTestRule(): TimberTestRule { +internal fun createTimberTestRule(): TimberTestRule { return TimberTestRule.builder() .showThread(false) .showTimestamp(false) diff --git a/vector/build.gradle b/vector/build.gradle index 2a898f5621..69608cf712 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -235,6 +235,15 @@ android { kotlinOptions { jvmTarget = "1.8" } + + sourceSets { + androidTest { + java.srcDirs += "src/sharedTest/java" + } + test { + java.srcDirs += "src/sharedTest/java" + } + } } dependencies { @@ -250,6 +259,7 @@ dependencies { def daggerVersion = '2.25.4' def autofill_version = "1.0.0" def work_version = '2.3.3' + def arch_version = '2.1.0' implementation project(":matrix-sdk-android") implementation project(":matrix-sdk-android-rx") @@ -378,10 +388,18 @@ dependencies { // TESTS testImplementation 'junit:junit:4.12' testImplementation 'org.amshove.kluent:kluent-android:1.44' + // Plant Timber tree for test + testImplementation 'net.lachlanmckee:timber-junit-rule:1.0.1' + androidTestImplementation 'androidx.test:core:1.2.0' androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestImplementation 'androidx.test:rules:1.2.0' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' androidTestImplementation 'org.amshove.kluent:kluent-android:1.44' + androidTestImplementation "androidx.arch.core:core-testing:$arch_version" + // Plant Timber tree for test + androidTestImplementation 'net.lachlanmckee:timber-junit-rule:1.0.1' } if (getGradle().getStartParameter().getTaskRequests().toString().contains("Gplay")) { diff --git a/vector/src/androidTest/java/im/vector/riotx/InstrumentedTest.kt b/vector/src/androidTest/java/im/vector/riotx/InstrumentedTest.kt new file mode 100644 index 0000000000..c34a3ef67b --- /dev/null +++ b/vector/src/androidTest/java/im/vector/riotx/InstrumentedTest.kt @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx + +import android.content.Context +import androidx.test.core.app.ApplicationProvider +import im.vector.riotx.test.shared.createTimberTestRule +import org.junit.Rule + +interface InstrumentedTest { + + @Rule + fun timberTestRule() = createTimberTestRule() + + fun context(): Context { + return ApplicationProvider.getApplicationContext() + } +} diff --git a/vector/src/androidTest/java/im/vector/riotx/features/reactions/data/EmojiDataSourceTest.kt b/vector/src/androidTest/java/im/vector/riotx/features/reactions/data/EmojiDataSourceTest.kt new file mode 100644 index 0000000000..a3e45c3cf2 --- /dev/null +++ b/vector/src/androidTest/java/im/vector/riotx/features/reactions/data/EmojiDataSourceTest.kt @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2020 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx.features.reactions.data + +import im.vector.riotx.InstrumentedTest +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.runners.MethodSorters +import kotlin.system.measureTimeMillis + +@RunWith(JUnit4::class) +@FixMethodOrder(MethodSorters.JVM) +class EmojiDataSourceTest : InstrumentedTest { + + @Test + fun checkParsingTime() { + val time = measureTimeMillis { + EmojiDataSource(context().resources) + } + + assertTrue("Too long to parse", time < 100) + } + + @Test + fun checkNumberOfResult() { + val emojiDataSource = EmojiDataSource(context().resources) + + assertEquals("Wrong number of emojis", 1545, emojiDataSource.rawData.emojis.size) + assertEquals("Wrong number of categories", 8, emojiDataSource.rawData.categories.size) + assertEquals("Wrong number of aliases", 57, emojiDataSource.rawData.aliases.size) + } + + @Test + fun searchTestEmptySearch() { + val emojiDataSource = EmojiDataSource(context().resources) + + assertEquals("Empty search should return 1545 results", 1545, emojiDataSource.filterWith("").size) + } + + @Test + fun searchTestNoResult() { + val emojiDataSource = EmojiDataSource(context().resources) + + assertTrue("Should not have result", emojiDataSource.filterWith("noresult").isEmpty()) + } + + @Test + fun searchTestOneResult() { + val emojiDataSource = EmojiDataSource(context().resources) + + assertEquals("Should have 1 result", 1, emojiDataSource.filterWith("france").size) + } + + @Test + fun searchTestManyResult() { + val emojiDataSource = EmojiDataSource(context().resources) + + assertTrue("Should have many result", emojiDataSource.filterWith("fra").size > 1) + } + + @Test + fun testTada() { + val emojiDataSource = EmojiDataSource(context().resources) + + val result = emojiDataSource.filterWith("tada") + + assertEquals("Should find tada emoji", 1, result.size) + assertEquals("Should find tada emoji", "🎉", result[0].emoji) + } + + @Test + fun testQuickReactions() { + val emojiDataSource = EmojiDataSource(context().resources) + + assertEquals("Should have 8 quick reactions", 8, emojiDataSource.getQuickReactions().size) + } +} diff --git a/vector/src/main/java/im/vector/riotx/features/reactions/data/EmojiDataSource.kt b/vector/src/main/java/im/vector/riotx/features/reactions/data/EmojiDataSource.kt index 1d7338e2a4..4acb8ed79e 100644 --- a/vector/src/main/java/im/vector/riotx/features/reactions/data/EmojiDataSource.kt +++ b/vector/src/main/java/im/vector/riotx/features/reactions/data/EmojiDataSource.kt @@ -32,6 +32,23 @@ class EmojiDataSource @Inject constructor( .adapter(EmojiData::class.java) .fromJson(input.bufferedReader().use { it.readText() }) } + ?.let { parsedRawData -> + // Add key as a keyword, it will solve the issue that ":tada" is not available in completion + parsedRawData.copy( + emojis = mutableMapOf().apply { + parsedRawData.emojis.keys.forEach { key -> + val origin = parsedRawData.emojis[key] ?: return@forEach + + // Do not add keys containing '_' + if (origin.keywords.contains(key) || key.contains("_")) { + put(key, origin) + } else { + put(key, origin.copy(keywords = origin.keywords + key)) + } + } + } + ) + } ?: EmojiData(emptyList(), emptyMap(), emptyMap()) private val quickReactions = mutableListOf() diff --git a/vector/src/sharedTest/java/im/vector/riotx/test/shared/TestRules.kt b/vector/src/sharedTest/java/im/vector/riotx/test/shared/TestRules.kt new file mode 100644 index 0000000000..d5790ba497 --- /dev/null +++ b/vector/src/sharedTest/java/im/vector/riotx/test/shared/TestRules.kt @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2020 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx.test.shared + +import net.lachlanmckee.timberjunit.TimberTestRule + +fun createTimberTestRule(): TimberTestRule { + return TimberTestRule.builder() + .showThread(false) + .showTimestamp(false) + .onlyLogWhenTestFails(false) + .build() +}