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

Fix list view heights for delete lists #5597

Merged
merged 4 commits into from
May 19, 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
Expand Up @@ -7,7 +7,7 @@
<org.odk.collect.android.formlists.FormListRecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/buttons"
app:layout_constraintTop_toTopOf="parent" />

Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/file_manager_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ the License.
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/buttons"
app:layout_constraintTop_toTopOf="parent" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ import org.odk.collect.android.formlists.blankformlist.DeleteBlankFormFragment
import org.odk.collect.androidshared.ui.FragmentFactoryBuilder
import org.odk.collect.androidshared.ui.MultiSelectViewModel
import org.odk.collect.fragmentstest.FragmentScenarioLauncherRule
import org.odk.collect.testshared.RecyclerViewMatcher
import org.odk.collect.testshared.RecyclerViewMatcher.Companion.withRecyclerView
import org.odk.collect.testshared.ViewActions.clickOnItemWith
import org.odk.collect.testshared.ViewMatchers.recyclerView

@RunWith(AndroidJUnit4::class)
class DeleteBlankFormFragmentTest {
Expand Down Expand Up @@ -88,8 +90,8 @@ class DeleteBlankFormFragmentTest {

multiSelectViewModel.select(2)

onView(RecyclerViewMatcher.withRecyclerView(R.id.list).atPositionOnView(1, R.id.form_title)).check(matches(withText("Form 2")))
onView(RecyclerViewMatcher.withRecyclerView(R.id.list).atPositionOnView(1, R.id.checkbox)).check(matches(isChecked()))
onView(withRecyclerView(R.id.list).atPositionOnView(1, R.id.form_title)).check(matches(withText("Form 2")))
onView(withRecyclerView(R.id.list).atPositionOnView(1, R.id.checkbox)).check(matches(isChecked()))
}

@Test
Expand All @@ -101,8 +103,8 @@ class DeleteBlankFormFragmentTest {
blankFormListItem(databaseId = 3, formName = "Form 3")
)

onView(withText("Form 1")).perform(click())
onView(withText("Form 3")).perform(click())
onView(recyclerView()).perform(clickOnItemWith(withText("Form 1")))
onView(recyclerView()).perform(clickOnItemWith(withText("Form 3")))

assertThat(multiSelectViewModel.getSelected().value, equalTo(setOf<Long>(1, 3)))
}
Expand All @@ -115,10 +117,10 @@ class DeleteBlankFormFragmentTest {
blankFormListItem(databaseId = 2, formName = "Form 2")
)

onView(withText("Form 1")).perform(click())
onView(withText("Form 2")).perform(click())
onView(recyclerView()).perform(clickOnItemWith(withText("Form 1")))
onView(recyclerView()).perform(clickOnItemWith(withText("Form 2")))

onView(withText("Form 2")).perform(click())
onView(recyclerView()).perform(clickOnItemWith(withText("Form 2")))

assertThat(multiSelectViewModel.getSelected().value, equalTo(setOf<Long>(1)))
}
Expand Down
1 change: 1 addition & 0 deletions testshared/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies {
implementation Dependencies.robolectric
implementation Dependencies.junit
implementation Dependencies.androidx_test_espresso_intents
implementation Dependencies.androidx_test_espresso_contrib
implementation Dependencies.android_material
implementation Dependencies.danlew_android_joda
implementation(Dependencies.androidx_fragment_testing) {
Expand Down
10 changes: 10 additions & 0 deletions testshared/src/main/java/org/odk/collect/testshared/ViewActions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import android.view.View
import android.view.ViewGroup
import androidx.annotation.StringRes
import androidx.core.view.allViews
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import androidx.test.espresso.UiController
import androidx.test.espresso.ViewAction
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItem
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import org.hamcrest.Matcher

object ViewActions {

Expand All @@ -25,4 +30,9 @@ object ViewActions {
}
}
}

@JvmStatic
fun clickOnItemWith(matcher: Matcher<View>): ViewAction {
return actionOnItem<ViewHolder>(hasDescendant(matcher), click())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.odk.collect.testshared

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.matcher.ViewMatchers
import org.hamcrest.Matcher

object ViewMatchers {

@JvmStatic
fun recyclerView(): Matcher<View> {
return ViewMatchers.isAssignableFrom(RecyclerView::class.java)
}
}