use of com.ichi2.libanki.DeckManager in project Anki-Android by ankidroid.
the class SchedV2Test method regression_test_preview.
@Test
public void regression_test_preview() throws Exception {
// "https://github.com/ankidroid/Anki-Android/issues/7285"
Collection col = getColV2();
DeckManager decks = col.getDecks();
AbstractSched sched = col.getSched();
addNoteUsingBasicModel("foo", "bar");
long did = addDynamicDeck("test");
Deck deck = decks.get(did);
deck.put("resched", false);
sched.rebuildDyn(did);
col.reset();
Card card;
for (int i = 0; i < 3; i++) {
advanceRobolectricLooperWithSleep();
card = sched.getCard();
assertNotNull(card);
sched.answerCard(card, BUTTON_ONE);
}
advanceRobolectricLooperWithSleep();
assertEquals(1, sched.lrnCount());
card = sched.getCard();
assertEquals(1, sched.counts(card).getLrn());
advanceRobolectricLooperWithSleep();
sched.answerCard(card, BUTTON_ONE);
assertDoesNotThrow(col::undo);
}
use of com.ichi2.libanki.DeckManager in project Anki-Android by ankidroid.
the class DecksTest method ensureDeckList.
@Test
public void ensureDeckList() {
DeckManager decks = getCol().getDecks();
for (String deckName : TEST_DECKS) {
addDeck(deckName);
}
Deck brokenDeck = decks.byName("cmxieunwoogyxsctnjmv::INSBGDS");
Asserts.notNull(brokenDeck, "We should get deck with given name");
// Changing the case. That could exists in an old collection or during sync.
brokenDeck.put("name", "CMXIEUNWOOGYXSCTNJMV::INSBGDS");
decks.save(brokenDeck);
decks.childMap();
for (JSONObject deck : decks.all()) {
long did = deck.getLong("id");
for (JSONObject parent : decks.parents(did)) {
Asserts.notNull(parent, "Parent should not be null");
}
}
}
use of com.ichi2.libanki.DeckManager in project Anki-Android by ankidroid.
the class ReviewerTest method jsAnkiGetDeckName.
@Test
public void jsAnkiGetDeckName() {
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();
AnkiDroidJsAPI javaScriptFunction = reviewer.javaScriptFunction();
waitForAsyncTasksToComplete();
assertThat(javaScriptFunction.ankiGetDeckName(), is("B"));
}
use of com.ichi2.libanki.DeckManager in project Anki-Android by ankidroid.
the class AbstractSchedTest method addDeckWithExactName.
private void addDeckWithExactName(String name) {
DeckManager decks = getCol().getDecks();
long did = addDeck(name);
Deck d = decks.get(did);
d.put("name", name);
decks.update(d);
boolean hasMatch = decks.all().stream().anyMatch(x -> name.equals(x.getString("name")));
assertThat(String.format("Deck %s should exist", name), hasMatch, is(true));
}
use of com.ichi2.libanki.DeckManager in project Anki-Android by ankidroid.
the class ContentProviderTest method testQueryAllDecks.
/**
* Test query to decks table
*/
@Test
public void testQueryAllDecks() {
Collection col = getCol();
DeckManager decks = col.getDecks();
Cursor decksCursor = getContentResolver().query(FlashCardsContract.Deck.CONTENT_ALL_URI, FlashCardsContract.Deck.DEFAULT_PROJECTION, null, null, null);
assertNotNull(decksCursor);
try {
assertEquals("Check number of results", decks.count(), decksCursor.getCount());
while (decksCursor.moveToNext()) {
long deckID = decksCursor.getLong(decksCursor.getColumnIndex(FlashCardsContract.Deck.DECK_ID));
String deckName = decksCursor.getString(decksCursor.getColumnIndex(FlashCardsContract.Deck.DECK_NAME));
Deck deck = decks.get(deckID);
assertNotNull("Check that the deck we received actually exists", deck);
assertEquals("Check that the received deck has the correct name", deck.getString("name"), deckName);
}
} finally {
decksCursor.close();
}
}
Aggregations