use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START in project Anki-Android by ankidroid.
the class CardTemplatePreviewerTest method testPreviewNormal.
@Test
public void testPreviewNormal() {
// Make sure we test previewing a new card template
String modelName = "Basic (and reversed card)";
Model collectionBasicModelOriginal = getCurrentDatabaseModelCopy(modelName);
Card testCard1 = getSavedCard(collectionBasicModelOriginal, 0);
Card testCard2 = getSavedCard(collectionBasicModelOriginal, 1);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra("cardList", new long[] { testCard1.getId(), testCard2.getId() });
intent.putExtra("index", 0);
ActivityController<TestCardTemplatePreviewer> previewerController = Robolectric.buildActivity(TestCardTemplatePreviewer.class, intent).create().start().resume().visible();
saveControllerForCleanup(previewerController);
// Take it through a destroy/re-create lifecycle in order to test instance state persistence
Bundle outBundle = new Bundle();
previewerController.saveInstanceState(outBundle);
previewerController.pause().stop().destroy();
previewerController = Robolectric.buildActivity(TestCardTemplatePreviewer.class).create(outBundle).start().resume().visible();
saveControllerForCleanup((previewerController));
TestCardTemplatePreviewer testCardTemplatePreviewer = previewerController.get();
// Make sure we can click
Assert.assertFalse("Showing the answer already?", testCardTemplatePreviewer.getShowingAnswer());
testCardTemplatePreviewer.disableDoubleClickPrevention();
View showAnswerButton = testCardTemplatePreviewer.findViewById(R.id.preview_buttons_layout);
showAnswerButton.performClick();
Assert.assertTrue("Not showing the answer?", testCardTemplatePreviewer.getShowingAnswer());
}
use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START in project Anki-Android by ankidroid.
the class CardTemplatePreviewerTest method testPreviewUnsavedTemplate.
@Test
public void testPreviewUnsavedTemplate() {
String modelName = "Basic";
Model collectionBasicModelOriginal = getCurrentDatabaseModelCopy(modelName);
JSONObject template = collectionBasicModelOriginal.getJSONArray("tmpls").getJSONObject(0);
template.put("qfmt", template.getString("qfmt") + "PREVIEWER_TEST");
String tempModelPath = TemporaryModel.saveTempModel(getTargetContext(), collectionBasicModelOriginal);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra(TemporaryModel.INTENT_MODEL_FILENAME, tempModelPath);
intent.putExtra("index", 0);
ActivityController<TestCardTemplatePreviewer> previewerController = Robolectric.buildActivity(TestCardTemplatePreviewer.class, intent).create().start().resume().visible();
saveControllerForCleanup((previewerController));
TestCardTemplatePreviewer testCardTemplatePreviewer = previewerController.get();
Assert.assertTrue("model change did not show up?", testCardTemplatePreviewer.getDummyCard(collectionBasicModelOriginal, 0).q().contains("PREVIEWER_TEST") && testCardTemplatePreviewer.getDummyCard(collectionBasicModelOriginal, 0).a().contains("PREVIEWER_TEST"));
// Take it through a destroy/re-create lifecycle in order to test instance state persistence
Bundle outBundle = new Bundle();
previewerController.saveInstanceState(outBundle);
previewerController.pause().stop().destroy();
previewerController = Robolectric.buildActivity(TestCardTemplatePreviewer.class).create(outBundle).start().resume().visible();
saveControllerForCleanup(previewerController);
testCardTemplatePreviewer = previewerController.get();
Assert.assertTrue("model change not preserved in lifecycle??", testCardTemplatePreviewer.getDummyCard(collectionBasicModelOriginal, 0).q().contains("PREVIEWER_TEST") && testCardTemplatePreviewer.getDummyCard(collectionBasicModelOriginal, 0).a().contains("PREVIEWER_TEST"));
// Make sure we can click
Assert.assertFalse("Showing the answer already?", testCardTemplatePreviewer.getShowingAnswer());
testCardTemplatePreviewer.disableDoubleClickPrevention();
View showAnswerButton = testCardTemplatePreviewer.findViewById(R.id.preview_buttons_layout);
showAnswerButton.performClick();
Assert.assertTrue("Not showing the answer?", testCardTemplatePreviewer.getShowingAnswer());
}
use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START in project Anki-Android by ankidroid.
the class CardTemplatePreviewerTest method testPreviewUnsavedTemplate_basic_answer.
@Test
@Config(qualifiers = "en")
public void testPreviewUnsavedTemplate_basic_answer() {
String modelName = "Basic (type in the answer)";
Model collectionBasicModelOriginal = getCurrentDatabaseModelCopy(modelName);
List<String> fields = collectionBasicModelOriginal.getFieldsNames();
JSONObject template = collectionBasicModelOriginal.getJSONArray("tmpls").getJSONObject(0);
template.put("qfmt", template.getString("qfmt") + "PREVIEWER_TEST");
String tempModelPath = TemporaryModel.saveTempModel(getTargetContext(), collectionBasicModelOriginal);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra(TemporaryModel.INTENT_MODEL_FILENAME, tempModelPath);
intent.putExtra("index", 0);
ActivityController<TestCardTemplatePreviewer> previewerController = Robolectric.buildActivity(TestCardTemplatePreviewer.class, intent).create().start().resume().visible();
saveControllerForCleanup((previewerController));
TestCardTemplatePreviewer testCardTemplatePreviewer = previewerController.get();
String[] arr = testCardTemplatePreviewer.getDummyCard(collectionBasicModelOriginal, 0).note().getFields();
assertThat(arr[0], is("(" + fields.get(0) + ")"));
assertThat(arr[1], is(testCardTemplatePreviewer.getString(R.string.basic_answer_sample_text)));
}
use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START in project Anki-Android by ankidroid.
the class CardTemplatePreviewerTest method testPreviewUnsavedTemplate_Cloze.
@Test
@Config(qualifiers = "en")
public void testPreviewUnsavedTemplate_Cloze() {
String modelName = "Cloze";
Model collectionBasicModelOriginal = getCurrentDatabaseModelCopy(modelName);
List<String> fields = collectionBasicModelOriginal.getFieldsNames();
JSONObject template = collectionBasicModelOriginal.getJSONArray("tmpls").getJSONObject(0);
template.put("qfmt", template.getString("qfmt") + "PREVIEWER_TEST");
String tempModelPath = TemporaryModel.saveTempModel(getTargetContext(), collectionBasicModelOriginal);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra(TemporaryModel.INTENT_MODEL_FILENAME, tempModelPath);
intent.putExtra("index", 0);
ActivityController<TestCardTemplatePreviewer> previewerController = Robolectric.buildActivity(TestCardTemplatePreviewer.class, intent).create().start().resume().visible();
saveControllerForCleanup((previewerController));
TestCardTemplatePreviewer testCardTemplatePreviewer = previewerController.get();
String[] arr = testCardTemplatePreviewer.getDummyCard(collectionBasicModelOriginal, 0).note().getFields();
assertThat(arr[0], is(testCardTemplatePreviewer.getString(R.string.cloze_sample_text, "c1")));
assertThat(arr[1], is("(" + fields.get(1) + ")"));
}
use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START in project Anki-Android by ankidroid.
the class SchedV2Test method test_reorder.
@Test
public void test_reorder() throws Exception {
Collection col = getColV2();
// add a note with default deck
Note note = col.newNote();
note.setItem("Front", "one");
col.addNote(note);
Note note2 = col.newNote();
note2.setItem("Front", "two");
col.addNote(note2);
assertEquals(2, note2.cards().get(0).getDue());
boolean found = false;
// 50/50 chance of being reordered
for (int i = 0; i < 20; i++) {
col.getSched().randomizeCards(1);
if (note.cards().get(0).getDue() != note.getId()) {
found = true;
break;
}
}
assertTrue(found);
col.getSched().orderCards(1);
assertEquals(1, note.cards().get(0).getDue());
// shifting
Note note3 = col.newNote();
note3.setItem("Front", "three");
col.addNote(note3);
Note note4 = col.newNote();
note4.setItem("Front", "four");
col.addNote(note4);
assertEquals(1, note.cards().get(0).getDue());
assertEquals(2, note2.cards().get(0).getDue());
assertEquals(3, note3.cards().get(0).getDue());
assertEquals(4, note4.cards().get(0).getDue());
/* todo: start
col.getSched().sortCards(new long [] {note3.cards().get(0).getId(), note4.cards().get(0).getId()}, start=1, shift=true);
assertEquals(3, note.cards().get(0).getDue());
assertEquals(4, note2.cards().get(0).getDue());
assertEquals(1, note3.cards().get(0).getDue());
assertEquals(2, note4.cards().get(0).getDue());
*/
}
Aggregations