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

NF: use "note type" in androidTest #17711

Merged
merged 1 commit into from
Jan 4, 2025
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 @@ -1414,14 +1414,14 @@ class ContentProviderTest : InstrumentedTest() {
): String {
val noteType = col.notetypes.new(name)
for (field in fields) {
col.notetypes.addFieldInNewModel(noteType, col.notetypes.newField(field))
col.notetypes.addFieldInNewNoteType(noteType, col.notetypes.newField(field))
}
val t =
Notetypes.newTemplate("Card 1").also { t ->
t.qfmt = qfmt
t.afmt = afmt
}
col.notetypes.addTemplateInNewModel(noteType, t)
col.notetypes.addTemplateInNewNoteType(noteType, t)
col.notetypes.add(noteType)
return name
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ class CardContentProvider : ContentProvider() {
// Add the fields
val allFields = Utils.splitFields(fieldNames)
for (f: String? in allFields) {
noteTypes.addFieldInNewModel(newNoteType, noteTypes.newField(f!!))
noteTypes.addFieldInNewNoteType(newNoteType, noteTypes.newField(f!!))
}
// Add some empty card templates
var idx = 0
Expand All @@ -866,7 +866,7 @@ class CardContentProvider : ContentProvider() {
answerField = allFields[1]
}
t.afmt = "{{FrontSide}}\\n\\n<hr id=answer>\\n\\n{{$answerField}}"
noteTypes.addTemplateInNewModel(newNoteType, t)
noteTypes.addTemplateInNewNoteType(newNoteType, t)
idx++
}
// Add the CSS if specified
Expand Down
4 changes: 2 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/libanki/Notetypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ class Notetypes(
* [ConfirmModSchemaException]
*/
@RustCleanup("Since Kotlin doesn't have throws, this may not be needed")
fun addFieldInNewModel(
fun addFieldInNewNoteType(
notetype: NotetypeJson,
field: Field,
) {
Expand All @@ -447,7 +447,7 @@ class Notetypes(
}
}

fun addTemplateInNewModel(
fun addTemplateInNewNoteType(
notetype: NotetypeJson,
template: CardTemplate,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class AbstractFlashcardViewerTest : RobolectricTest() {
fun testEditingCardChangesTypedAnswer() =
runTest {
// 7363
addNoteUsingBasicTypedModel("Hello", "World")
addBasicWithTypingNote("Hello", "World")

val viewer: NonAbstractFlashcardViewer = getViewer(true)

Expand All @@ -171,7 +171,7 @@ class AbstractFlashcardViewerTest : RobolectricTest() {
fun testEditingCardChangesTypedAnswerOnDisplayAnswer() =
runTest {
// 7363
addNoteUsingBasicTypedModel("Hello", "World")
addBasicWithTypingNote("Hello", "World")

val viewer: NonAbstractFlashcardViewer = getViewer(true)

Expand Down Expand Up @@ -256,8 +256,8 @@ class AbstractFlashcardViewerTest : RobolectricTest() {

LanguageHintService.setLanguageHintForField(col.notetypes, withLanguage, typedField, Locale("ja"))

addNoteUsingModelName(withLanguage.getString("name"), "ichi", "ni")
addNoteUsingModelName(normal.getString("name"), "one", "two")
addNoteUsingNoteTypeName(withLanguage.getString("name"), "ichi", "ni")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignorable: name feels too long. No immediate suggestions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. But the note type "Basic (Type in the answer)" is quite hard to rephrase

addNoteUsingNoteTypeName(normal.getString("name"), "one", "two")
val viewer = getViewer(false)

assertThat("A model with a language hint (japanese) should use it", viewer.hintLocale, equalTo("ja"))
Expand Down Expand Up @@ -297,7 +297,7 @@ class AbstractFlashcardViewerTest : RobolectricTest() {
@Test
fun `Show audio play buttons preference handling - sound`() =
runTest {
addNoteUsingBasicTypedModel("SOUND [sound:android_audiorec.3gp]", "back")
addBasicWithTypingNote("SOUND [sound:android_audiorec.3gp]", "back")
getViewerContent().let { content ->
assertThat("show audio preference default value: enabled", content, containsString("playsound:q:0"))
assertThat("show audio preference default value: enabled", content, containsString("SOUND"))
Expand All @@ -317,7 +317,7 @@ class AbstractFlashcardViewerTest : RobolectricTest() {
@Test
fun `Show audio play buttons preference handling - tts`() =
runTest {
addNoteUsingTextToSpeechNoteType("TTS", "BACK")
addTextToSpeechNote("TTS", "BACK")
getViewerContent().let { content ->
assertThat("show audio preference default value: enabled", content, containsString("playsound:q:0"))
assertThat("show audio preference default value: enabled", content, containsString("TTS"))
Expand Down
24 changes: 12 additions & 12 deletions AnkiDroid/src/test/java/com/ichi2/anki/AnkiDroidJsAPITest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AnkiDroidJsAPITest : RobolectricTest() {
val didA = addDeck("Test", setAsSelected = true)
val basic = models.byName(BASIC_MODEL_NAME)
basic!!.put("did", didA)
addNoteUsingBasicModel("foo", "bar")
addBasicNote("foo", "bar")

val reviewer: Reviewer = startReviewer()
val jsapi = reviewer.jsApi
Expand Down Expand Up @@ -76,7 +76,7 @@ class AnkiDroidJsAPITest : RobolectricTest() {
val didA = addDeck("Test", setAsSelected = true)
val basic = models.byName(BASIC_MODEL_NAME)
basic!!.put("did", didA)
addNoteUsingBasicModel("foo", "bar")
addBasicNote("foo", "bar")

val reviewer: Reviewer = startReviewer()
val jsapi = reviewer.jsApi
Expand Down Expand Up @@ -187,7 +187,7 @@ class AnkiDroidJsAPITest : RobolectricTest() {
val didA = addDeck("Test", setAsSelected = true)
val basic = models.byName(BASIC_MODEL_NAME)
basic!!.put("did", didA)
addNoteUsingBasicModel("foo", "bar")
addBasicNote("foo", "bar")

val reviewer: Reviewer = startReviewer()
val jsapi = reviewer.jsApi
Expand Down Expand Up @@ -230,7 +230,7 @@ class AnkiDroidJsAPITest : RobolectricTest() {
val didA = addDeck("Test", setAsSelected = true)
val basic = models.byName(BASIC_MODEL_NAME)
basic!!.put("did", didA)
addNoteUsingBasicModel("foo", "bar")
addBasicNote("foo", "bar")

val reviewer: Reviewer = startReviewer()
val jsapi = reviewer.jsApi
Expand Down Expand Up @@ -291,11 +291,11 @@ class AnkiDroidJsAPITest : RobolectricTest() {
val didA = addDeck("Test", setAsSelected = true)
val basic = models.byName(BASIC_MODEL_NAME)
basic!!.put("did", didA)
addNoteUsingBasicModel("foo", "bar")
addNoteUsingBasicModel("baz", "bak")
addNoteUsingBasicModel("Anki", "Droid")
addNoteUsingBasicModel("Test Card", "Bury and Suspend Card")
addNoteUsingBasicModel("Test Note", "Bury and Suspend Note")
addBasicNote("foo", "bar")
addBasicNote("baz", "bak")
addBasicNote("Anki", "Droid")
addBasicNote("Test Card", "Bury and Suspend Card")
addBasicNote("Test Note", "Bury and Suspend Note")

val reviewer: Reviewer = startReviewer()
val jsapi = reviewer.jsApi
Expand Down Expand Up @@ -360,8 +360,8 @@ class AnkiDroidJsAPITest : RobolectricTest() {
val didA = addDeck("Test", setAsSelected = true)
val basic = models.byName(BASIC_MODEL_NAME)
basic!!.put("did", didA)
addNoteUsingBasicModel("foo", "bar")
addNoteUsingBasicModel("baz", "bak")
addBasicNote("foo", "bar")
addBasicNote("baz", "bak")

val reviewer: Reviewer = startReviewer()
waitForAsyncTasksToComplete()
Expand All @@ -385,7 +385,7 @@ class AnkiDroidJsAPITest : RobolectricTest() {
@Test
fun ankiResetProgressTest() =
runTest {
val n = addNoteUsingBasicModel("Front", "Back")
val n = addBasicNote("Front", "Back")
val c = n.firstCard()

// Make card review with 28L due and 280% ease
Expand Down
40 changes: 20 additions & 20 deletions AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class CardBrowserTest : RobolectricTest() {

@Test
fun flagValueIsShownOnCard() {
val n = addNoteUsingBasicModel("1", "back")
val n = addBasicNote("1", "back")
flagCardForNote(n, Flag.RED)

val cardId = n.cids()[0]
Expand Down Expand Up @@ -441,7 +441,7 @@ class CardBrowserTest : RobolectricTest() {
@Test
fun tagWithBracketsDisplaysProperly() =
runTest {
val n = addNoteUsingBasicModel("Hello", "World")
val n = addBasicNote("Hello", "World")
n.addTag("sketchy::(1)")
n.flush()

Expand All @@ -456,8 +456,8 @@ class CardBrowserTest : RobolectricTest() {
fun previewWorksAfterSort() =
runTest {
// #7286
val cid1 = addNoteUsingBasicModel("Hello", "World").cards()[0].id
val cid2 = addNoteUsingBasicModel("Hello2", "World2").cards()[0].id
val cid1 = addBasicNote("Hello", "World").cards()[0].id
val cid2 = addBasicNote("Hello2", "World2").cards()[0].id

val b = browserWithNoNewCards

Expand Down Expand Up @@ -558,7 +558,7 @@ class CardBrowserTest : RobolectricTest() {
fun resetDataTest() =
runTest {
TimeManager.reset()
addNoteUsingBasicModel("Hello", "World").firstCard().update {
addBasicNote("Hello", "World").firstCard().update {
due = 5
queue = QueueType.Rev
type = CardType.Rev
Expand Down Expand Up @@ -649,8 +649,8 @@ class CardBrowserTest : RobolectricTest() {
@Test
fun checkSearchString() =
runTest {
addNoteUsingBasicModel("Hello", "John")
addNoteUsingBasicModel("New", "world").firstCard().update {
addBasicNote("Hello", "John")
addBasicNote("New", "world").firstCard().update {
did = addDeck("Deck 1", setAsSelected = true)
}

Expand Down Expand Up @@ -729,8 +729,8 @@ class CardBrowserTest : RobolectricTest() {
@Test
fun checkIfSearchAllDecksWorks() =
runTest {
addNoteUsingBasicModel("Hello", "World")
addNoteUsingBasicModel("Front", "Back").firstCard().update {
addBasicNote("Hello", "World")
addBasicNote("Front", "Back").firstCard().update {
did = addDeck("Test Deck", setAsSelected = true)
}

Expand All @@ -753,8 +753,8 @@ class CardBrowserTest : RobolectricTest() {
fun `'notes-only mode' returns one card from each note`() =
runTest {
// #14623: The functionality was broken
addNoteUsingBasicAndReversedModel("Hello", "World")
addNoteUsingBasicAndReversedModel("Hello", "Anki")
addBasicAndReversedNote("Hello", "World")
addBasicAndReversedNote("Hello", "Anki")

browserWithNoNewCards.apply {
searchAllDecks().join()
Expand Down Expand Up @@ -861,11 +861,11 @@ class CardBrowserTest : RobolectricTest() {
ensureCollectionLoadIsSynchronous()
if (reversed) {
for (i in 0 until noteCount) {
addNoteUsingBasicAndReversedModel(i.toString(), "back")
addBasicAndReversedNote(i.toString(), "back")
}
} else {
for (i in 0 until noteCount) {
addNoteUsingBasicModel(i.toString(), "back")
addBasicNote(i.toString(), "back")
}
}
return super.startRegularActivity<CardBrowser>(Intent()).also {
Expand Down Expand Up @@ -1102,8 +1102,8 @@ class CardBrowserTest : RobolectricTest() {

// We're going to move this functionality entirely to the ViewModel over the next few weeks
// so this test should be updated and working after the refactorings are completed
addNoteUsingBasicModel().moveToDeck("First")
addNoteUsingBasicModel().moveToDeck("Second")
addBasicNote().moveToDeck("First")
addBasicNote().moveToDeck("Second")

val secondDeckId = requireNotNull(col.decks.idForName("Second"))

Expand Down Expand Up @@ -1139,7 +1139,7 @@ class CardBrowserTest : RobolectricTest() {
@Config(qualifiers = "en")
fun nextDueTest() {
TimeManager.reset()
val n = addNoteUsingBasicModel("Front", "Back")
val n = addBasicNote("Front", "Back")
val c = n.firstCard()
val decks = col.decks
val cal = Calendar.getInstance()
Expand Down Expand Up @@ -1237,7 +1237,7 @@ class CardBrowserTest : RobolectricTest() {
@Test
fun `tts tags are stripped`() {
val note =
addNonClozeModel(
addStandardNoteType(
"test",
arrayOf("Front", "Back"),
"[anki:tts lang=de_DE voices=com.google.android.tts-de-DE-language]{{Front}}[/anki:tts]",
Expand All @@ -1257,7 +1257,7 @@ class CardBrowserTest : RobolectricTest() {
fun `initial value is correct column`() {
// Column 1 is [QUESTION, SFLD], the values when [SFLD] is selected

addNoteUsingBasicAndReversedModel("Hello", "World")
addBasicAndReversedNote("Hello", "World")

withBrowser {
assertThat(viewModel.column1, equalTo(SFLD))
Expand All @@ -1273,7 +1273,7 @@ class CardBrowserTest : RobolectricTest() {
"use an integration test",
)
fun `column text is updated - cardsOrNotes and column change`() {
addNoteUsingBasicAndReversedModel("Hello", "World")
addBasicAndReversedNote("Hello", "World")

withBrowser {
assertThat("cards: original column", column2TitleText, equalTo("Card Type"))
Expand All @@ -1296,7 +1296,7 @@ class CardBrowserTest : RobolectricTest() {
fun NotetypeJson.addNote(
field: String,
vararg fields: String,
): Note = addNoteUsingModelName(this.name, field, *fields)
): Note = addNoteUsingNoteTypeName(this.name, field, *fields)

@Suppress("SameParameterValue")
private fun withBrowser(
Expand Down
8 changes: 4 additions & 4 deletions AnkiDroid/src/test/java/com/ichi2/anki/DeckPickerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class DeckPickerTest : RobolectricTest() {
dconf.getJSONObject("new").put("perDay", 10)
col.decks.save(dconf)
for (i in 0..10) {
addNoteUsingBasicModel("Which card is this ?", i.toString())
addBasicNote("Which card is this ?", i.toString())
}
// This set a card as current card
sched.card
Expand Down Expand Up @@ -503,7 +503,7 @@ class DeckPickerTest : RobolectricTest() {
val deckId = addDeck("Deck 1")
getColUnsafe.decks.select(deckId)
getColUnsafe.notetypes.byName("Basic")!!.put("did", deckId)
val card = addNoteUsingBasicModel("front", "back").firstCard()
val card = addBasicNote("front", "back").firstCard()
getColUnsafe.sched.buryCards(listOf(card.id))
updateDeckList()
assertEquals(1, visibleDeckCount)
Expand All @@ -519,7 +519,7 @@ class DeckPickerTest : RobolectricTest() {
startActivityNormallyOpenCollectionWithIntent(DeckPicker::class.java, Intent()).run {
val cardIds =
(0..3)
.map { addNoteUsingBasicModel("$it", "").firstCard().id }
.map { addBasicNote("$it", "").firstCard().id }
assertTrue(allCardsInSameDeck(cardIds, 1))
val deckId = addDynamicDeck("Deck 1")
getColUnsafe.sched.rebuildDyn(deckId)
Expand Down Expand Up @@ -703,7 +703,7 @@ class DeckPickerTest : RobolectricTest() {
col.notetypes.byName("Basic (and reversed card)")!!.also { noteType ->
col.notetypes.save(noteType.apply { put("did", deckWithCards) })
}
addNoteUsingBasicAndReversedModel()
addBasicAndReversedNote()

// Answer 'Easy' for one of the cards, burying the other
col.decks.select(deckWithCards)
Expand Down
12 changes: 6 additions & 6 deletions AnkiDroid/src/test/java/com/ichi2/anki/NoteEditorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class NoteEditorTest : RobolectricTest() {
fun copyNoteCopiesDeckId() {
val currentDid = addDeck("Basic::Test")
col.config.set(CURRENT_DECK, currentDid)
val n = super.addNoteUsingBasicModel("Test", "Note")
val n = super.addBasicNote("Test", "Note")
n.notetype.put("did", currentDid)
val editor = getNoteEditorEditingExistingBasicNote("Test", "Note", DECK_LIST)
col.config.set(CURRENT_DECK, Consts.DEFAULT_DECK_ID) // Change DID if going through default path
Expand Down Expand Up @@ -422,7 +422,7 @@ class NoteEditorTest : RobolectricTest() {

// by default, the first deck is selected, so move the card to the second deck
val homeDeckId = addDeck("B", setAsSelected = true)
val note = addNoteUsingBasicModel().updateCards { did = homeDeckId }
val note = addBasicNote().updateCards { did = homeDeckId }
moveToDynamicDeck(note)

// ensure note is correctly setup
Expand Down Expand Up @@ -466,7 +466,7 @@ class NoteEditorTest : RobolectricTest() {
fun `editing card in filtered deck retains deck`() =
runTest {
val homeDeckId = addDeck("A")
val note = addNoteUsingBasicModel().updateCards { did = homeDeckId }
val note = addBasicNote().updateCards { did = homeDeckId }
moveToDynamicDeck(note)

// ensure note is correctly setup
Expand Down Expand Up @@ -528,11 +528,11 @@ class NoteEditorTest : RobolectricTest() {
NoteType.BASIC -> col.notetypes.byName("Basic")
NoteType.CLOZE -> col.notetypes.byName("Cloze")
NoteType.BACK_TO_FRONT -> {
val name = super.addNonClozeModel("Reversed", arrayOf("Front", "Back"), "{{Back}}", "{{Front}}")
val name = super.addStandardNoteType("Reversed", arrayOf("Front", "Back"), "{{Back}}", "{{Front}}")
col.notetypes.byName(name)
}
NoteType.THREE_FIELD_INVALID_TEMPLATE -> {
val name = super.addNonClozeModel("Invalid", arrayOf("Front", "Back", "Side"), "", "")
val name = super.addStandardNoteType("Invalid", arrayOf("Front", "Back", "Side"), "", "")
col.notetypes.byName(name)
}
NoteType.IMAGE_OCCLUSION -> col.notetypes.byName("Image Occlusion")
Expand All @@ -553,7 +553,7 @@ class NoteEditorTest : RobolectricTest() {
back: String,
from: FromScreen,
): NoteEditor {
val n = super.addNoteUsingBasicModel(front, back)
val n = super.addBasicNote(front, back)
return getNoteEditorEditingExistingBasicNote(n, from)
}

Expand Down
Loading
Loading