use of com.ichi2.anki.exception.ConfirmModSchemaException in project AnkiChinaAndroid by ankichinateam.
the class ReviewerTest method addNoteWithThreeCards.
private void addNoteWithThreeCards() throws ConfirmModSchemaException {
Models 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);
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.anki.exception.ConfirmModSchemaException in project AnkiChinaAndroid by ankichinateam.
the class ModelTest method test_chained_mods.
@Test
public void test_chained_mods() throws ConfirmModSchemaException {
Collection col = getCol();
col.getModels().setCurrent(col.getModels().byName("Cloze"));
Model m = col.getModels().current();
Models mm = col.getModels();
// We replace the default Cloze template
JSONObject t = Models.newTemplate("ChainedCloze");
t.put("qfmt", "{{cloze:text:Text}}");
t.put("afmt", "{{cloze:text:Text}}");
mm.addTemplateModChanged(m, t);
mm.save(m);
col.getModels().remTemplate(m, m.getJSONArray("tmpls").getJSONObject(0));
Note note = col.newNote();
String q1 = "<span style=\"color:red\">phrase</span>";
String a1 = "<b>sentence</b>";
String q2 = "<span style=\"color:red\">en chaine</span>";
String a2 = "<i>chained</i>";
note.setItem("Text", "This {{c1::" + q1 + "::" + a1 + "}} demonstrates {{c1::" + q2 + "::" + a2 + "}} clozes.");
assertEquals(1, col.addNote(note));
String question = note.cards().get(0).q();
/* TODO: chained modifier
assertThat("Question «"+question+"» does not contain the expected string", question, containsString("This <span class=cloze>[sentence]</span> demonstrates <span class=cloze>[chained]</span> clozes.")
);
assertThat(note.cards().get(0).a(), containsString("This <span class=cloze>phrase</span> demonstrates <span class=cloze>en chaine</span> clozes."
));
*/
}
use of com.ichi2.anki.exception.ConfirmModSchemaException in project AnkiChinaAndroid by ankichinateam.
the class ModelTest method test_templates.
@Test
public void test_templates() throws ConfirmModSchemaException {
Collection col = getCol();
Model m = col.getModels().current();
Models 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)"));
}
use of com.ichi2.anki.exception.ConfirmModSchemaException in project AnkiChinaAndroid by ankichinateam.
the class SchedTest method getColV1.
/**
***************
** autogenerated from https://github.com/ankitects/anki/blob/2c73dcb2e547c44d9e02c20a00f3c52419dc277b/pylib/tests/test_cards.py*
****************
*/
private Collection getColV1() throws ConfirmModSchemaException {
Collection col = getCol();
col.changeSchedulerVer(1);
return col;
}
use of com.ichi2.anki.exception.ConfirmModSchemaException in project Anki-Android by ankidroid.
the class SchedV2Test method handlesSmallSteps.
@Test
public void handlesSmallSteps() throws ConfirmModSchemaException {
// a delay of 0 crashed the app (step of 0.01).
getCol().changeSchedulerVer(2);
addNoteUsingBasicModel("Hello", "World");
getCol().getDecks().allConf().get(0).getJSONObject("new").put("delays", new JSONArray(Arrays.asList(0.01, 10)));
Card c = getCol().getSched().getCard();
assertThat(c, notNullValue());
getCol().getSched().answerCard(c, BUTTON_ONE);
}
Aggregations