コード例 #1
0
  public void testUserSaveNewQuestion() {
    screen.fillQuestionAndAnswer("foo", "bar");
    screen.selectSaveMenuItem();

    Question questionFromDb = dataService.findQuestionById(dataService.findAllQuestionIds().get(0));
    assertEquals("foo", questionFromDb.getValue());
    assertEquals("bar", questionFromDb.getAnswer());
  }
コード例 #2
0
  private void addQuestionWithValueAndAnswer(String value, String answer) {
    QuestionListScreen listScreen =
        QuestionListScreen.screenForAcceptanceTests(getInstrumentation(), solo);
    listScreen.selectNewQuestionMenu();

    QuestionEditScreen editScreen =
        QuestionEditScreen.screenForAcceptanceTests(getInstrumentation(), solo);
    editScreen.fillQuestionAndAnswer(value, answer);
    editScreen.selectSaveMenuItem();
  }
コード例 #3
0
 public void testShouldGoToHomeWhenUserClicksHomeButton() {
   if (Build.VERSION.SDK_INT >= 11) {
     screen.selectHomeMenuItem();
     Intent goToHomeIntent = getStartedActivityIntent();
     assertEquals(".activities.MainActivity", goToHomeIntent.getComponent().getShortClassName());
   }
 }
コード例 #4
0
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    this.startActivity(
        new Intent(
            QuestionEditActivity.ADD_QUESTION_ACTION,
            Uri.parse("kotoba://kotoba.fiive.net/question/new")),
        null,
        null);
    QuestionEditActivity activity = getActivity();
    new DatabaseCleaner().cleanDatabase(getInstrumentation().getTargetContext());
    dataService = new DataService(getInstrumentation().getTargetContext());

    screen = QuestionEditScreen.screenForUnitTests(activity);
    screen.onActivityCreated(null);
  }
コード例 #5
0
  public void testUserClicksOnSaveAndNew() {
    screen.fillQuestionAndAnswer("foo", "bar");
    screen.selectSaveAndNewMenuItem();

    Question questionFromDb = dataService.findQuestionById(dataService.findAllQuestionIds().get(0));
    assertEquals("foo", questionFromDb.getValue());
    assertEquals("", screen.getValueText());
    assertEquals("", screen.getAnswerText());

    screen.fillQuestionAndAnswer("foo2", "bar2");
    screen.selectSaveAndNewMenuItem();
    assertEquals(2, dataService.findAllQuestionIds().size());
  }
コード例 #6
0
 public void testUserClicksCancelButton() {
   if (Build.VERSION.SDK_INT < 11) {
     screen.clickOnCancelButton();
     assertBackToQuestionList();
   }
 }
コード例 #7
0
 public void testUserClicksCancelMenu() {
   screen.selectCancelMenuItem();
   assertBackToQuestionList();
 }
コード例 #8
0
  public void testIteration() throws InterruptedException {

    if (Build.VERSION.SDK_INT < 11) {

      QuestionGameScreen screen =
          QuestionGameScreen.screenForAcceptanceTest(getInstrumentation(), solo);
      assertTrue(screen.hasDefaultQuestionValue());
      assertFalse(screen.isAnswerVisible());

      screen.clickOnShowAnswerButton();
      assertTrue(screen.isAnswerVisible());
      assertTrue(screen.hasDefaultAnswerValue());

      screen.clickOnNextQuestionButton();
      assertFalse(screen.isAnswerVisible());
      assertTrue(screen.hasDefaultQuestionValue());

      screen.selectManageQuestionsMenu();

      QuestionListScreen listScreen =
          QuestionListScreen.screenForAcceptanceTests(getInstrumentation(), solo);
      assertTrue(listScreen.isEmpty());

      addQuestionWithValueAndAnswer("Question 01", "Answer 01");
      listScreen = QuestionListScreen.screenForAcceptanceTests(getInstrumentation(), solo);
      assertEquals(1, listScreen.getListSize());
      assertEquals("Question 01", listScreen.getTextAtLine(0));

      addQuestionWithValueAndAnswer("Question 02", "");
      listScreen = QuestionListScreen.screenForAcceptanceTests(getInstrumentation(), solo);
      assertEquals(2, listScreen.getListSize());
      assertEquals("Question 02", listScreen.getTextAtLine(1));

      solo.clickOnText("Question 02");
      QuestionEditScreen editScreen =
          QuestionEditScreen.screenForAcceptanceTests(getInstrumentation(), solo);
      editScreen.fillQuestionAndAnswer("Question 03", editScreen.getAnswerText());
      editScreen.selectSaveMenuItem();

      listScreen = QuestionListScreen.screenForAcceptanceTests(getInstrumentation(), solo);
      assertEquals(2, listScreen.getListSize());
      assertEquals("Question 03", listScreen.getTextAtLine(1));

      solo.goBack();
      screen = QuestionGameScreen.screenForAcceptanceTest(getInstrumentation(), solo);
      String firstText = screen.getValueText();
      assertTrue(firstText.equals("Question 01") || firstText.equals("Question 03"));
      assertFalse(screen.isAnswerVisible());
      screen.clickOnShowAnswerButton();
      if (firstText.equals("Question 01")) {
        assertEquals("Answer 01", screen.getAnswerText());
      } else {
        assertEquals("", screen.getAnswerText());
      }
      screen.clickOnNextQuestionButton();
      String secondText = screen.getValueText();
      assertTrue(secondText.equals("Question 01") || secondText.equals("Question 03"));
      assertFalse(screen.isAnswerVisible());

      screen.selectManageQuestionsMenu();
      removeQuestion("Question 01");
      listScreen = QuestionListScreen.screenForAcceptanceTests(getInstrumentation(), solo);
      assertEquals(1, listScreen.getListSize());
      assertEquals("Question 03", listScreen.getTextAtLine(0));

      removeQuestion("Question 03");
      listScreen = QuestionListScreen.screenForAcceptanceTests(getInstrumentation(), solo);
      assertTrue(listScreen.isEmpty());

      solo.goBack();
      screen = QuestionGameScreen.screenForAcceptanceTest(getInstrumentation(), solo);
      assertTrue(screen.hasDefaultQuestionValue());
    }
  }
コード例 #9
0
 private void removeQuestion(String question) throws InterruptedException {
   solo.clickOnText(question);
   QuestionEditScreen editScreen =
       QuestionEditScreen.screenForAcceptanceTests(getInstrumentation(), solo);
   editScreen.removeCurrentQuestion();
 }