use of com.ichi2.anki.CardBrowser.Column.CARD in project AnkiChinaAndroid by ankichinateam.
the class MathJaxClozeTest method verifyMathJaxClozeCards.
@Test
public void verifyMathJaxClozeCards() {
final Context context = ApplicationProvider.getApplicationContext();
Collection c = getCol();
Note f = c.newNote(c.getModels().byName("Cloze"));
f.setItem("Text", "{{c1::ok}} \\(2^2\\) {{c2::not ok}} \\(2^{{c3::2}}\\) \\(x^3\\) {{c4::blah}} {{c5::text with \\(x^2\\) jax}}");
c.addNote(f);
assertEquals(5, f.numberOfCards());
ArrayList<Card> cards = f.cards();
assertThat(cards.get(0).q(), containsString("class=cloze"));
assertThat(cards.get(1).q(), containsString("class=cloze"));
String s = cards.get(2).q();
assertThat(cards.get(2).q(), not(containsString("class=cloze")));
assertThat(cards.get(3).q(), containsString("class=cloze"));
assertThat(cards.get(4).q(), containsString("class=cloze"));
}
use of com.ichi2.anki.CardBrowser.Column.CARD in project AnkiChinaAndroid by ankichinateam.
the class MathJaxClozeTest method verifyMathJaxInCloze.
@Test
public void verifyMathJaxInCloze() {
final Context context = ApplicationProvider.getApplicationContext();
Collection c = getCol();
{
Note f = c.newNote(c.getModels().byName("Cloze"));
f.setItem("Text", "\\(1 \\div 2 =\\){{c1::\\(\\frac{1}{2}\\)}}");
c.addNote(f);
ArrayList<Card> cards = f.cards();
Card c2 = cards.get(0);
String q = c2.q();
String a = c2.a();
assertThat(q, containsString("\\(1 \\div 2 =\\)"));
assertThat(a, containsString("\\(1 \\div 2 =\\)"));
assertThat(a, containsString("<span class=cloze>\\(\\frac{1}{2}\\)</span>"));
}
{
Note f = c.newNote(c.getModels().byName("Cloze"));
f.setItem("Text", "\\(a\\) {{c1::b}} \\[ {{c1::c}} \\]");
c.addNote(f);
ArrayList<Card> cards = f.cards();
Card c2 = cards.get(0);
String q = c2.q();
assertThat(q, containsString("\\(a\\) <span class=cloze>[...]</span> \\[ [...] \\]"));
}
}
use of com.ichi2.anki.CardBrowser.Column.CARD 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.CardBrowser.Column.CARD in project AnkiChinaAndroid by ankichinateam.
the class AbstractFlashcardViewerCommandTest method cardWith.
private Card cardWith(@FlagDef int flag) {
Card c = mock(Card.class);
int[] flags = new int[] { flag };
when(c.userFlag()).then((invocation) -> flags[0]);
doAnswer(invocation -> {
flags[0] = invocation.getArgument(0);
return null;
}).when(c).setUserFlag(anyInt());
return c;
}
use of com.ichi2.anki.CardBrowser.Column.CARD in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_button_spacingV2.
@Test
public void test_button_spacingV2() throws Exception {
Collection col = getColV2();
Note note = col.newNote();
note.setItem("Front", "one");
col.addNote(note);
// 1 day ivl review card due now
Card c = note.cards().get(0);
c.setType(CARD_TYPE_REV);
c.setQueue(QUEUE_TYPE_REV);
c.setDue(col.getSched().getToday());
c.setReps(1);
c.setIvl(1);
c.startTimer();
c.flush();
col.reset();
// Upstream, there is no space in 2d
assertEquals("2 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, 2)));
assertEquals("3 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, 3)));
assertEquals("4 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, 4)));
// if hard factor is <= 1, then hard may not increase
DeckConfig conf = col.getDecks().confForDid(1);
conf.getJSONObject("rev").put("hardFactor", 1);
col.getDecks().save(conf);
assertEquals("1 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, 2)));
}
Aggregations