At least make integration tests compile

This commit is contained in:
Matthieu 2021-02-11 01:24:05 +01:00
parent 1268f5c977
commit fe08782803
10 changed files with 55 additions and 54 deletions

View File

@ -4,6 +4,7 @@ import android.Manifest
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.Intent.ACTION_CHOOSER import android.content.Intent.ACTION_CHOOSER
import android.widget.ImageButton
import androidx.fragment.app.testing.launchFragmentInContainer import androidx.fragment.app.testing.launchFragmentInContainer
import androidx.test.core.app.ApplicationProvider import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.intent.Intents 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.postCreation.camera.CameraFragment
import com.h.pixeldroid.testUtility.clearData import com.h.pixeldroid.testUtility.clearData
import com.h.pixeldroid.testUtility.initDB import com.h.pixeldroid.testUtility.initDB
import kotlinx.android.synthetic.main.camera_ui_container.*
import org.hamcrest.CoreMatchers import org.hamcrest.CoreMatchers
import org.hamcrest.Matcher import org.hamcrest.Matcher
import org.junit.After import org.junit.After
@ -50,9 +50,9 @@ class CameraTest {
avatar_static = "some_avatar_url", avatar_static = "some_avatar_url",
isActive = true, isActive = true,
accessToken = "token", accessToken = "token",
refreshToken = refreshToken, refreshToken = "refreshToken",
clientId = clientId, clientId = "clientId",
clientSecret = clientSecret clientSecret = "clientSecret"
) )
) )
db.close() db.close()
@ -88,7 +88,7 @@ class CameraTest {
val scenario = launchFragmentInContainer<CameraFragment>() val scenario = launchFragmentInContainer<CameraFragment>()
scenario.onFragment { fragment -> scenario.onFragment { fragment ->
fragment.photo_view_button.performClick() fragment.view?.findViewById<ImageButton>(R.id.photo_view_button)?.performClick()
} }
Thread.sleep(1000) Thread.sleep(1000)
@ -102,7 +102,7 @@ class CameraTest {
fun switchButton() { fun switchButton() {
val scenario = launchFragmentInContainer<CameraFragment>() val scenario = launchFragmentInContainer<CameraFragment>()
scenario.onFragment { fragment -> scenario.onFragment { fragment ->
fragment.camera_switch_button.performClick() fragment.view?.findViewById<ImageButton>(R.id.camera_switch_button)?.performClick()
} }
Thread.sleep(1000) Thread.sleep(1000)
scenario.onFragment { fragment -> scenario.onFragment { fragment ->

View File

@ -61,9 +61,9 @@ class DrawerMenuTest {
avatar_static = "some_avatar_url", avatar_static = "some_avatar_url",
isActive = true, isActive = true,
accessToken = "token", accessToken = "token",
refreshToken = refreshToken, refreshToken = "refreshToken",
clientId = clientId, clientId = "clientId",
clientSecret = clientSecret clientSecret = "clientSecret"
) )
) )
db.close() db.close()
@ -132,8 +132,7 @@ class DrawerMenuTest {
onView(withText(R.string.menu_account)).perform(click()) onView(withText(R.string.menu_account)).perform(click())
// Check that profile activity was opened. // Check that profile activity was opened.
onView(withId(R.id.editButton)).check(matches(isDisplayed())) onView(withId(R.id.editButton)).check(matches(isDisplayed()))
val followersText = context.getString(R.string.nb_followers) val followersText = context.resources.getQuantityString(R.plurals.nb_followers, 68)
.format(68)
onView(withText(followersText)).perform(click()) onView(withText(followersText)).perform(click())
onView(withText("Dobios")).check(matches(isDisplayed())) onView(withText("Dobios")).check(matches(isDisplayed()))
} }
@ -144,8 +143,7 @@ class DrawerMenuTest {
onView(withText(R.string.menu_account)).perform(click()) onView(withText(R.string.menu_account)).perform(click())
// Check that profile activity was opened. // Check that profile activity was opened.
onView(withId(R.id.editButton)).check(matches(isDisplayed())) onView(withId(R.id.editButton)).check(matches(isDisplayed()))
val followingText = context.getString(R.string.nb_following) val followingText = context.resources.getQuantityString(R.plurals.nb_followers, 27)
.format(27)
onView(withText(followingText)).perform(click()) onView(withText(followingText)).perform(click())
onView(withText("Dobios")).check(matches(isDisplayed())) onView(withText("Dobios")).check(matches(isDisplayed()))
} }

View File

@ -22,14 +22,14 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule import androidx.test.rule.GrantPermissionRule
import com.google.android.material.tabs.TabLayout 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.settings.AboutActivity
import com.h.pixeldroid.testUtility.CustomMatchers import com.h.pixeldroid.testUtility.CustomMatchers
import com.h.pixeldroid.testUtility.clearData 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.hamcrest.CoreMatchers.allOf
import org.junit.* import org.junit.*
import org.junit.Assert.assertTrue
import org.junit.rules.Timeout import org.junit.rules.Timeout
import org.junit.runner.RunWith import org.junit.runner.RunWith
import java.io.File 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_contrast)).perform(setProgress(change))
Espresso.onView(withId(R.id.seekbar_saturation)).perform(setProgress(change)) Espresso.onView(withId(R.id.seekbar_saturation)).perform(setProgress(change))
Assert.assertEquals(change, activity.seekbar_brightness.progress) Assert.assertEquals(change, activity.findViewById<SeekBar>(R.id.seekbar_brightness).progress)
Assert.assertEquals(change, activity.seekbar_contrast.progress) Assert.assertEquals(change, activity.findViewById<SeekBar>(R.id.seekbar_contrast).progress)
Assert.assertEquals(change, activity.seekbar_saturation.progress) Assert.assertEquals(change, activity.findViewById<SeekBar>(R.id.seekbar_saturation).progress)
Thread.sleep(1000) 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_contrast)).perform(setProgress(change))
Espresso.onView(withId(R.id.seekbar_saturation)).perform(setProgress(change)) Espresso.onView(withId(R.id.seekbar_saturation)).perform(setProgress(change))
Assert.assertEquals(change, activity.seekbar_brightness.progress) Assert.assertEquals(change, activity.findViewById<SeekBar>(R.id.seekbar_brightness).progress)
Assert.assertEquals(change, activity.seekbar_contrast.progress) Assert.assertEquals(change, activity.findViewById<SeekBar>(R.id.seekbar_contrast).progress)
Assert.assertEquals(change, activity.seekbar_saturation.progress) Assert.assertEquals(change, activity.findViewById<SeekBar>(R.id.seekbar_saturation).progress)
} }
@Test @Test
@ -181,7 +181,7 @@ class EditPhotoTest {
@Test @Test
fun alreadyUploadingDialog() { fun alreadyUploadingDialog() {
activityScenario.onActivity { a -> a.saving = true } 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) Thread.sleep(1000)
Espresso.onView(withText(R.string.busy_dialog_text)).check(matches(isDisplayed())) Espresso.onView(withText(R.string.busy_dialog_text)).check(matches(isDisplayed()))
} }

