From fe087828034599a4f0ffe771fea7215175abbf0c Mon Sep 17 00:00:00 2001 From: Matthieu <24-artectrex@users.noreply.shinice.net> Date: Thu, 11 Feb 2021 01:24:05 +0100 Subject: [PATCH] At least make integration tests compile --- .../java/com/h/pixeldroid/CameraTest.kt | 12 +++---- .../java/com/h/pixeldroid/DrawerMenuTest.kt | 12 +++---- .../java/com/h/pixeldroid/EditPhotoTest.kt | 20 ++++++------ .../java/com/h/pixeldroid/HomeFeedTest.kt | 6 ++-- .../java/com/h/pixeldroid/IntentTest.kt | 6 ++-- .../h/pixeldroid/LoginActivityOnlineTest.kt | 6 ++-- .../java/com/h/pixeldroid/LoginCheckIntent.kt | 3 -- .../h/pixeldroid/PostCreationFragmentTest.kt | 10 +++--- .../java/com/h/pixeldroid/PostTest.kt | 32 +++++++++++-------- .../photoEdit/PhotoEditActivity.kt | 2 +- 10 files changed, 55 insertions(+), 54 deletions(-) diff --git a/app/src/androidTest/java/com/h/pixeldroid/CameraTest.kt b/app/src/androidTest/java/com/h/pixeldroid/CameraTest.kt index e5ca9d0f..66835e54 100644 --- a/app/src/androidTest/java/com/h/pixeldroid/CameraTest.kt +++ b/app/src/androidTest/java/com/h/pixeldroid/CameraTest.kt @@ -4,6 +4,7 @@ import android.Manifest import android.content.Context import android.content.Intent import android.content.Intent.ACTION_CHOOSER +import android.widget.ImageButton import androidx.fragment.app.testing.launchFragmentInContainer import androidx.test.core.app.ApplicationProvider import androidx.test.espresso.intent.Intents @@ -14,7 +15,6 @@ import com.h.pixeldroid.utils.db.entities.UserDatabaseEntity import com.h.pixeldroid.postCreation.camera.CameraFragment import com.h.pixeldroid.testUtility.clearData import com.h.pixeldroid.testUtility.initDB -import kotlinx.android.synthetic.main.camera_ui_container.* import org.hamcrest.CoreMatchers import org.hamcrest.Matcher import org.junit.After @@ -50,9 +50,9 @@ class CameraTest { avatar_static = "some_avatar_url", isActive = true, accessToken = "token", - refreshToken = refreshToken, - clientId = clientId, - clientSecret = clientSecret + refreshToken = "refreshToken", + clientId = "clientId", + clientSecret = "clientSecret" ) ) db.close() @@ -88,7 +88,7 @@ class CameraTest { val scenario = launchFragmentInContainer() scenario.onFragment { fragment -> - fragment.photo_view_button.performClick() + fragment.view?.findViewById(R.id.photo_view_button)?.performClick() } Thread.sleep(1000) @@ -102,7 +102,7 @@ class CameraTest { fun switchButton() { val scenario = launchFragmentInContainer() scenario.onFragment { fragment -> - fragment.camera_switch_button.performClick() + fragment.view?.findViewById(R.id.camera_switch_button)?.performClick() } Thread.sleep(1000) scenario.onFragment { fragment -> diff --git a/app/src/androidTest/java/com/h/pixeldroid/DrawerMenuTest.kt b/app/src/androidTest/java/com/h/pixeldroid/DrawerMenuTest.kt index dde1f96c..a23d3869 100644 --- a/app/src/androidTest/java/com/h/pixeldroid/DrawerMenuTest.kt +++ b/app/src/androidTest/java/com/h/pixeldroid/DrawerMenuTest.kt @@ -61,9 +61,9 @@ class DrawerMenuTest { avatar_static = "some_avatar_url", isActive = true, accessToken = "token", - refreshToken = refreshToken, - clientId = clientId, - clientSecret = clientSecret + refreshToken = "refreshToken", + clientId = "clientId", + clientSecret = "clientSecret" ) ) db.close() @@ -132,8 +132,7 @@ class DrawerMenuTest { onView(withText(R.string.menu_account)).perform(click()) // Check that profile activity was opened. onView(withId(R.id.editButton)).check(matches(isDisplayed())) - val followersText = context.getString(R.string.nb_followers) - .format(68) + val followersText = context.resources.getQuantityString(R.plurals.nb_followers, 68) onView(withText(followersText)).perform(click()) onView(withText("Dobios")).check(matches(isDisplayed())) } @@ -144,8 +143,7 @@ class DrawerMenuTest { onView(withText(R.string.menu_account)).perform(click()) // Check that profile activity was opened. onView(withId(R.id.editButton)).check(matches(isDisplayed())) - val followingText = context.getString(R.string.nb_following) - .format(27) + val followingText = context.resources.getQuantityString(R.plurals.nb_followers, 27) onView(withText(followingText)).perform(click()) onView(withText("Dobios")).check(matches(isDisplayed())) } diff --git a/app/src/androidTest/java/com/h/pixeldroid/EditPhotoTest.kt b/app/src/androidTest/java/com/h/pixeldroid/EditPhotoTest.kt index 356cbd3b..1193e192 100644 --- a/app/src/androidTest/java/com/h/pixeldroid/EditPhotoTest.kt +++ b/app/src/androidTest/java/com/h/pixeldroid/EditPhotoTest.kt @@ -22,14 +22,14 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry import androidx.test.rule.GrantPermissionRule import com.google.android.material.tabs.TabLayout -import com.h.pixeldroid.adapters.ThumbnailAdapter +import com.h.pixeldroid.postCreation.photoEdit.PhotoEditActivity +import com.h.pixeldroid.postCreation.photoEdit.ThumbnailAdapter import com.h.pixeldroid.settings.AboutActivity import com.h.pixeldroid.testUtility.CustomMatchers import com.h.pixeldroid.testUtility.clearData -import junit.framework.Assert.assertTrue -import kotlinx.android.synthetic.main.fragment_edit_image.* import org.hamcrest.CoreMatchers.allOf import org.junit.* +import org.junit.Assert.assertTrue import org.junit.rules.Timeout import org.junit.runner.RunWith import java.io.File @@ -141,9 +141,9 @@ class EditPhotoTest { Espresso.onView(withId(R.id.seekbar_contrast)).perform(setProgress(change)) Espresso.onView(withId(R.id.seekbar_saturation)).perform(setProgress(change)) - Assert.assertEquals(change, activity.seekbar_brightness.progress) - Assert.assertEquals(change, activity.seekbar_contrast.progress) - Assert.assertEquals(change, activity.seekbar_saturation.progress) + Assert.assertEquals(change, activity.findViewById(R.id.seekbar_brightness).progress) + Assert.assertEquals(change, activity.findViewById(R.id.seekbar_contrast).progress) + Assert.assertEquals(change, activity.findViewById(R.id.seekbar_saturation).progress) Thread.sleep(1000) @@ -152,9 +152,9 @@ class EditPhotoTest { Espresso.onView(withId(R.id.seekbar_contrast)).perform(setProgress(change)) Espresso.onView(withId(R.id.seekbar_saturation)).perform(setProgress(change)) - Assert.assertEquals(change, activity.seekbar_brightness.progress) - Assert.assertEquals(change, activity.seekbar_contrast.progress) - Assert.assertEquals(change, activity.seekbar_saturation.progress) + Assert.assertEquals(change, activity.findViewById(R.id.seekbar_brightness).progress) + Assert.assertEquals(change, activity.findViewById(R.id.seekbar_contrast).progress) + Assert.assertEquals(change, activity.findViewById(R.id.seekbar_saturation).progress) } @Test @@ -181,7 +181,7 @@ class EditPhotoTest { @Test fun alreadyUploadingDialog() { activityScenario.onActivity { a -> a.saving = true } - Espresso.onView(withId(R.id.action_upload)).perform(click()) + Espresso.onView(withId(R.id.action_save)).perform(click()) Thread.sleep(1000) Espresso.onView(withText(R.string.busy_dialog_text)).check(matches(isDisplayed())) } diff --git a/app/src/androidTest/java/com/h/pixeldroid/HomeFeedTest.kt b/app/src/androidTest/java/com/h/pixeldroid/HomeFeedTest.kt index 0f188bac..98f340c6 100644 --- a/app/src/androidTest/java/com/h/pixeldroid/HomeFeedTest.kt +++ b/app/src/androidTest/java/com/h/pixeldroid/HomeFeedTest.kt @@ -68,9 +68,9 @@ class HomeFeedTest { avatar_static = "some_avatar_url", isActive = true, accessToken = "token", - refreshToken = refreshToken, - clientId = clientId, - clientSecret = clientSecret + refreshToken = "refreshToken", + clientId = "clientId", + clientSecret = "clientSecret" ) ) db.close() diff --git a/app/src/androidTest/java/com/h/pixeldroid/IntentTest.kt b/app/src/androidTest/java/com/h/pixeldroid/IntentTest.kt index fc1a9226..38957ee0 100644 --- a/app/src/androidTest/java/com/h/pixeldroid/IntentTest.kt +++ b/app/src/androidTest/java/com/h/pixeldroid/IntentTest.kt @@ -85,9 +85,9 @@ class IntentTest { avatar_static = "some_avatar_url", isActive = true, accessToken = "token", - refreshToken = refreshToken, - clientId = clientId, - clientSecret = clientSecret + refreshToken = "refreshToken", + clientId = "clientId", + clientSecret = "clientSecret" ) ) db.close() diff --git a/app/src/androidTest/java/com/h/pixeldroid/LoginActivityOnlineTest.kt b/app/src/androidTest/java/com/h/pixeldroid/LoginActivityOnlineTest.kt index 35ece520..78530895 100644 --- a/app/src/androidTest/java/com/h/pixeldroid/LoginActivityOnlineTest.kt +++ b/app/src/androidTest/java/com/h/pixeldroid/LoginActivityOnlineTest.kt @@ -124,9 +124,9 @@ class LoginActivityOnlineTest { avatar_static = "some_avatar_url", isActive = true, accessToken = "token", - refreshToken = refreshToken, - clientId = clientId, - clientSecret = clientSecret + refreshToken = "refreshToken", + clientId = "clientId", + clientSecret = "clientSecret" ) ) db.close() diff --git a/app/src/androidTest/java/com/h/pixeldroid/LoginCheckIntent.kt b/app/src/androidTest/java/com/h/pixeldroid/LoginCheckIntent.kt index 37c292ea..78219fbc 100644 --- a/app/src/androidTest/java/com/h/pixeldroid/LoginCheckIntent.kt +++ b/app/src/androidTest/java/com/h/pixeldroid/LoginCheckIntent.kt @@ -1,6 +1,5 @@ package com.h.pixeldroid -import android.content.Context import android.content.Intent import android.content.Intent.ACTION_VIEW import androidx.test.core.app.ActivityScenario @@ -28,8 +27,6 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class LoginCheckIntent { - private lateinit var context: Context - @get:Rule var globalTimeout: Timeout = Timeout.seconds(100) diff --git a/app/src/androidTest/java/com/h/pixeldroid/PostCreationFragmentTest.kt b/app/src/androidTest/java/com/h/pixeldroid/PostCreationFragmentTest.kt index 4dea5921..2f2fa227 100644 --- a/app/src/androidTest/java/com/h/pixeldroid/PostCreationFragmentTest.kt +++ b/app/src/androidTest/java/com/h/pixeldroid/PostCreationFragmentTest.kt @@ -16,13 +16,13 @@ import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry import androidx.test.rule.GrantPermissionRule +import com.google.android.material.tabs.TabLayout import com.h.pixeldroid.utils.db.AppDatabase import com.h.pixeldroid.utils.db.entities.InstanceDatabaseEntity import com.h.pixeldroid.utils.db.entities.UserDatabaseEntity import com.h.pixeldroid.testUtility.MockServer import com.h.pixeldroid.testUtility.clearData import com.h.pixeldroid.testUtility.initDB -import kotlinx.android.synthetic.main.activity_main.* import org.hamcrest.Matcher import org.junit.After import org.junit.Before @@ -96,9 +96,9 @@ class PostFragmentUITests { avatar_static = "some_avatar_url", isActive = true, accessToken = "token", - refreshToken = refreshToken, - clientId = clientId, - clientSecret = clientSecret + refreshToken = "refreshToken", + clientId = "clientId", + clientSecret = "clientSecret" ) ) db.close() @@ -114,7 +114,7 @@ class PostFragmentUITests { @Test fun newPostUiTest() { ActivityScenario.launch(MainActivity::class.java).onActivity { - a -> a.tabs.getTabAt(2)!!.select() + it.findViewById(R.id.tabs).getTabAt(2)!!.select() } Thread.sleep(1500) onView(withId(R.id.photo_view_button)).check(matches(isDisplayed())) diff --git a/app/src/androidTest/java/com/h/pixeldroid/PostTest.kt b/app/src/androidTest/java/com/h/pixeldroid/PostTest.kt index 1086efc5..0daab678 100644 --- a/app/src/androidTest/java/com/h/pixeldroid/PostTest.kt +++ b/app/src/androidTest/java/com/h/pixeldroid/PostTest.kt @@ -63,9 +63,9 @@ class PostTest { avatar_static = "some_avatar_url", isActive = true, accessToken = "token", - refreshToken = refreshToken, - clientId = clientId, - clientSecret = clientSecret + refreshToken = "refreshToken", + clientId = "clientId", + clientSecret = "clientSecret" ) ) db.close() @@ -76,14 +76,15 @@ class PostTest { fun saveToGalleryTestSimplePost() { val attachment = Attachment( id = "12", - url = "https://wiki.gnugen.ch/lib/tpl/gnugen/images/logo_web.png" + url = "https://wiki.gnugen.ch/lib/tpl/gnugen/images/logo_web.png", + meta = null ) val post = Status( id = "12", account = Account( id = "12", username = "douze", - url = "https://pixelfed.de/douze" + url = "https://pixelfed.de/douze", ), media_attachments = listOf(attachment) ) @@ -106,11 +107,13 @@ class PostTest { fun saveToGalleryTestAlbum() { val attachment1 = Attachment( id = "12", - url = "https://wiki.gnugen.ch/lib/tpl/gnugen/images/logo_web.png" + url = "https://wiki.gnugen.ch/lib/tpl/gnugen/images/logo_web.png", + meta = null ) val attachment2 = Attachment( id = "13", - url = "https://wiki.gnugen.ch/lib/tpl/gnugen/images/logo_web.png" + url = "https://wiki.gnugen.ch/lib/tpl/gnugen/images/logo_web.png", + meta = null ) val post = Status( id = "12", @@ -141,14 +144,15 @@ class PostTest { val expectedIntent: Matcher = IntentMatchers.hasAction(Intent.ACTION_CHOOSER) val attachment = Attachment( id = "12", - url = "https://wiki.gnugen.ch/lib/tpl/gnugen/images/logo_web.png" + url = "https://wiki.gnugen.ch/lib/tpl/gnugen/images/logo_web.png", + meta = null ) val post = Status( id = "12", account = Account( id = "12", username = "douze", - url = "https://pixelfed.de/douze" + url = "https://pixelfed.de/douze", ), media_attachments = listOf(attachment) ) @@ -166,11 +170,13 @@ class PostTest { val expectedIntent: Matcher = IntentMatchers.hasAction(Intent.ACTION_CHOOSER) val attachment1 = Attachment( id = "12", - url = "https://wiki.gnugen.ch/lib/tpl/gnugen/images/logo_web.png" + url = "https://wiki.gnugen.ch/lib/tpl/gnugen/images/logo_web.png", + meta = null ) val attachment2 = Attachment( id = "13", - url = "https://wiki.gnugen.ch/lib/tpl/gnugen/images/logo_web.png" + url = "https://wiki.gnugen.ch/lib/tpl/gnugen/images/logo_web.png", + meta = null ) val post = Status( id = "12", @@ -208,7 +214,7 @@ class PostTest { media_attachments= listOf( Attachment(id="15888", type= Attachment.AttachmentType.image, url="https://pixelfed.de/storage/m/113a3e2124a33b1f5511e531953f5ee48456e0c7/34dd6d9fb1762dac8c7ddeeaf789d2d8fa083c9f/JtjO0eAbELpgO1UZqF5ydrKbCKRVyJUM1WAaqIeB.jpeg", preview_url="https://pixelfed.de/storage/m/113a3e2124a33b1f5511e531953f5ee48456e0c7/34dd6d9fb1762dac8c7ddeeaf789d2d8fa083c9f/JtjO0eAbELpgO1UZqF5ydrKbCKRVyJUM1WAaqIeB_thumb.jpeg", - remote_url=null, text_url=null, description=null, blurhash=null) + remote_url=null, text_url=null, description=null, blurhash=null, meta = null) ), application= Application(name="web", website=null, vapid_key=null), mentions=emptyList(), tags= listOf(Tag(name="hiking", url="https://pixelfed.de/discover/tags/hiking", history=null), Tag(name="nature", url="https://pixelfed.de/discover/tags/nature", history=null), Tag(name="rotavicentina", url="https://pixelfed.de/discover/tags/rotavicentina", history=null)), @@ -235,7 +241,7 @@ class PostTest { media_attachments= listOf( Attachment(id="15888", type= Attachment.AttachmentType.image, url="https://pixelfed.de/storage/m/113a3e2124a33b1f5511e531953f5ee48456e0c7/34dd6d9fb1762dac8c7ddeeaf789d2d8fa083c9f/JtjO0eAbELpgO1UZqF5ydrKbCKRVyJUM1WAaqIeB.jpeg", preview_url="https://pixelfed.de/storage/m/113a3e2124a33b1f5511e531953f5ee48456e0c7/34dd6d9fb1762dac8c7ddeeaf789d2d8fa083c9f/JtjO0eAbELpgO1UZqF5ydrKbCKRVyJUM1WAaqIeB_thumb.jpeg", - remote_url=null, text_url=null, description=null, blurhash=null) + remote_url=null, text_url=null, description=null, blurhash=null, meta = null) ), application= Application(name="web", website=null, vapid_key=null), mentions=emptyList(), tags= listOf(Tag(name="hiking", url="https://pixelfed.de/discover/tags/hiking", history=null), Tag(name="nature", url="https://pixelfed.de/discover/tags/nature", history=null), Tag(name="rotavicentina", url="https://pixelfed.de/discover/tags/rotavicentina", history=null)), diff --git a/app/src/main/java/com/h/pixeldroid/postCreation/photoEdit/PhotoEditActivity.kt b/app/src/main/java/com/h/pixeldroid/postCreation/photoEdit/PhotoEditActivity.kt index c42c9971..e6e276f3 100644 --- a/app/src/main/java/com/h/pixeldroid/postCreation/photoEdit/PhotoEditActivity.kt +++ b/app/src/main/java/com/h/pixeldroid/postCreation/photoEdit/PhotoEditActivity.kt @@ -49,7 +49,7 @@ private val REQUIRED_PERMISSIONS = arrayOf( class PhotoEditActivity : BaseActivity() { - private var saving: Boolean = false + var saving: Boolean = false private val BITMAP_CONFIG = Bitmap.Config.ARGB_8888 private val BRIGHTNESS_START = 0 private val SATURATION_START = 1.0f