Search in sources :

Example 11 with Reviewer

use of com.ichi2.anki.Reviewer in project Anki-Android by ankidroid.

the class ReviewerTest method testMultipleCards.

@Test
public synchronized void testMultipleCards() throws ConfirmModSchemaException {
    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);
}
Also used : JSONObject(com.ichi2.utils.JSONObject) JSONArray(com.ichi2.utils.JSONArray) Collection(com.ichi2.libanki.Collection) MockTime(com.ichi2.testutils.MockTime) Test(org.junit.Test)

Example 12 with Reviewer

use of com.ichi2.anki.Reviewer 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 13 with Reviewer

use of com.ichi2.anki.Reviewer in project Anki-Android by ankidroid.

the class ReviewerTest method jsTime4ShouldBeBlankIfButtonUnavailable.

@Test
public void jsTime4ShouldBeBlankIfButtonUnavailable() {
    // #6623 - easy should be blank when displaying a card with 3 buttons (after displaying a review)
    Note firstNote = addNoteUsingBasicModel("Hello", "World");
    moveToReviewQueue(firstNote.firstCard());
    addNoteUsingBasicModel("Hello", "World2");
    Reviewer reviewer = startReviewer();
    AnkiDroidJsAPI javaScriptFunction = reviewer.javaScriptFunction();
    // The answer needs to be displayed to be able to get the time.
    displayAnswer(reviewer);
    assertThat("4 buttons should be displayed", reviewer.getAnswerButtonCount(), is(4));
    String nextTime = javaScriptFunction.ankiGetNextTime4();
    assertThat(nextTime, not(emptyString()));
    // Display the next answer
    reviewer.answerCard(Consts.BUTTON_FOUR);
    displayAnswer(reviewer);
    if (schedVersion == 1) {
        assertThat("The 4th button should not be visible", reviewer.getAnswerButtonCount(), is(3));
        String learnTime = javaScriptFunction.ankiGetNextTime4();
        assertThat("If the 4th button is not visible, there should be no time4 in JS", learnTime, emptyString());
    }
}
Also used : Note(com.ichi2.libanki.Note) Matchers.emptyString(org.hamcrest.Matchers.emptyString) Test(org.junit.Test)

Example 14 with Reviewer

use of com.ichi2.anki.Reviewer in project Anki-Android by ankidroid.

the class PreviewerTest method previewerShouldNotAccessScheduler.

@Test
public void previewerShouldNotAccessScheduler() {
    Card cardToPreview = addNoteUsingBasicModel("Hello", "World").firstCard();
    Previewer previewer = getPreviewerPreviewing(cardToPreview);
    assertThat("Previewer is not a reviewer", previewer.canAccessScheduler(), is(false));
}
Also used : Card(com.ichi2.libanki.Card) Test(org.junit.Test)

Example 15 with Reviewer

use of com.ichi2.anki.Reviewer in project Anki-Android by ankidroid.

the class AbstractSchedTest method siblingCorrectlyBuried.

@Test
public void siblingCorrectlyBuried() {
    // #6903
    Collection col = getCol();
    AbstractSched sched = col.getSched();
    DeckConfig dconf = col.getDecks().getConf(1);
    assertThat(dconf, notNullValue());
    dconf.getJSONObject("new").put("bury", true);
    getCol().getDecks().save(dconf);
    final int nbNote = 2;
    Note[] notes = new Note[nbNote];
    for (int i = 0; i < nbNote; i++) {
        Note note = addNoteUsingBasicAndReversedModel("front", "back");
        notes[i] = note;
    }
    col.reset();
    for (int i = 0; i < nbNote; i++) {
        Card card = sched.getCard();
        Counts counts = sched.counts(card);
        // imitate what the reviewer does
        sched.setCurrentCard(card);
        // Actual number of new card.
        assertThat(counts.getNew(), is(greaterThan(nbNote - i)));
        // Maximal number potentially shown,
        assertThat(counts.getNew(), is(lessThanOrEqualTo(nbNote * 2 - i)));
        // because decrementing does not consider burying sibling
        assertEquals(0, counts.getLrn());
        assertEquals(0, counts.getRev());
        assertEquals(notes[i].firstCard().getId(), card.getId());
        assertEquals(Consts.QUEUE_TYPE_NEW, card.getQueue());
        sched.answerCard(card, sched.answerButtons(card));
    }
    Card card = sched.getCard();
    assertNull(card);
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) DeckConfig(com.ichi2.libanki.DeckConfig) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 Collection (com.ichi2.libanki.Collection)10 Card (com.ichi2.libanki.Card)8 JSONObject (com.ichi2.utils.JSONObject)5 Intent (android.content.Intent)4 NonNull (androidx.annotation.NonNull)4 Nullable (androidx.annotation.Nullable)4 Model (com.ichi2.libanki.Model)4 Note (com.ichi2.libanki.Note)4 JSONArray (com.ichi2.utils.JSONArray)4 Resources (android.content.res.Resources)3 View (android.view.View)3 WindowManager (android.view.WindowManager)3 VisibleForTesting (androidx.annotation.VisibleForTesting)3 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)3 TaskData (com.ichi2.async.TaskData)3 ArrayList (java.util.ArrayList)3 Context (android.content.Context)2 SharedPreferences (android.content.SharedPreferences)2 Uri (android.net.Uri)2