Update tests
This commit is contained in:
parent
e8941dccb3
commit
dc402819d4
|
@ -11,6 +11,7 @@ import androidx.test.espresso.assertion.ViewAssertions.matches
|
|||
import androidx.test.espresso.matcher.ViewMatchers.*
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import org.hamcrest.CoreMatchers.anyOf
|
||||
import org.pixeldroid.app.testUtility.*
|
||||
import org.pixeldroid.app.utils.db.AppDatabase
|
||||
import org.junit.After
|
||||
|
@ -81,7 +82,11 @@ class MockedServerTest {
|
|||
|
||||
waitForView(R.id.username)
|
||||
|
||||
onView(withId(R.id.username)).check(matches(withSubstring("User ")))
|
||||
onView(withId(R.id.username)).check(matches(anyOf(
|
||||
withSubstring("User "),
|
||||
withSubstring("PixelDroid Developer"),
|
||||
withSubstring("Testi Testo")
|
||||
)))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,35 +1,117 @@
|
|||
package org.pixeldroid.app
|
||||
|
||||
import android.content.Context
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.*
|
||||
import androidx.work.ListenableWorker
|
||||
import androidx.work.testing.TestListenableWorkerBuilder
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.hamcrest.CoreMatchers
|
||||
import org.hamcrest.MatcherAssert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.JUnit4
|
||||
import org.pixeldroid.app.settings.AboutActivity
|
||||
import org.pixeldroid.app.testUtility.*
|
||||
import org.pixeldroid.app.utils.api.objects.Account
|
||||
import org.pixeldroid.app.utils.api.objects.Notification
|
||||
import org.pixeldroid.app.utils.db.AppDatabase
|
||||
import org.pixeldroid.app.utils.notificationsWorker.NotificationsWorker
|
||||
import java.time.Instant
|
||||
|
||||
//TODO actual test here
|
||||
@RunWith(JUnit4::class)
|
||||
class NotificationWorkerTest {
|
||||
private lateinit var context: Context
|
||||
private lateinit var activityScenario: ActivityScenario<AboutActivity>
|
||||
private val uiDevice by lazy { UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) }
|
||||
|
||||
private lateinit var db: AppDatabase
|
||||
|
||||
private val secondToLatestNotification: Notification =
|
||||
Notification(
|
||||
id = "1",
|
||||
type = Notification.NotificationType.follow,
|
||||
created_at = Instant.parse("2021-09-19T19:23:30Z"),
|
||||
account = Account(
|
||||
id = "344399325768278017",
|
||||
username = "pixeldroid",
|
||||
acct = "pixeldroid",
|
||||
url = "https://testing.pixeldroid.org/pixeldroid",
|
||||
display_name = "PixelDroid",
|
||||
note = "",
|
||||
avatar = "https://testing.pixeldroid.org/storage/avatars/default.jpg?v=0",
|
||||
avatar_static = null,
|
||||
header = null,
|
||||
header_static = null,
|
||||
locked = false,
|
||||
emojis = null,
|
||||
discoverable = null,
|
||||
created_at = Instant.parse("1970-01-01T00:00:00Z"),
|
||||
statuses_count = 0,
|
||||
followers_count = 0,
|
||||
following_count = 1,
|
||||
moved = null,
|
||||
fields = null,
|
||||
bot = null,
|
||||
source = null
|
||||
),
|
||||
status = null,
|
||||
user_id = "344399082242686977",
|
||||
instance_uri = "https://testing.pixeldroid.org"
|
||||
)
|
||||
@Before
|
||||
fun setup() {
|
||||
context = ApplicationProvider.getApplicationContext()
|
||||
|
||||
db = initDB(context)
|
||||
db.clearAllTables()
|
||||
db.instanceDao().insertInstance(
|
||||
testiTestoInstance
|
||||
)
|
||||
|
||||
db.userDao().insertUser(
|
||||
testiTesto
|
||||
)
|
||||
|
||||
runBlocking {
|
||||
db.notificationDao().insertAll(listOf(secondToLatestNotification))
|
||||
}
|
||||
|
||||
db.close()
|
||||
|
||||
activityScenario = ActivityScenario.launch(AboutActivity::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNotificationWorker() {
|
||||
// Get the ListenableWorker
|
||||
while (true) {
|
||||
val worker =
|
||||
TestListenableWorkerBuilder<NotificationsWorker>(context).build() // Run the worker synchronously
|
||||
val result = worker.startWork().get()
|
||||
MatcherAssert.assertThat(result, CoreMatchers.`is`(ListenableWorker.Result.success()))
|
||||
}
|
||||
val expectedAppName = context.getString(R.string.app_name)
|
||||
val expectedText = "user1 followed you"
|
||||
|
||||
// Run the worker synchronously
|
||||
val worker = TestListenableWorkerBuilder<NotificationsWorker>(context).build()
|
||||
val result = worker.startWork().get()
|
||||
|
||||
// Check worker returns success (which doesn't mean much, but is a good start)
|
||||
MatcherAssert.assertThat(result, CoreMatchers.`is`(ListenableWorker.Result.success()))
|
||||
|
||||
//Open notification shade
|
||||
uiDevice.openNotification()
|
||||
uiDevice.wait(Until.hasObject(By.textStartsWith(expectedAppName)), 5000)
|
||||
|
||||
val text: UiObject2 = uiDevice.findObject(By.textStartsWith(expectedText))
|
||||
text.click()
|
||||
|
||||
uiDevice.wait(Until.hasObject(By.textStartsWith(expectedText)), 5000)
|
||||
waitForView(R.id.notification_type)
|
||||
onView(first(withId(R.id.notification_type)))
|
||||
.check(matches(withText(expectedText)))
|
||||
|
||||
}
|
||||
}
|
|
@ -29,6 +29,7 @@ import org.junit.runner.RunWith
|
|||
import java.text.SimpleDateFormat
|
||||
import java.time.Instant
|
||||
import java.time.OffsetDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
|
@ -42,7 +43,7 @@ class PostTest {
|
|||
|
||||
@Before
|
||||
fun before(){
|
||||
context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
context = getInstrumentation().targetContext
|
||||
db = initDB(context)
|
||||
db.clearAllTables()
|
||||
db.instanceDao().insertInstance(
|
||||
|
@ -187,7 +188,7 @@ class PostTest {
|
|||
@Test
|
||||
fun getNLikesReturnsCorrectFormat() {
|
||||
val status = Status(id="140364967936397312", uri="https://pixelfed.de/p/Miike/140364967936397312",
|
||||
created_at= Instant.parse("2020-03-03T08:00:16+00:00"),
|
||||
created_at= OffsetDateTime.parse("2020-03-03T08:00:16+00:00").toInstant(),
|
||||
account= Account(id="115114166443970560", username="Miike", acct="Miike",
|
||||
url="https://pixelfed.de/Miike", display_name="Miike Duart", note="",
|
||||
avatar="https://pixelfed.de/storage/avatars/011/511/416/644/397/056/0/ZhaopLJWTWJ3hsVCS5pS_avatar.png?v=d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35",
|
||||
|
@ -214,7 +215,7 @@ class PostTest {
|
|||
@Test
|
||||
fun getNSharesReturnsCorrectFormat() {
|
||||
val status = Status(id="140364967936397312", uri="https://pixelfed.de/p/Miike/140364967936397312",
|
||||
created_at= Instant.parse("2020-03-03T08:00:16+00:00"),
|
||||
created_at= Instant.parse("2020-03-03T08:00:16.00Z"),
|
||||
account= Account(id="115114166443970560", username="Miike", acct="Miike",
|
||||
url="https://pixelfed.de/Miike", display_name="Miike Duart", note="",
|
||||
avatar="https://pixelfed.de/storage/avatars/011/511/416/644/397/056/0/ZhaopLJWTWJ3hsVCS5pS_avatar.png?v=d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35",
|
||||
|
|
|
@ -38,7 +38,7 @@ class ProfileTest {
|
|||
db.close()
|
||||
|
||||
val intent = Intent(context, ProfileActivity::class.java)
|
||||
val account = Account(id = "265472486651596800", username = "pixeldroid", acct = "pixeldroid", url = "https://testing2.pixeldroid.org/pixeldroid", display_name = "PixelDroid Developer", avatar = "https://testing2.pixeldroid.org/storage/avatars/default.jpg?v=0", avatar_static = "https://testing2.pixeldroid.org/storage/avatars/default.jpg?v=0", locked = false, emojis = arrayListOf(), discoverable = null, created_at = Instant.parse("2021-02-11T13:32:53.000000Z"), statuses_count = 1, followers_count = 1, following_count = 1, moved = null, fields = null, bot = false, source = null)
|
||||
val account = Account(id="344399325768278017", username="pixeldroid", acct="pixeldroid", url="https://testing.pixeldroid.org/pixeldroid", display_name="PixelDroid Developer", note="", avatar="https://testing.pixeldroid.org/storage/avatars/default.jpg?v=0", avatar_static="https://testing.pixeldroid.org/storage/avatars/default.jpg?v=0", header="", header_static="", locked=false, emojis= emptyList(), discoverable=null, created_at=Instant.parse("2021-09-17T08:39:57Z"), statuses_count=0, followers_count=1, following_count=1, moved=null, fields=null, bot=false, source=null)
|
||||
intent.putExtra(Account.ACCOUNT_TAG, account)
|
||||
activityScenario = ActivityScenario.launch(intent)
|
||||
onView(withId(R.id.profileRefreshLayout)).perform(swipeDown())
|
||||
|
@ -87,7 +87,7 @@ class ProfileTest {
|
|||
waitForView(R.id.account_entry_username)
|
||||
|
||||
// Open follower's profile
|
||||
onView(ViewMatchers.withText("testi testo")).perform((ViewActions.click()))
|
||||
onView(ViewMatchers.withText("Testi Testo")).perform((ViewActions.click()))
|
||||
|
||||
waitForView(R.id.editButton)
|
||||
|
||||
|
|
Loading…
Reference in New Issue