Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TECH: add recycler test #470

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.kaspersky.kaspressample.recycler

import com.kaspersky.kaspressample.R
import com.kaspersky.kaspresso.screens.KScreen
import io.github.kakaocup.kakao.recycler.KRecyclerView

object RecyclerScreen : KScreen<RecyclerScreen>() {
override val layoutId: Int = R.layout.fragment_recycler
override val viewClass: Class<*> = RecyclerFragment::class.java

val recycler = KRecyclerView(builder = { withId(R.id.recycler) }, {})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.kaspersky.kaspressample.recycler

import androidx.fragment.app.testing.launchFragmentInContainer
import com.kaspersky.kaspressample.R
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
import org.junit.Test

class RecyclerTest : TestCase() {
@Test
fun test() = before {
launchFragmentInContainer<RecyclerFragment>(themeResId = R.style.AppTheme)
}.after {
}.run {
RecyclerScreen {
recycler {
scrollTo(15)
scrollToEnd()
scrollToStart()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.kaspersky.kaspressample.recycler

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.kaspersky.kaspressample.R

class RecyclerAdapter : RecyclerView.Adapter<RecyclerAdapter.RecyclerViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_recycler, parent, false)
return RecyclerViewHolder(view)
}

override fun getItemCount() = ITEMS_COUNT

override fun onBindViewHolder(holder: RecyclerViewHolder, position: Int) = holder.bind(position)

class RecyclerViewHolder(view: View) : RecyclerView.ViewHolder(view) {
private val textView: TextView by lazy { view.findViewById(R.id.textView) }

fun bind(position: Int) {
textView.text = position.toString()
}
}

companion object {
private const val ITEMS_COUNT = 30
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.kaspersky.kaspressample.recycler

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.kaspersky.kaspressample.R

class RecyclerFragment : Fragment(R.layout.fragment_recycler) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.findViewById<RecyclerView>(R.id.recycler).run {
layoutManager = LinearLayoutManager(view.context)
adapter = RecyclerAdapter()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/item_recycler" />
</FrameLayout>
16 changes: 16 additions & 0 deletions samples/kaspresso-sample/src/main/res/layout/item_recycler.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="20sp"
android:gravity="center"
tools:text="123" />
</FrameLayout>