use of com.ichi2.libanki.ModelManager in project Anki-Android by ankidroid.
the class ReviewerTest method baseDeckName.
@Test
public void baseDeckName() {
Collection col = getCol();
ModelManager models = col.getModels();
DeckManager decks = col.getDecks();
Long didAb = addDeck("A::B");
Model basic = models.byName(AnkiDroidApp.getAppResources().getString(R.string.basic_model_name));
basic.put("did", didAb);
addNoteUsingBasicModel("foo", "bar");
Long didA = addDeck("A");
decks.select(didA);
Reviewer reviewer = startReviewer();
waitForAsyncTasksToComplete();
assertThat(reviewer.getSupportActionBar().getTitle(), is("B"));
}
use of com.ichi2.libanki.ModelManager in project Anki-Android by ankidroid.
the class ReviewerTest method addNoteWithThreeCards.
private void addNoteWithThreeCards() throws ConfirmModSchemaException {
ModelManager models = getCol().getModels();
Model m = models.copy(models.current());
m.put("name", "Three");
models.add(m);
m = models.byName("Three");
models.flush();
cloneTemplate(models, m);
cloneTemplate(models, m);
@NonNull Note newNote = getCol().newNote();
newNote.setField(0, "Hello");
assertThat(newNote.model().get("name"), is("Three"));
assertThat(getCol().addNote(newNote), is(3));
}
use of com.ichi2.libanki.ModelManager in project Anki-Android by ankidroid.
the class ModelTest method test_templates.
@Test
public void test_templates() throws ConfirmModSchemaException {
Collection col = getCol();
Model m = col.getModels().current();
ModelManager mm = col.getModels();
JSONObject t = Models.newTemplate("Reverse");
t.put("qfmt", "{{Back}}");
t.put("afmt", "{{Front}}");
mm.addTemplateModChanged(m, t);
mm.save(m);
Note note = col.newNote();
note.setItem("Front", "1");
note.setItem("Back", "2");
col.addNote(note);
assertEquals(2, col.cardCount());
List<Card> cards = note.cards();
assertEquals(2, cards.size());
Card c = cards.get(0);
Card c2 = cards.get(1);
// first card should have first ord
assertEquals(0, c.getOrd());
assertEquals(1, c2.getOrd());
// switch templates
col.getModels().moveTemplate(m, c.template(), 1);
c.load();
c2.load();
assertEquals(1, c.getOrd());
assertEquals(0, c2.getOrd());
// removing a template should delete its cards
col.getModels().remTemplate(m, m.getJSONArray("tmpls").getJSONObject(0));
assertEquals(1, col.cardCount());
// and should have updated the other cards' ordinals
c = note.cards().get(0);
assertEquals(0, c.getOrd());
assertEquals("1", stripHTML(c.q()));
// it shouldn't be possible to orphan notes by removing templates
t = Models.newTemplate("template name");
mm.addTemplateModChanged(m, t);
col.getModels().remTemplate(m, m.getJSONArray("tmpls").getJSONObject(0));
assertEquals(0, col.getDb().queryLongScalar("select count() from cards where nid not in (select id from notes)"));
}
Aggregations