feat(chat): 채팅 탭 기본 layout을 추가한다
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
package kr.co.vividnext.sodalive.v2.main.chat
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.v2.widget.CapsuleTabBarView
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertSame
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], application = Application::class)
|
||||
class ChatMainFragmentLayoutTest {
|
||||
|
||||
@Test
|
||||
fun `기본 title bar는 title과 가변 action container를 함께 제공한다`() {
|
||||
val titleBar = inflateView(R.layout.view_title_bar_default) as LinearLayout
|
||||
val title = requireNotNull(titleBar.findViewById<TextView>(R.id.tv_title_bar_title))
|
||||
val actions = requireNotNull(titleBar.findViewById<LinearLayout>(R.id.ll_title_bar_actions))
|
||||
val menu = requireNotNull(titleBar.findViewById<ImageView>(R.id.iv_title_bar_menu))
|
||||
|
||||
assertSame(actions, menu.parent)
|
||||
assertSame(titleBar, title.parent)
|
||||
assertSame(titleBar, actions.parent)
|
||||
assertTrue(titleBar.indexOfChild(title) < titleBar.indexOfChild(actions))
|
||||
assertEquals(LinearLayout.HORIZONTAL, actions.orientation)
|
||||
assertEquals(ViewGroup.LayoutParams.WRAP_CONTENT, actions.layoutParams.width)
|
||||
assertEquals(ViewGroup.LayoutParams.WRAP_CONTENT, actions.layoutParams.height)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `채팅 fragment layout은 title bar tab list floating button만 포함한다`() {
|
||||
val root = inflateView(R.layout.fragment_v2_main_chat) as ConstraintLayout
|
||||
val titleBar = requireNotNull(root.findViewById<View>(R.id.view_chat_title_bar))
|
||||
val tabBar = requireNotNull(root.findViewById<CapsuleTabBarView>(R.id.view_chat_filter_tabs))
|
||||
val recyclerView = requireNotNull(root.findViewById<RecyclerView>(R.id.rv_chat_rooms))
|
||||
val floatingButton = requireNotNull(root.findViewById<ImageView>(R.id.btn_chat_floating))
|
||||
|
||||
assertEquals(Color.BLACK, (root.background as ColorDrawable).color)
|
||||
assertSame(root, titleBar.parent)
|
||||
assertSame(root, tabBar.parent)
|
||||
assertSame(root, recyclerView.parent)
|
||||
assertSame(root, floatingButton.parent)
|
||||
assertFalse(root.containsClassName("com.google.android.material.bottomnavigation.BottomNavigationView"))
|
||||
assertFalse(root.containsViewIdContaining("unread"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `채팅 fragment list와 floating button은 계획된 constraint를 사용한다`() {
|
||||
val root = inflateView(R.layout.fragment_v2_main_chat)
|
||||
val titleBar = requireNotNull(root.findViewById<View>(R.id.view_chat_title_bar))
|
||||
val tabBar = requireNotNull(root.findViewById<CapsuleTabBarView>(R.id.view_chat_filter_tabs))
|
||||
val recyclerView = requireNotNull(root.findViewById<RecyclerView>(R.id.rv_chat_rooms))
|
||||
val floatingButton = requireNotNull(root.findViewById<ImageView>(R.id.btn_chat_floating))
|
||||
val tabParams = tabBar.layoutParams as ConstraintLayout.LayoutParams
|
||||
val listParams = recyclerView.layoutParams as ConstraintLayout.LayoutParams
|
||||
val buttonParams = floatingButton.layoutParams as ConstraintLayout.LayoutParams
|
||||
|
||||
assertEquals(60.dpToPx(), titleBar.layoutParams.height)
|
||||
assertEquals(52.dpToPx(), tabBar.layoutParams.height)
|
||||
assertEquals(R.id.view_chat_title_bar, tabParams.topToBottom)
|
||||
assertEquals(R.id.view_chat_filter_tabs, listParams.topToBottom)
|
||||
assertEquals(ConstraintLayout.LayoutParams.PARENT_ID, listParams.bottomToBottom)
|
||||
assertEquals(false, recyclerView.clipToPadding)
|
||||
assertTrue(recyclerView.paddingBottom >= 28.dpToPx())
|
||||
assertEquals(ConstraintLayout.LayoutParams.PARENT_ID, buttonParams.endToEnd)
|
||||
assertEquals(ConstraintLayout.LayoutParams.PARENT_ID, buttonParams.bottomToBottom)
|
||||
}
|
||||
|
||||
private fun inflateView(layoutResId: Int): View {
|
||||
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
return LayoutInflater.from(context).inflate(layoutResId, null, false)
|
||||
}
|
||||
|
||||
private fun View.containsViewIdContaining(idNamePart: String): Boolean {
|
||||
if (id != View.NO_ID) {
|
||||
val idName = runCatching { resources.getResourceEntryName(id) }.getOrNull()
|
||||
if (idName != null && idName.contains(idNamePart, ignoreCase = true)) return true
|
||||
}
|
||||
if (this !is ViewGroup) return false
|
||||
return (0 until childCount).any { getChildAt(it).containsViewIdContaining(idNamePart) }
|
||||
}
|
||||
|
||||
private fun View.containsClassName(className: String): Boolean {
|
||||
if (javaClass.name == className) return true
|
||||
if (this !is ViewGroup) return false
|
||||
return (0 until childCount).any { getChildAt(it).containsClassName(className) }
|
||||
}
|
||||
|
||||
private fun Int.dpToPx(): Int {
|
||||
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
return (this * context.resources.displayMetrics.density).toInt()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user