social-aggregator/app/src/androidTest/java/pl/edu/amu/wmi/socialaggregator/AddSocialActivityTest.kt

82 lines
2.7 KiB
Kotlin

package pl.edu.amu.wmi.socialaggregator
import androidx.recyclerview.widget.RecyclerView
import androidx.test.core.app.launchActivity
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4
import junit.framework.Assert.assertEquals
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import pl.edu.amu.wmi.socialaggregator.TestUtils.actionOnChild
import pl.edu.amu.wmi.socialaggregator.TestUtils.cleanLocalStorage
import pl.edu.amu.wmi.socialaggregator.activity.AddSocialActivity
@RunWith(AndroidJUnit4::class)
class AddSocialActivityTest {
@Rule
@JvmField
val activity = IntentsTestRule(AddSocialActivity::class.java)
@Test
fun initialState_noAddedSocials_oneAvailableSocial() {
cleanLocalStorage(activity)
val newActivity = launchActivity<AddSocialActivity>()
assertEquals(
0, activity.activity.findViewById<RecyclerView>(R.id.availableSocialsRecyclerView)
.adapter?.itemCount
)
assertEquals(
1, activity.activity.findViewById<RecyclerView>(R.id.addSocialRecyclerView)
.adapter?.itemCount
)
}
@Test
fun clickingSocials_movesThemFormAvailableToAdded_etViceVersa() {
cleanLocalStorage(activity)
onView(withId(R.id.addSocialRecyclerView))
.perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(
0,
actionOnChild(click(), R.id.socialPlatformImage)
)
)
assertEquals(
1, activity.activity.findViewById<RecyclerView>(R.id.availableSocialsRecyclerView)
.adapter?.itemCount
)
assertEquals(
0, activity.activity.findViewById<RecyclerView>(R.id.addSocialRecyclerView)
.adapter?.itemCount
)
onView(withId(R.id.availableSocialsRecyclerView))
.perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(
0,
actionOnChild(click(), R.id.socialPlatformImage)
)
)
assertEquals(
0, activity.activity.findViewById<RecyclerView>(R.id.availableSocialsRecyclerView)
.adapter?.itemCount
)
assertEquals(
1, activity.activity.findViewById<RecyclerView>(R.id.addSocialRecyclerView)
.adapter?.itemCount
)
}
}