Skip to content

Commit

Permalink
Remove TagsDialog code related to custom study by tags
Browse files Browse the repository at this point in the history
  • Loading branch information
lukstbit committed Feb 14, 2025
1 parent c047a7d commit a2540a4
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import com.ichi2.utils.positiveButton
import com.ichi2.utils.show
import com.ichi2.utils.title
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.apache.commons.io.FileUtils
import timber.log.Timber
Expand All @@ -65,11 +64,6 @@ class TagsDialog : AnalyticsDialogFragment {
* Filter notes by tags
*/
FILTER_BY_TAG,

/**
* A custom study session filtered by tags
*/
CUSTOM_STUDY_TAGS,
}

private var type: DialogType? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,17 @@
*/
package com.ichi2.anki.dialogs.tags

import android.content.DialogInterface
import android.os.Bundle
import android.view.View
import android.widget.EditText
import android.widget.RadioGroup
import androidx.appcompat.app.AlertDialog
import androidx.core.os.BundleCompat
import androidx.fragment.app.testing.FragmentScenario
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import androidx.recyclerview.widget.RecyclerView
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.ichi2.anki.R
import com.ichi2.anki.RobolectricTest
import com.ichi2.anki.dialogs.utils.AnKingTags
import com.ichi2.anki.model.CardStateFilter
import com.ichi2.compat.CompatHelper.Companion.getSerializableCompat
import com.ichi2.testutils.HamcrestUtils.containsInAnyOrder
import com.ichi2.testutils.ParametersUtils
import com.ichi2.testutils.RecyclerViewUtils
Expand All @@ -44,68 +37,10 @@ import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito
import org.mockito.kotlin.whenever
import timber.log.Timber
import java.util.concurrent.atomic.AtomicReference

@RunWith(AndroidJUnit4::class)
class TagsDialogTest : RobolectricTest() {
@Test
fun testTagsDialogCustomStudyOptionInterface() {
val type = TagsDialog.DialogType.CUSTOM_STUDY_TAGS
val allTags = listOf("1", "2", "3", "4")
val args =
TagsDialog(ParametersUtils.whatever())
.withTestArguments(type, ArrayList(), allTags)
.requireArguments()
val mockListener = Mockito.mock(TagsDialogListener::class.java)
val factory = TagsDialogFactory(mockListener)
runTagsDialogScenario(args, factory) { f: TagsDialog ->
val dialog = f.dialog as AlertDialog?
assertThat(dialog, IsNull.notNullValue())

val optionsGroup = dialog!!.findViewById<RadioGroup>(R.id.tags_dialog_options_radiogroup)!!
Assert.assertEquals(optionsGroup.visibility.toLong(), View.VISIBLE.toLong())
val expectedOption = CardStateFilter.NEW
optionsGroup.getChildAt(1).performClick()
dialog.getButton(DialogInterface.BUTTON_POSITIVE).callOnClick()
advanceRobolectricLooper()
Mockito.verify(mockListener, Mockito.times(1)).onSelectedTags(ArrayList(), ArrayList(), expectedOption)
}
}

@Test
fun testTagsDialogCustomStudyOptionFragmentAPI() {
val type = TagsDialog.DialogType.CUSTOM_STUDY_TAGS
val allTags = listOf("1", "2", "3", "4")
val args =
TagsDialog(ParametersUtils.whatever())
.withTestArguments(type, ArrayList(), allTags)
.requireArguments()
runTagsDialogScenario(args) { f: TagsDialog ->
val dialog = f.dialog as AlertDialog?
assertThat(dialog, IsNull.notNullValue())
val returnedList = AtomicReference<List<String>?>()
val returnedOption = AtomicReference<CardStateFilter>()
f.parentFragmentManager.setFragmentResultListener(
TagsDialogListener.ON_SELECTED_TAGS_KEY,
mockLifecycleOwner(),
) { _: String?, bundle: Bundle ->
returnedList.set(bundle.getStringArrayList(TagsDialogListener.ON_SELECTED_TAGS__SELECTED_TAGS))
returnedOption.set(bundle.getSerializableCompat<CardStateFilter>(TagsDialogListener.ON_SELECTED_TAGS__OPTION))
}

val optionsGroup = dialog!!.findViewById<RadioGroup>(R.id.tags_dialog_options_radiogroup)!!
Assert.assertEquals(optionsGroup.visibility.toLong(), View.VISIBLE.toLong())
val expectedOption = CardStateFilter.DUE
optionsGroup.getChildAt(2).performClick()
dialog.getButton(DialogInterface.BUTTON_POSITIVE).callOnClick()
advanceRobolectricLooper()
ListUtil.assertListEquals(ArrayList(), returnedList.get())
Assert.assertEquals(expectedOption, returnedOption.get())
}
}

// regression test #8762
// test for #8763
@Test
Expand Down Expand Up @@ -712,14 +647,4 @@ class TagsDialogTest : RobolectricTest() {
}
}
}

companion object {
private fun mockLifecycleOwner(): LifecycleOwner {
val owner = Mockito.mock(LifecycleOwner::class.java)
val lifecycle = LifecycleRegistry(owner)
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
whenever(owner.lifecycle).thenReturn(lifecycle)
return owner
}
}
}

0 comments on commit a2540a4

Please sign in to comment.