Search in sources :

Example 21 with CardBrowser

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

the class CardBrowserTest method checkSearchString.

/**
 * 8027
 */
@Test
public void checkSearchString() {
    addNoteUsingBasicModel("Hello", "John");
    long deck = addDeck("Deck 1");
    getCol().getDecks().select(deck);
    Card c2 = addNoteUsingBasicModel("New", "world").firstCard();
    c2.setDid(deck);
    c2.flush();
    CardBrowser cardBrowser = getBrowserWithNoNewCards();
    cardBrowser.searchCards("world or hello");
    advanceRobolectricLooperWithSleep();
    assertThat("Cardbrowser has Deck 1 as selected deck", cardBrowser.getSelectedDeckNameForUi(), is("Deck 1"));
    assertThat("Results should only be from the selected deck", cardBrowser.getCardCount(), is(1));
}
Also used : Card(com.ichi2.libanki.Card) Test(org.junit.Test)

Example 22 with CardBrowser

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

the class CardBrowserTest method resetDataTest.

@Test
@Config(qualifiers = "en")
public void resetDataTest() {
    Card c = addNoteUsingBasicModel("Hello", "World").firstCard();
    c.setDue(5);
    c.setQueue(Consts.QUEUE_TYPE_REV);
    c.setType(Consts.CARD_TYPE_REV);
    c.flush();
    CardBrowser b = getBrowserWithNoNewCards();
    b.checkCardsAtPositions(0);
    CardBrowser.CardCache card = getCheckedCard(b);
    assertThat("Initial due of checked card", card.getColumnHeaderText(CardBrowser.Column.DUE), is("8/12/20"));
    b.resetProgressNoConfirm(Collections.singletonList(card.getId()));
    advanceRobolectricLooperWithSleep();
    assertThat("Position of checked card after reset", card.getColumnHeaderText(CardBrowser.Column.DUE), is("1"));
}
Also used : Card(com.ichi2.libanki.Card) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 23 with CardBrowser

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

the class CardBrowserTest method flagValueIsShownOnCard.

@Test
public void flagValueIsShownOnCard() {
    Note n = addNoteUsingBasicModel("1", "back");
    flagCardForNote(n, 1);
    long cardId = n.cids().get(0);
    CardBrowser b = getBrowserWithNoNewCards();
    int actualFlag = getCardFlagAfterFlagChangeDone(b, cardId);
    assertThat("The card flag value should be reflected in the UI", actualFlag, is(1));
}
Also used : Note(com.ichi2.libanki.Note) Test(org.junit.Test)

Example 24 with CardBrowser

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

the class CardBrowserTest method tagWithBracketsDisplaysProperly.

@Test
public void tagWithBracketsDisplaysProperly() {
    Note n = addNoteUsingBasicModel("Hello", "World");
    n.addTag("sketchy::(1)");
    n.flush();
    CardBrowser b = getBrowserWithNoNewCards();
    b.filterByTag("sketchy::(1)");
    advanceRobolectricLooperWithSleep();
    assertThat("tagged card should be returned", b.getCardCount(), is(1));
}
Also used : Note(com.ichi2.libanki.Note) Test(org.junit.Test)

Example 25 with CardBrowser

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

the class CardBrowserTest method flagsAreShownInBigDecksTest.

