Search in sources :

Example 1 with DeckManager

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);
}
Also used : Collection(com.ichi2.libanki.Collection) Deck(com.ichi2.libanki.Deck) DeckManager(com.ichi2.libanki.DeckManager) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 2 with DeckManager

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");
        }
    }
}
Also used : JSONObject(com.ichi2.utils.JSONObject) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 3 with DeckManager

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"));
}
Also used : Model(com.ichi2.libanki.Model) Collection(com.ichi2.libanki.Collection) DeckManager(com.ichi2.libanki.DeckManager) ModelManager(com.ichi2.libanki.ModelManager) Test(org.junit.Test)

Example 4 with DeckManager

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));
}
Also used : Deck(com.ichi2.libanki.Deck) DeckManager(com.ichi2.libanki.DeckManager)

Example 5 with DeckManager

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();
    }
}
Also used : Collection(com.ichi2.libanki.Collection) Deck(com.ichi2.libanki.Deck) DeckManager(com.ichi2.libanki.DeckManager) Cursor(android.database.Cursor) Test(org.junit.Test)

Aggregations

DeckManager (com.ichi2.libanki.DeckManager)5 Test (org.junit.Test)5 Collection (com.ichi2.libanki.Collection)4 Deck (com.ichi2.libanki.Deck)3 RobolectricTest (com.ichi2.anki.RobolectricTest)2 Model (com.ichi2.libanki.Model)2 ModelManager (com.ichi2.libanki.ModelManager)2 Cursor (android.database.Cursor)1 Card (com.ichi2.libanki.Card)1 JSONObject (com.ichi2.utils.JSONObject)1