Skip to content

Commit 4daffb5

Browse files
committed
test(NoteEditor): Add test for note type change field restoration
1 parent 3ecad85 commit 4daffb5

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

AnkiDroid/src/test/java/com/ichi2/anki/NoteEditorTest.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,33 @@ class NoteEditorTest : RobolectricTest() {
300300
assertThat("newlines should be preserved, second field should be blanked", actual, contains(newFirstField, ""))
301301
}
302302

303+
@Test
304+
fun `changing note type preserves and restores field contents`() =
305+
runTest {
306+
val fiveFieldNoteTypeName = "FiveFieldType"
307+
val fieldNames = arrayOf("F1", "F2", "F3", "F4", "F5")
308+
addStandardNoteType(fiveFieldNoteTypeName, fieldNames, "{{F1}}", "{{F2}}")
309+
val fiveFieldNoteType = col.notetypes.byName(fiveFieldNoteTypeName)!!
310+
val basicNoteType = col.notetypes.basic
311+
312+
withNoteEditorAdding {
313+
noteType = fiveFieldNoteType
314+
val originalTexts = fieldNames.map { "Text for $it" }
315+
originalTexts.forEachIndexed { i, text -> fields[i] = text }
316+
317+
noteType = basicNoteType
318+
319+
assertThat("Field 1 should be copied", fields[0], equalTo(originalTexts[0]))
320+
assertThat("Field 2 should be copied", fields[1], equalTo(originalTexts[1]))
321+
322+
noteType = fiveFieldNoteType
323+
324+
originalTexts.forEachIndexed { i, text ->
325+
assertThat("Field ${i + 1} should be restored from memory", fields[i], equalTo(text))
326+
}
327+
}
328+
}
329+
303330
@Test
304331
fun `sticky fields do not impact current values`() =
305332
runTest {

0 commit comments

Comments
 (0)