View File

@ -68,9 +68,9 @@ class HomeFeedTest {
avatar_static = "some_avatar_url", avatar_static = "some_avatar_url",
isActive = true, isActive = true,
accessToken = "token", accessToken = "token",
refreshToken = refreshToken, refreshToken = "refreshToken",
clientId = clientId, clientId = "clientId",
clientSecret = clientSecret clientSecret = "clientSecret"
) )
) )
db.close() db.close()

View File

@ -85,9 +85,9 @@ class IntentTest {
avatar_static = "some_avatar_url", avatar_static = "some_avatar_url",
isActive = true, isActive = true,
accessToken = "token", accessToken = "token",
refreshToken = refreshToken, refreshToken = "refreshToken",
clientId = clientId, clientId = "clientId",
clientSecret = clientSecret clientSecret = "clientSecret"
) )
) )
db.close() db.close()

View File

@ -124,9 +124,9 @@ class LoginActivityOnlineTest {
avatar_static = "some_avatar_url", avatar_static = "some_avatar_url",
isActive = true, isActive = true,
accessToken = "token", accessToken = "token",
refreshToken = refreshToken, refreshToken = "refreshToken",
clientId = clientId, clientId = "clientId",
clientSecret = clientSecret clientSecret = "clientSecret"
) )
) )
db.close() db.close()

View File

