From 3c279711cf7a83e108efee64c042f2c21bd26f82 Mon Sep 17 00:00:00 2001 From: KT-1114 Date: Mon, 23 Feb 2026 00:40:59 +0530 Subject: [PATCH] Added tests for export dialog options --- .../ichi2/anki/export/ExportDialogFragment.kt | 3 - .../anki/export/ExportDialogFragmentTest.kt | 65 +++++++++++++++++++ 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/export/ExportDialogFragment.kt b/AnkiDroid/src/main/java/com/ichi2/anki/export/ExportDialogFragment.kt index 3e75e6e87d0e..54559a761bb8 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/export/ExportDialogFragment.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/export/ExportDialogFragment.kt @@ -38,7 +38,6 @@ import com.ichi2.anki.ALL_DECKS_ID import com.ichi2.anki.CollectionManager import com.ichi2.anki.CollectionManager.withCol import com.ichi2.anki.R -import com.ichi2.anki.common.annotations.NeedsTest import com.ichi2.anki.common.time.TimeManager import com.ichi2.anki.common.time.getTimestamp import com.ichi2.anki.databinding.DialogExportOptionsBinding @@ -185,7 +184,6 @@ class ExportDialogFragment : DialogFragment() { /** * Initializes the views representing the extra options available when exporting a collection. */ - @NeedsTest("Checkbox value is provided to the correct export functions (true/false)") private fun DialogExportOptionsBinding.initializeCollectionExportUi() = with(CollectionManager.TR) { collectionIncludeMedia.text = exportingIncludeMedia() @@ -195,7 +193,6 @@ class ExportDialogFragment : DialogFragment() { /** * Initializes the views representing the extra options available when exporting an Anki package. */ - @NeedsTest("Checkbox value is provided to the correct export functions (true/false)") private fun DialogExportOptionsBinding.initializeApkgExportUi() = with(CollectionManager.TR) { apkgIncludeMedia.text = exportingIncludeMedia() diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/export/ExportDialogFragmentTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/export/ExportDialogFragmentTest.kt index ca91eebe4320..3bdb113c47b3 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/export/ExportDialogFragmentTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/export/ExportDialogFragmentTest.kt @@ -22,6 +22,7 @@ import androidx.test.espresso.matcher.RootMatchers.isDialog import androidx.test.espresso.matcher.ViewMatchers.isChecked import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.runners.AndroidJUnit4 import com.ichi2.anki.CollectionManager.TR import com.ichi2.anki.R @@ -33,6 +34,70 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class ExportDialogFragmentTest : RobolectricTest() { + @Test + fun `collection export options are initialized correctly`() { + launchFragment( + themeResId = R.style.Theme_Light, + ).onFragment { + // Select export type as anki collection package. + onView(withId(R.id.export_type_selector)).inRoot(isDialog()).perform(click()) + onData(containsString(TR.exportingAnkiCollectionPackage())) + .inAdapterView(withId(R.id.export_type_selector)) + .perform(click()) + + // Check that the UI elements are displayed and have the correct text and default values for checkboxes. + onView(withId(R.id.collection_include_media)) + .inRoot(isDialog()) + .check(matches(isDisplayed())) + .check(matches(withText(TR.exportingIncludeMedia()))) + .check(matches(isChecked())) + + onView(withId(R.id.collection_export_legacy)) + .inRoot(isDialog()) + .check(matches(isDisplayed())) + .check(matches(withText(TR.exportingSupportOlderAnkiVersions()))) + .check(matches(not(isChecked()))) + } + } + + @Test + fun `apkg export options are initialized correctly`() { + launchFragment( + themeResId = R.style.Theme_Light, + ).onFragment { + // Select export type as anki deck package. + onView(withId(R.id.export_type_selector)).inRoot(isDialog()).perform(click()) + onData(containsString(TR.exportingAnkiDeckPackage())) + .inAdapterView(withId(R.id.export_type_selector)) + .perform(click()) + + // Check that the UI elements are displayed and have the correct text and default values for checkboxes. + onView(withId(R.id.apkg_include_media)) + .inRoot(isDialog()) + .check(matches(isDisplayed())) + .check(matches(withText(TR.exportingIncludeMedia()))) + .check(matches(isChecked())) + + onView(withId(R.id.apkg_include_deck_configs)) + .inRoot(isDialog()) + .check(matches(isDisplayed())) + .check(matches(withText(TR.exportingIncludeDeckConfigs()))) + .check(matches(not(isChecked()))) + + onView(withId(R.id.apkg_include_schedule)) + .inRoot(isDialog()) + .check(matches(isDisplayed())) + .check(matches(withText(TR.exportingIncludeSchedulingInformation()))) + .check(matches(isChecked())) + + onView(withId(R.id.apkg_export_legacy)) + .inRoot(isDialog()) + .check(matches(isDisplayed())) + .check(matches(withText(TR.exportingSupportOlderAnkiVersions()))) + .check(matches(not(isChecked()))) + } + } + @Test fun `Legacy export checkbox(default false) is shown only for collection and apkg`() { launchFragment(