@Test
public void flagsAreShownInBigDecksTest() {
    int numberOfNotes = 75;
    CardBrowser cardBrowser = getBrowserWithNotes(numberOfNotes);
    // select a random card
    Random random = new Random(1);
    int cardPosition = random.nextInt(numberOfNotes);
    assumeThat("card position to select is 60", cardPosition, is(60));
    cardBrowser.checkCardsAtPositions(cardPosition);
    assumeTrue("card at position 60 is selected", cardBrowser.hasCheckedCardAtPosition(cardPosition));
    // flag the selected card with flag = 1
    final int flag = 1;
    cardBrowser.flagTask(flag);
    advanceRobolectricLooperWithSleep();
    // check if card flag turned to flag = 1
    assertThat("Card should be flagged", getCheckedCard(cardBrowser).getCard().userFlag(), is(flag));
    // unflag the selected card with flag = 0
    final int unflagFlag = 0;
    cardBrowser.flagTask(unflagFlag);
    advanceRobolectricLooperWithSleep();
    // check if card flag actually changed from flag = 1
    assertThat("Card flag should be removed", getCheckedCard(cardBrowser).getCard().userFlag(), not(flag));
    // deselect and select all cards
    cardBrowser.onSelectNone();
    cardBrowser.onSelectAll();
    // flag all the cards with flag = 3
    final int flagForAll = 3;
    cardBrowser.flagTask(flagForAll);
    advanceRobolectricLooperWithSleep();
    // check if all card flags turned to flag = 3
    assertThat("All cards should be flagged", stream(cardBrowser.getCardIds()).map(cardId -> getCardFlagAfterFlagChangeDone(cardBrowser, cardId)).noneMatch(flag1 -> flag1 != flagForAll));
}
Also used : ActivityController(org.robolectric.android.controller.ActivityController) Bundle(android.os.Bundle) Deck(com.ichi2.libanki.Deck) SortOrder(com.ichi2.libanki.SortOrder) TaskManager(com.ichi2.async.TaskManager) Matchers.not(org.hamcrest.Matchers.not) Random(java.util.Random) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) ApplicationProvider(androidx.test.core.app.ApplicationProvider) ShadowApplication(org.robolectric.shadows.ShadowApplication) Manifest(android.Manifest) Locale(java.util.Locale) Is.is(org.hamcrest.core.Is.is) View(android.view.View) AdapterView(android.widget.AdapterView) AnkiAssert(com.ichi2.testutils.AnkiAssert) ShadowActivity(org.robolectric.shadows.ShadowActivity) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Timber(timber.log.Timber) Objects(java.util.Objects) List(java.util.List) StringRes(androidx.annotation.StringRes) Consts(com.ichi2.libanki.Consts) Application(android.app.Application) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) ListView(android.widget.ListView) Arrays.stream(java.util.Arrays.stream) Matchers.containsString(org.hamcrest.Matchers.containsString) Note(com.ichi2.libanki.Note) RunWith(org.junit.runner.RunWith) Config(org.robolectric.annotation.Config) Intent(android.content.Intent) Shadows.shadowOf(org.robolectric.Shadows.shadowOf) MenuItem(android.view.MenuItem) HashSet(java.util.HashSet) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) IntentAssert(com.ichi2.testutils.IntentAssert) ComponentName(android.content.ComponentName) Robolectric(org.robolectric.Robolectric) Assert.assertTrue(org.junit.Assert.assertTrue) CollectionTask(com.ichi2.async.CollectionTask) Test(org.junit.Test) CheckReturnValue(javax.annotation.CheckReturnValue) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Ignore(org.junit.Ignore) Card(com.ichi2.libanki.Card) Assert(org.junit.Assert) Activity(android.app.Activity) Collections(java.util.Collections) Random(java.util.Random) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 Intent (android.content.Intent)9 Deck (com.ichi2.libanki.Deck)9 Note (com.ichi2.libanki.Note)7 Card (com.ichi2.libanki.Card)6 MenuItem (android.view.MenuItem)5 CollectionTask (com.ichi2.async.CollectionTask)5 JSONObject (com.ichi2.utils.JSONObject)5 HashSet (java.util.HashSet)5 IntentFilter (android.content.IntentFilter)4 SharedPreferences (android.content.SharedPreferences)4 View (android.view.View)4 AdapterView (android.widget.AdapterView)4 SearchView (androidx.appcompat.widget.SearchView)4 Bundle (android.os.Bundle)3 ListView (android.widget.ListView)3 TextView (android.widget.TextView)3 IntegerDialog (com.ichi2.anki.dialogs.IntegerDialog)3 SimpleMessageDialog (com.ichi2.anki.dialogs.SimpleMessageDialog)3 Consts (com.ichi2.libanki.Consts)3