use of com.ichi2.libanki.Model in project AnkiChinaAndroid by ankichinateam.
the class NoteEditorTest method stickyFieldsAreUnchangedAfterAdd.
@Test
public void stickyFieldsAreUnchangedAfterAdd() {
// #6795 - newlines were converted to <br>
Model basic = makeNoteForType(NoteType.BASIC);
// Enable sticky "Front" field
basic.getJSONArray("flds").getJSONObject(0).put("sticky", true);
String initFirstField = "Hello";
String initSecondField = "unused";
// /r/n on Windows under Robolectric
String newFirstField = "Hello" + FieldEditText.NEW_LINE + "World";
NoteEditor editor = getNoteEditorAdding(NoteType.BASIC).withFirstField(initFirstField).withSecondField(initSecondField).build();
assertThat(Arrays.asList(editor.getCurrentFieldStrings()), contains(initFirstField, initSecondField));
editor.setFieldValueFromUi(0, newFirstField);
assertThat(Arrays.asList(editor.getCurrentFieldStrings()), contains(newFirstField, initSecondField));
editor.saveNote();
this.waitForAsyncTasksToComplete();
List<String> actual = Arrays.asList(editor.getCurrentFieldStrings());
assertThat("newlines should be preserved, second field should be blanked", actual, contains(newFirstField, ""));
}
use of com.ichi2.libanki.Model in project AnkiChinaAndroid by ankichinateam.
the class ReviewerTest method baseDeckName.
@Test
public void baseDeckName() {
Collection col = getCol();
Models models = col.getModels();
Decks decks = col.getDecks();
Long didAb = decks.id("A::B");
Model basic = models.byName(AnkiDroidApp.getAppResources().getString(R.string.basic_model_name));
basic.put("did", didAb);
addNoteUsingBasicModel("foo", "bar");
Long didA = decks.id("A");
decks.select(didA);
Reviewer reviewer = startReviewer();
waitForAsyncTasksToComplete();
assertThat(reviewer.getSupportActionBar().getTitle(), is("B"));
}
use of com.ichi2.libanki.Model 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.libanki.Model in project AnkiChinaAndroid by ankichinateam.
the class RobolectricTest method addNonClozeModel.
protected String addNonClozeModel(String name, String[] fields, String qfmt, String afmt) {
Model model = getCol().getModels().newModel(name);
for (int i = 0; i < fields.length; i++) {
addField(model, fields[i]);
}
model.put(FlashCardsContract.CardTemplate.QUESTION_FORMAT, qfmt);
model.put(FlashCardsContract.CardTemplate.ANSWER_FORMAT, afmt);
getCol().getModels().add(model);
getCol().getModels().flush();
return name;
}
use of com.ichi2.libanki.Model in project AnkiChinaAndroid by ankichinateam.
the class CardTest method test_genrem.
@Test
public void test_genrem() {
Collection col = getCol();
Note note = col.newNote();
note.setItem("Front", "1");
note.setItem("Back", "");
col.addNote(note);
assertEquals(1, note.numberOfCards());
Model m = col.getModels().current();
Models mm = col.getModels();
// adding a new template should automatically create cards
JSONObject t = Models.newTemplate("rev");
t.put("qfmt", "{{Front}}");
t.put("afmt", "");
mm.addTemplateModChanged(m, t);
mm.save(m, true);
assertEquals(2, note.numberOfCards());
// if the template is changed to remove cards, they'll be removed
t = m.getJSONArray("tmpls").getJSONObject(1);
t.put("qfmt", "{{Back}}");
mm.save(m, true);
List<Long> rep = col.emptyCids();
col.remCards(rep);
assertEquals(1, note.numberOfCards());
// if we add to the note, a card should be automatically generated
note.load();
note.setItem("Back", "1");
note.flush();
assertEquals(2, note.numberOfCards());
}
Aggregations