@ -1,6 +1,5 @@
package com.h.pixeldroid package com.h.pixeldroid
import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.Intent.ACTION_VIEW import android.content.Intent.ACTION_VIEW
import androidx.test.core.app.ActivityScenario import androidx.test.core.app.ActivityScenario
@ -28,8 +27,6 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
class LoginCheckIntent { class LoginCheckIntent {
private lateinit var context: Context
@get:Rule @get:Rule
var globalTimeout: Timeout = Timeout.seconds(100) var globalTimeout: Timeout = Timeout.seconds(100)

View File

@ -16,13 +16,13 @@ import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule 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.AppDatabase
import com.h.pixeldroid.utils.db.entities.InstanceDatabaseEntity import com.h.pixeldroid.utils.db.entities.InstanceDatabaseEntity
import com.h.pixeldroid.utils.db.entities.UserDatabaseEntity import com.h.pixeldroid.utils.db.entities.UserDatabaseEntity
import com.h.pixeldroid.testUtility.MockServer import com.h.pixeldroid.testUtility.MockServer
import com.h.pixeldroid.testUtility.clearData import com.h.pixeldroid.testUtility.clearData
import com.h.pixeldroid.testUtility.initDB import com.h.pixeldroid.testUtility.initDB
import kotlinx.android.synthetic.main.activity_main.*
import org.hamcrest.Matcher import org.hamcrest.Matcher
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
@ -96,9 +96,9 @@ class PostFragmentUITests {
avatar_static = "some_avatar_url", avatar_static = "some_avatar_url",
isActive = true, isActive = true,
accessToken = "token", accessToken = "token",
refreshToken = refreshToken, refreshToken = "refreshToken",
clientId = clientId, clientId = "clientId",
clientSecret = clientSecret clientSecret = "clientSecret"
) )
) )
db.close() db.close()
@ -114,7 +114,7 @@ class PostFragmentUITests {
@Test @Test
fun newPostUiTest() { fun newPostUiTest() {
ActivityScenario.launch(MainActivity::class.java).onActivity { ActivityScenario.launch(MainActivity::class.java).onActivity {
a -> a.tabs.getTabAt(2)!!.select() it.findViewById<TabLayout>(R.id.tabs).getTabAt(2)!!.select()
} }
Thread.sleep(1500) Thread.sleep(1500)
onView(withId(R.id.photo_view_button)).check(matches(isDisplayed())) onView(withId(R.id.photo_view_button)).check(matches(isDisplayed()))

View File

@ -63,9 +63,9 @@ class PostTest {
avatar_static = "some_avatar_url", avatar_static = "some_avatar_url",
isActive = true, isActive = true,
accessToken = "token", accessToken = "token",
refreshToken = refreshToken, refreshToken = "refreshToken",
clientId = clientId, clientId = "clientId",
clientSecret = clientSecret clientSecret = "clientSecret"
) )
) )
db.close() db.close()
@ -76,14 +76,15 @@ class PostTest {
fun saveToGalleryTestSimplePost() { fun saveToGalleryTestSimplePost() {
val attachment = Attachment( val attachment = Attachment(
id = "12", 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( val post = Status(
id = "12", id = "12",
account = Account( account = Account(
id = "12", id = "12",
username = "douze", username = "douze",
url = "https://pixelfed.de/douze" url = "https://pixelfed.de/douze",
), ),
media_attachments = listOf(attachment) media_attachments = listOf(attachment)
) )
@ -106,11 +107,13 @@ class PostTest {
fun saveToGalleryTestAlbum() { fun saveToGalleryTestAlbum() {
val attachment1 = Attachment( val attachment1 = Attachment(
id = "12", 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( val attachment2 = Attachment(
id = "13", 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( val post = Status(
id = "12", id = "12",
@ -141,14 +144,15 @@ class PostTest {
val expectedIntent: Matcher<Intent> = IntentMatchers.hasAction(Intent.ACTION_CHOOSER) val expectedIntent: Matcher<Intent> = IntentMatchers.hasAction(Intent.ACTION_CHOOSER)
val attachment = Attachment( val attachment = Attachment(
id = "12", 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( val post = Status(
id = "12", id = "12",
account = Account( account = Account(
id = "12", id = "12",
username = "douze", username = "douze",
url = "https://pixelfed.de/douze" url = "https://pixelfed.de/douze",
), ),
media_attachments = listOf(attachment) media_attachments = listOf(attachment)
) )
@ -166,11 +170,13 @@ class PostTest {
val expectedIntent: Matcher<Intent> = IntentMatchers.hasAction(Intent.ACTION_CHOOSER) val expectedIntent: Matcher<Intent> = IntentMatchers.hasAction(Intent.ACTION_CHOOSER)
val attachment1 = Attachment( val attachment1 = Attachment(
id = "12", 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( val attachment2 = Attachment(
id = "13", 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( val post = Status(
id = "12", id = "12",
@ -208,7 +214,7 @@ class PostTest {
media_attachments= listOf( media_attachments= listOf(
Attachment(id="15888", type= Attachment.AttachmentType.image, url="https://pixelfed.de/storage/m/113a3e2124a33b1f5511e531953f5ee48456e0c7/34dd6d9fb1762dac8c7ddeeaf789d2d8fa083c9f/JtjO0eAbELpgO1UZqF5ydrKbCKRVyJUM1WAaqIeB.jpeg", 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", 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(), 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)), 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( media_attachments= listOf(
Attachment(id="15888", type= Attachment.AttachmentType.image, url="https://pixelfed.de/storage/m/113a3e2124a33b1f5511e531953f5ee48456e0c7/34dd6d9fb1762dac8c7ddeeaf789d2d8fa083c9f/JtjO0eAbELpgO1UZqF5ydrKbCKRVyJUM1WAaqIeB.jpeg", 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", 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(), 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)), 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)),

View File

@ -49,7 +49,7 @@ private val REQUIRED_PERMISSIONS = arrayOf(
class PhotoEditActivity : BaseActivity() { class PhotoEditActivity : BaseActivity() {
private var saving: Boolean = false var saving: Boolean = false
private val BITMAP_CONFIG = Bitmap.Config.ARGB_8888 private val BITMAP_CONFIG = Bitmap.Config.ARGB_8888
private val BRIGHTNESS_START = 0 private val BRIGHTNESS_START = 0
private val SATURATION_START = 1.0f private val SATURATION_START = 1.0f