fix(card-template): reject blank card type names - #22117
CapThunder19 wants to merge 1 commit into
Conversation
uhhh? |
david-allison
left a comment
There was a problem hiding this comment.
At least as a start (GPT-6)
Subject: [PATCH] test: use withRenameDialog for dialog assertions
---
Index: AnkiDroid/src/test/java/com/ichi2/anki/notetype/RenameCardTypeDialogTest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/notetype/RenameCardTypeDialogTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/notetype/RenameCardTypeDialogTest.kt
--- a/AnkiDroid/src/test/java/com/ichi2/anki/notetype/RenameCardTypeDialogTest.kt (revision 52fbf9855269bf726ab3a701817eb2a33e8be6c3)
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/notetype/RenameCardTypeDialogTest.kt (revision bd699834bf74ebc064314b56c27d1853a993c54f)
@@ -21,33 +21,33 @@
private var renamedTo: CardTypeName? = null
@Test
- fun `whitespace-only name is rejected`() {
- val dialog = showRenameDialog()
- dialog.getInputField().setText(" ")
- assertFalse(dialog.positiveButton.isEnabled, "Rename should be disabled for a blank name")
- }
+ fun `whitespace-only name is rejected`() =
+ withRenameDialog {
+ getInputField().setText(" ")
+ assertFalse(positiveButton.isEnabled, "Rename should be disabled for a blank name")
+ }
@Test
- fun `quotes-only name is rejected`() {
- val dialog = showRenameDialog()
- dialog.getInputField().setText("\"\"")
- assertFalse(dialog.positiveButton.isEnabled, "Rename should be disabled for a quotes-only name")
+ fun `quotes-only name is rejected`() =
+ withRenameDialog {
+ getInputField().setText("\"\"")
+ assertFalse(positiveButton.isEnabled, "Rename should be disabled for a quotes-only name")
- dialog.getInputField().setText(" \" \" ")
- assertFalse(dialog.positiveButton.isEnabled, "Rename should be disabled for quotes and whitespace")
- }
+ getInputField().setText(" \" \" ")
+ assertFalse(positiveButton.isEnabled, "Rename should be disabled for quotes and whitespace")
+ }
@Test
- fun `valid name is accepted`() {
- val dialog = showRenameDialog()
- dialog.getInputField().setText(" Reverse ")
- assertTrue(dialog.positiveButton.isEnabled, "Rename should be enabled for a valid name")
+ fun `valid name is accepted`() =
+ withRenameDialog {
+ getInputField().setText(" Reverse ")
+ assertTrue(positiveButton.isEnabled, "Rename should be enabled for a valid name")
- dialog.positiveButton.performClick()
- assertThat(renamedTo?.value, equalTo("Reverse"))
- }
+ positiveButton.performClick()
+ assertThat(renamedTo?.value, equalTo("Reverse"))
+ }
- private fun showRenameDialog(): AlertDialog {
+ private fun withRenameDialog(block: AlertDialog.() -> Unit) {
val currentName = CardTypeName.fromString("Card 1")
RenameCardTypeDialog.showInstance(
startRegularActivity<AnkiActivity>(),
@@ -55,6 +55,6 @@
currentName = currentName,
existingNames = listOf(currentName),
) { renamedTo = it }
- return ShadowDialog.getLatestDialog() as AlertDialog
+ block(ShadowDialog.getLatestDialog() as AlertDialog)
}
}0984acf to
0dae7c4
Compare
|
@david-allison applied the test changes and also fixed the description sorry about the leftover placeholder |
0dae7c4 to
deb0e34
Compare
deb0e34 to
b026d15
Compare
mikehardy
left a comment
There was a problem hiding this comment.
Thanks for the tight dialog guard and for applying the test-helper changes.
The production change is the right one: allowEmpty = false only treats isEmpty(), so whitespace/quotes-only still enabled Rename and the failure showed up on save (Fixes #22114). Matching desktop’s “blank after stripping "” via ValidationResult.REJECTED is correct. No #22024-style R.string compile issue on this HEAD.
Request changes (AI_POLICY)
Tests are disclosed as Claude-assisted in the PR note, but commit b026d15d has no Assisted-by: trailer, and Claude sonnet is not a tool version. Please amend/rebase, e.g.
fix(card-template): reject blank card type names
Assisted-by: Claude Sonnet 4.x [tests]
Local on rebased tip: lint / package / emulator green. Full unit suite only hit unrelated PrefsSearchBar / ReminderLogTree order pollution (solo probes for those + RenameCardTypeDialogTest all green).
Assisted-by: Claude Sonnet 5 [tests]
b026d15 to
72d3d1e
Compare
mikehardy
left a comment
There was a problem hiding this comment.
Hey Anirudh 👋
Thanks for adding the Assisted-by: trailer with a tool version. That was the only hold from last time.
The production change still looks right to me: allowEmpty = false only catches isEmpty(), so whitespace/quotes-only still enabled Rename and the failure showed up on save (Fixes #22114). Rejecting after trim + strip " matches desktop’s blank-rename ignore. Tests cover the cases that used to bite.
Happy to Approve. Needs a second reviewer.
Cheers
Note
Assisted-by: Claude sonnet 5 (tests)
Purpose / Description
Renaming a card type to only spaces (or only
"characters) was accepted by the dialog, but saving the note type then failed with "Empty template name" / "Template name contains only quotes", and the other template changes were lost.Fixes
Approach
The Rename button is now disabled when the name is blank after removing
", the same as for an empty field. This matches Anki Desktop, which ignores blank renames (clayout.py,onRename).How Has This Been Tested?
RenameCardTypeDialogTest: blank and quotes-only names are rejected, and a normal name is still accepted and trimmed. The two rejection tests failed before the fix.CardTemplateEditorTest,CardTemplateNotetypeTestand thenotetypetests pass, and so doesktlintCheck.Checklist