use of com.ichi2.anki.exception.ConfirmModSchemaException in project AnkiChinaAndroid by ankichinateam.
the class ReviewerTest method testMultipleCards.
@Test
public synchronized void testMultipleCards() throws ConfirmModSchemaException, InterruptedException {
addNoteWithThreeCards();
Collection col = getCol();
JSONObject nw = col.getDecks().confForDid(1).getJSONObject("new");
MockTime time = getCollectionTime();
nw.put("delays", new JSONArray(new int[] { 1, 10, 60, 120 }));
waitForAsyncTasksToComplete();
Reviewer reviewer = startReviewer();
waitForAsyncTasksToComplete();
assertCounts(reviewer, 3, 0, 0);
// card 1 is shown
answerCardOrdinalAsGood(reviewer, 1);
// card get scheduler in [10, 12.5] minutes
time.addM(3);
// We wait 3 minutes to ensure card 2 is scheduled after card 1
// card 2 is shown
answerCardOrdinalAsGood(reviewer, 2);
// Same as above
time.addM(3);
// card 3 is shown
answerCardOrdinalAsGood(reviewer, 3);
undo(reviewer);
assertCurrentOrdIs(reviewer, 3);
// card 3 is shown
answerCardOrdinalAsGood(reviewer, 3);
// Anki Desktop shows "1"
assertCurrentOrdIsNot(reviewer, 3);
}
use of com.ichi2.anki.exception.ConfirmModSchemaException in project AnkiChinaAndroid by ankichinateam.
the class ReviewerTest method cloneTemplate.
private void cloneTemplate(Models models, Model m) throws ConfirmModSchemaException {
JSONArray tmpls = m.getJSONArray("tmpls");
JSONObject defaultTemplate = tmpls.getJSONObject(0);
JSONObject newTemplate = defaultTemplate.deepClone();
newTemplate.put("ord", tmpls.length());
newTemplate.put("name", "Card " + tmpls.length() + 1);
models.addTemplate(m, newTemplate);
}
use of com.ichi2.anki.exception.ConfirmModSchemaException in project AnkiChinaAndroid by ankichinateam.
the class ContentProviderTest method testInsertAndUpdateModel.
/**
* Check that inserting a new model works as expected
*/
@Test
public void testInsertAndUpdateModel() {
final ContentResolver cr = InstrumentationRegistry.getInstrumentation().getTargetContext().getContentResolver();
ContentValues cv = new ContentValues();
// Insert a new model
cv.put(FlashCardsContract.Model.NAME, TEST_MODEL_NAME);
cv.put(FlashCardsContract.Model.FIELD_NAMES, Utils.joinFields(TEST_MODEL_FIELDS));
cv.put(FlashCardsContract.Model.NUM_CARDS, TEST_MODEL_CARDS.length);
Uri modelUri = cr.insert(FlashCardsContract.Model.CONTENT_URI, cv);
assertNotNull("Check inserted model isn't null", modelUri);
assertNotNull("Check last path segment exists", modelUri.getLastPathSegment());
long mid = Long.parseLong(modelUri.getLastPathSegment());
Collection col = reopenCol();
try {
JSONObject model = col.getModels().get(mid);
assertNotNull("Check model", model);
assertEquals("Check model name", TEST_MODEL_NAME, model.getString("name"));
assertEquals("Check templates length", TEST_MODEL_CARDS.length, model.getJSONArray("tmpls").length());
assertEquals("Check field length", TEST_MODEL_FIELDS.length, model.getJSONArray("flds").length());
JSONArray fields = model.getJSONArray("flds");
for (int i = 0; i < fields.length(); i++) {
assertEquals("Check name of fields", TEST_MODEL_FIELDS[i], fields.getJSONObject(i).getString("name"));
}
// Test updating the model CSS (to test updating MODELS_ID Uri)
cv = new ContentValues();
cv.put(FlashCardsContract.Model.CSS, TEST_MODEL_CSS);
assertThat(cr.update(modelUri, cv, null, null), is(greaterThan(0)));
col = reopenCol();
model = col.getModels().get(mid);
assertNotNull("Check model", model);
assertEquals("Check css", TEST_MODEL_CSS, model.getString("css"));
// Update each of the templates in model (to test updating MODELS_ID_TEMPLATES_ID Uri)
for (int i = 0; i < TEST_MODEL_CARDS.length; i++) {
cv = new ContentValues();
cv.put(FlashCardsContract.CardTemplate.NAME, TEST_MODEL_CARDS[i]);
cv.put(FlashCardsContract.CardTemplate.QUESTION_FORMAT, TEST_MODEL_QFMT[i]);
cv.put(FlashCardsContract.CardTemplate.ANSWER_FORMAT, TEST_MODEL_AFMT[i]);
cv.put(FlashCardsContract.CardTemplate.BROWSER_QUESTION_FORMAT, TEST_MODEL_QFMT[i]);
cv.put(FlashCardsContract.CardTemplate.BROWSER_ANSWER_FORMAT, TEST_MODEL_AFMT[i]);
Uri tmplUri = Uri.withAppendedPath(Uri.withAppendedPath(modelUri, "templates"), Integer.toString(i));
assertThat("Update rows", cr.update(tmplUri, cv, null, null), is(greaterThan(0)));
col = reopenCol();
model = col.getModels().get(mid);
assertNotNull("Check model", model);
JSONObject template = model.getJSONArray("tmpls").getJSONObject(i);
assertEquals("Check template name", TEST_MODEL_CARDS[i], template.getString("name"));
assertEquals("Check qfmt", TEST_MODEL_QFMT[i], template.getString("qfmt"));
assertEquals("Check afmt", TEST_MODEL_AFMT[i], template.getString("afmt"));
assertEquals("Check bqfmt", TEST_MODEL_QFMT[i], template.getString("bqfmt"));
assertEquals("Check bafmt", TEST_MODEL_AFMT[i], template.getString("bafmt"));
}
} finally {
// Delete the model (this will force a full-sync)
col.modSchemaNoCheck();
try {
Model model = col.getModels().get(mid);
assertNotNull("Check model", model);
col.getModels().rem(model);
} catch (ConfirmModSchemaException e) {
// This will never happen
}
}
}
use of com.ichi2.anki.exception.ConfirmModSchemaException in project AnkiChinaAndroid by ankichinateam.
the class ImportTest method testCsv2.
@Test
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
public void testCsv2() throws IOException, ConfirmModSchemaException {
Models mm = testCol.getModels();
Model m = mm.current();
JSONObject f = mm.newField("Three");
mm.addField(m, f);
mm.save(m);
Note n = testCol.newNote();
n.setField(0, "1");
n.setField(1, "2");
n.setField(2, "3");
testCol.addNote(n);
// an update with unmapped fields should not clobber those fields
String file = Shared.getTestFilePath(InstrumentationRegistry.getInstrumentation().getTargetContext(), "text-update.txt");
TextImporter i = new TextImporter(testCol, file);
i.initMapping();
i.run();
n.load();
List<String> fields = Arrays.asList(n.getFields());
assertThat(fields, contains("1", "x", "3"));
}
use of com.ichi2.anki.exception.ConfirmModSchemaException in project AnkiChinaAndroid by ankichinateam.
the class ImportTest method addFieldToCurrentModel.
private void addFieldToCurrentModel(String fieldName) throws ConfirmModSchemaException {
Models mm = testCol.getModels();
Model m = mm.current();
JSONObject f = mm.newField(fieldName);
mm.addField(m, f);
mm.save(m);
}
Aggregations