Skip to content

Commit

Permalink
NF: rename model to note type
Browse files Browse the repository at this point in the history
As David mentioned recently, Anki don't use "model" anymore, it should
not be in the codebase.

There are two places where `model` should not be replaced. When the
variable refers to a model that is not a note type (e.g. a viewModel,
the Card Browser's model..). And when the word "model" appears in the
API. Indeed we should not break the existing code using the API.

While it may be considered to extend our API, duplicating the Model
commands to introduce a NoteType command with the same meaning. And,
maybe one day, deprecate the previous API. But I don't think there is
even a need to deprecate the API, it does not really lead to
confusion.

On top of replacing "model", "models", "Model", "Models", "MODEL",
"MODELS", we also rename the variables "m", "m2" and "mm" as those
variable where abbreviations for "Model". I renamed some layout, menu,

In one case, the documentation was wrong. It mentioned "model" instead
of "template". I thus replaced "model" by "template" in order to
correct the documentation.

Note that all the changes were done manually. I used Android-Studio to
rename function, variables, values and constant. But I generally
avoided the "search and replace" feature which may have led to
erroneous update. (Example of exception: `m` and `mm` in `modelTest`
  • Loading branch information
Arthur-Milchior committed Dec 29, 2024
1 parent afe220c commit aaaa9df
Show file tree
Hide file tree
Showing 74 changed files with 1,375 additions and 1,368 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DeckPickerTest : InstrumentedTest() {

@Before
fun before() {
addNoteUsingBasicModel()
addNoteUsingBasicNoteType()
disableIntroductionSlide()
discardPreliminaryViews()
}
Expand Down
4 changes: 2 additions & 2 deletions AnkiDroid/src/androidTest/java/com/ichi2/anki/PagesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ class PagesTest : InstrumentedTest() {
fun PagesTest.getStatistics(context: Context): Intent = Statistics.getIntent(context)

fun PagesTest.getCardInfo(context: Context): Intent =
addNoteUsingBasicModel().firstCard(col).let { card ->
addNoteUsingBasicNoteType().firstCard(col).let { card ->
this.card = card
CardInfoDestination(card.id).toIntent(context)
}

fun PagesTest.getCongratsPage(context: Context): Intent =
addNoteUsingBasicModel().firstCard(col).let { card ->
addNoteUsingBasicNoteType().firstCard(col).let { card ->
this.card = card
CardInfoDestination(card.id).toIntent(context)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ReviewerFragmentTest : InstrumentedTest() {
states.good.normal.review.scheduledDays = 123;
customData.good.c += 1;
"""
val note = addNoteUsingBasicModel("foo", "bar")
val note = addNoteUsingBasicNoteType("foo", "bar")
val card = note.firstCard(col)
val deck = col.decks.get(note.notetype.did)!!
card.moveToReviewQueue()
Expand Down Expand Up @@ -107,7 +107,7 @@ class ReviewerFragmentTest : InstrumentedTest() {
setNewReviewer()
// Issue 15035 - runtime errors weren't handled
col.cardStateCustomizer = "states.this_is_not_defined.normal.review = 12;"
addNoteUsingBasicModel()
addNoteUsingBasicNoteType()

closeGetStartedScreenIfExists()
closeBackupCollectionDialogIfExists()
Expand Down
4 changes: 2 additions & 2 deletions AnkiDroid/src/androidTest/java/com/ichi2/anki/ReviewerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class ReviewerTest : InstrumentedTest() {
states.good.normal.review.scheduledDays = 123;
customData.good.c += 1;
"""
val note = addNoteUsingBasicModel("foo", "bar")
val note = addNoteUsingBasicNoteType("foo", "bar")
val card = note.firstCard(col)
val deck = col.decks.get(note.notetype.did)!!
card.moveToReviewQueue()
Expand Down Expand Up @@ -136,7 +136,7 @@ class ReviewerTest : InstrumentedTest() {
fun testCustomSchedulerWithRuntimeError() {
// Issue 15035 - runtime errors weren't handled
col.cardStateCustomizer = "states.this_is_not_defined.normal.review = 12;"
addNoteUsingBasicModel()
addNoteUsingBasicNoteType()

closeGetStartedScreenIfExists()
closeBackupCollectionDialogIfExists()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.ichi2.anki.R
import com.ichi2.anki.dialogs.ModelEditorContextMenu.ModelEditorContextMenuAction
import com.ichi2.anki.dialogs.NoteTypeEditorContextMenu.Action
import com.ichi2.anki.tests.InstrumentedTest
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class ModelEditorContextMenuTest : InstrumentedTest() {
class NoteTypeEditorContextMenuTest : InstrumentedTest() {
private val testDialogTitle = "test editor title"

@Test
@Ignore("flaky")
fun showsAllOptions() {
launchFragment(
fragmentArgs = bundleOf(ModelEditorContextMenu.KEY_LABEL to testDialogTitle),
fragmentArgs = bundleOf(NoteTypeEditorContextMenu.KEY_LABEL to testDialogTitle),
themeResId = R.style.Theme_Light,
) { ModelEditorContextMenu() }
) { NoteTypeEditorContextMenu() }
onView(withText(testDialogTitle)).check(matches(isDisplayed()))
ModelEditorContextMenuAction.entries.forEach {
Action.entries.forEach {
onView(withText(it.actionTextId)).check(matches(isDisplayed()))
}
}
Expand Down
Loading

0 comments on commit aaaa9df

Please sign in to comment.