Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
469 lines (382 sloc) 19.3 KB
package com.github.johnnysc.tutor.presentation.study
import androidx.test.espresso.Espresso
import com.github.johnnysc.tutor.presentation.core.*
import org.junit.Before
import org.junit.Test
/**
* 0. Check there are 3 categories with 3 items all in initial state
*
* 1.Pass first category all with corrects.
* Check the first category items have corrects 1 and incorrects 0
*
* 2.Pass the second category all with incorrects with skipping.
* Check the second category items have corrects 0 and incorrects 2
* Check the first category items have corrects 1 and incorrects 0
*
* 3.Pass the third one with 1 correct and 2 incorrects just by skipping the first and last one
* Check first and last items have corrects 0 and incorrects 1, the middle one has corrects 1 and incorrects 0
* Check the second category items have corrects 0 and incorrects 1
* Check the first category items have corrects 1 and incorrects 0
*
* 4.Pass first category all with corrects again.
* Check all the items while passing have correct state 1 and incorrect 0.
* After passing check corrects are 2 for each item. And the category has 6 corrects.
* Check all the rest is in the same state.
*
* 5.Pass second category all with corrects.
* Check each item has incorrect 2 and correct 0 while passing through.
* After passing check all the items have 1 correct and 2 incorrects.
* Category in total has 3 corrects and 6 incorrects.
* Check all the rest is in the same state.
*
* 6. Pass third one with corrects.
* Check that first and last items while passing have 0 correct and 1 incorrect.
* Check the middle one has 1 correct and 0 incorrect while passing.
* After passing check that first one and last one each has 1 correct and 1 incorrect.
* After passing check that second one has 2 corrects.
* Check category has 4 corrects and 2 incorrects.
*
* 7. Pass the first category with fails and skips for each one.
* Check each item has 2 corrects and 0 incorrects while passing.
* After passing check that the first category has 6 corrects and 6 incorrects.
* Check all the rest categories data.
*
* 8. Pass the second category with skips for each item.
* Check that category after passing has 3 corrects and 9 incorrects.
* Check all the rest data is still the same.
*
* 9. For the third category skip the first one, answer correct for the second item and then just leave it.
* Check while passing that the first one has 1 correct and 1 incorrect.
* Check while passing that the second item has 2 corrects.
* After leaving the study screen check category has 5 corrects and 3 incorrects
* Check all the rest items are in the same position.
*
* 10. Using developer options Don't keep activities on Nexus 5X recreate the process and check all the data again.
*
* @author Asatryan on 29.06.19
*/
class StudyComplexTest : BaseTest() {
private companion object {
const val FIRST_CATEGORY = "first category"
const val SECOND_CATEGORY = "second category"
const val THIRD_CATEGORY = "third category"
}
private val item101 = InitialData(FIRST_CATEGORY, "source101", "value101")
private val item102 = InitialData(FIRST_CATEGORY, "source102", "value102")
private val item103 = InitialData(FIRST_CATEGORY, "source103", "value103")
private val firstCategoryItems = listOf(item101, item102, item103)
private val item201 = InitialData(SECOND_CATEGORY, "source201", "value201")
private val item202 = InitialData(SECOND_CATEGORY, "source202", "value202")
private val item203 = InitialData(SECOND_CATEGORY, "source203", "value203")
private val secondCategoryItems = listOf(item201, item202, item203)
private val item301 = InitialData(THIRD_CATEGORY, "source301", "value301")
private val item302 = InitialData(THIRD_CATEGORY, "source302", "value302")
private val item303 = InitialData(THIRD_CATEGORY, "source303", "value303")
private val thirdCategoryItems = listOf(item301, item302, item303)
private val items = listOf(item101, item102, item103, item201, item202, item203, item301, item302, item303)
@Before
override fun setUp() {
super.setUp()
for (item in items) {
addItem(item)
}
}
@Test
fun test_complex_logic() {
//0. Check initial data
checkStep0()
//1. Pass first category with corrects
checkStep1()
//2.Pass the second category all with incorrects
checkStep2()
//3. Pass the third one with 1 correct and 2 incorrects just by skipping the first and last one
checkStep3()
//4.Pass first category all with corrects again.
checkStep4()
//5. Pass second category all with corrects.
checkStep5()
//6. Pass third one with corrects.
checkStep6()
//7.Pass the first category with fails and skips for each one.
checkStep7()
//8. Pass the second category with skips for each item.
checkStep8()
//9. For the third category skip the first one, answer correct for the second item and then just leave it.
checkStep9()
// 10. Recreate the process and check all the data again.
checkStep10()
}
//region steps
private fun checkStep0() {
mainPage.learnButton.click()
checkCategory(0, "$FIRST_CATEGORY (3)", 0, 0)
checkCategory(1, "$SECOND_CATEGORY (3)", 0, 0)
checkCategory(2, "$THIRD_CATEGORY (3)", 0, 0)
checkCategoryDetails(0, FIRST_CATEGORY, firstCategoryItems, listOf(Pair(0, 0), Pair(0, 0), Pair(0, 0)))
checkCategoryDetails(1, SECOND_CATEGORY, secondCategoryItems, listOf(Pair(0, 0), Pair(0, 0), Pair(0, 0)))
checkCategoryDetails(2, THIRD_CATEGORY, thirdCategoryItems, listOf(Pair(0, 0), Pair(0, 0), Pair(0, 0)))
}
private fun checkStep1() {
studyCategory(0)
checkLearningPairStudyScreenData(item101, Pair(0, 0), "1/3")
passWithCorrect(item101)
checkLearningPairStudyScreenData(item102, Pair(0, 0), "2/3")
passWithCorrect(item102)
checkLearningPairStudyScreenData(item103, Pair(0, 0), "3/3")
passWithCorrect(item103)
closeResultsScreen(FIRST_CATEGORY, 3, 3)
checkLearningPairsListData(FIRST_CATEGORY, firstCategoryItems, listOf(Pair(1, 0), Pair(1, 0), Pair(1, 0)))
Espresso.pressBack()
checkCategory(0, "$FIRST_CATEGORY (3)", 3, 0)
checkCategory(1, "$SECOND_CATEGORY (3)", 0, 0)
checkCategory(2, "$THIRD_CATEGORY (3)", 0, 0)
checkCategoryDetails(0, FIRST_CATEGORY, firstCategoryItems, listOf(Pair(1, 0), Pair(1, 0), Pair(1, 0)))
checkCategoryDetails(1, SECOND_CATEGORY, secondCategoryItems, listOf(Pair(0, 0), Pair(0, 0), Pair(0, 0)))
checkCategoryDetails(2, THIRD_CATEGORY, thirdCategoryItems, listOf(Pair(0, 0), Pair(0, 0), Pair(0, 0)))
}
private fun checkStep2() {
studyCategory(1)
checkLearningPairStudyScreenData(item201, Pair(0, 0), "1/3")
inputIncorrect()
checkLearningPairStudyScreenData(item201, Pair(0, 1), "1/3")
skipItem()
checkLearningPairStudyScreenData(item202, Pair(0, 0), "2/3")
inputIncorrect()
checkLearningPairStudyScreenData(item202, Pair(0, 1), "2/3")
skipItem()
checkLearningPairStudyScreenData(item203, Pair(0, 0), "3/3")
inputIncorrect()
checkLearningPairStudyScreenData(item203, Pair(0, 1), "3/3")
skipItem()
closeResultsScreen(SECOND_CATEGORY, 0, 3)
checkLearningPairsListData(SECOND_CATEGORY, secondCategoryItems, listOf(Pair(0, 2), Pair(0, 2), Pair(0, 2)))
Espresso.pressBack()
checkCategory(0, "$FIRST_CATEGORY (3)", 3, 0)
checkCategory(1, "$SECOND_CATEGORY (3)", 0, 6)
checkCategory(2, "$THIRD_CATEGORY (3)", 0, 0)
checkCategoryDetails(0, FIRST_CATEGORY, firstCategoryItems, listOf(Pair(1, 0), Pair(1, 0), Pair(1, 0)))
checkCategoryDetails(1, SECOND_CATEGORY, secondCategoryItems, listOf(Pair(0, 2), Pair(0, 2), Pair(0, 2)))
checkCategoryDetails(2, THIRD_CATEGORY, thirdCategoryItems, listOf(Pair(0, 0), Pair(0, 0), Pair(0, 0)))
}
private fun checkStep3() {
studyCategory(2)
checkLearningPairStudyScreenData(item301, Pair(0, 0), "1/3")
skipItem()
checkLearningPairStudyScreenData(item302, Pair(0, 0), "2/3")
passWithCorrect(item302)
checkLearningPairStudyScreenData(item303, Pair(0, 0), "3/3")
skipItem()
closeResultsScreen(THIRD_CATEGORY, 1, 3)
checkLearningPairsListData(THIRD_CATEGORY, thirdCategoryItems, listOf(Pair(0, 1), Pair(1, 0), Pair(0, 1)))
Espresso.pressBack()
checkCategory(0, "$FIRST_CATEGORY (3)", 3, 0)
checkCategory(1, "$SECOND_CATEGORY (3)", 0, 6)
checkCategory(2, "$THIRD_CATEGORY (3)", 1, 2)
checkCategoryDetails(0, FIRST_CATEGORY, firstCategoryItems, listOf(Pair(1, 0), Pair(1, 0), Pair(1, 0)))
checkCategoryDetails(1, SECOND_CATEGORY, secondCategoryItems, listOf(Pair(0, 2), Pair(0, 2), Pair(0, 2)))
checkCategoryDetails(2, THIRD_CATEGORY, thirdCategoryItems, listOf(Pair(0, 1), Pair(1, 0), Pair(0, 1)))
}
private fun checkStep4() {
studyCategory(0)
checkLearningPairStudyScreenData(item101, Pair(1, 0), "1/3")
passWithCorrect(item101)
checkLearningPairStudyScreenData(item102, Pair(1, 0), "2/3")
passWithCorrect(item102)
checkLearningPairStudyScreenData(item103, Pair(1, 0), "3/3")
passWithCorrect(item103)
closeResultsScreen(FIRST_CATEGORY, 3, 3)
checkLearningPairsListData(FIRST_CATEGORY, firstCategoryItems, listOf(Pair(2, 0), Pair(2, 0), Pair(2, 0)))
Espresso.pressBack()
checkCategory(0, "$FIRST_CATEGORY (3)", 6, 0)
checkCategory(1, "$SECOND_CATEGORY (3)", 0, 6)
checkCategory(2, "$THIRD_CATEGORY (3)", 1, 2)
checkCategoryDetails(0, FIRST_CATEGORY, firstCategoryItems, listOf(Pair(2, 0), Pair(2, 0), Pair(2, 0)))
checkCategoryDetails(1, SECOND_CATEGORY, secondCategoryItems, listOf(Pair(0, 2), Pair(0, 2), Pair(0, 2)))
checkCategoryDetails(2, THIRD_CATEGORY, thirdCategoryItems, listOf(Pair(0, 1), Pair(1, 0), Pair(0, 1)))
}
private fun checkStep5() {
studyCategory(1)
checkLearningPairStudyScreenData(item201, Pair(0, 2), "1/3")
passWithCorrect(item201)
checkLearningPairStudyScreenData(item202, Pair(0, 2), "2/3")
passWithCorrect(item202)
checkLearningPairStudyScreenData(item203, Pair(0, 2), "3/3")
passWithCorrect(item203)
closeResultsScreen(SECOND_CATEGORY, 3, 3)
checkLearningPairsListData(SECOND_CATEGORY, secondCategoryItems, listOf(Pair(1, 2), Pair(1, 2), Pair(1, 2)))
Espresso.pressBack()
checkCategory(0, "$FIRST_CATEGORY (3)", 6, 0)
checkCategory(1, "$SECOND_CATEGORY (3)", 3, 6)
checkCategory(2, "$THIRD_CATEGORY (3)", 1, 2)
checkCategoryDetails(0, FIRST_CATEGORY, firstCategoryItems, listOf(Pair(2, 0), Pair(2, 0), Pair(2, 0)))
checkCategoryDetails(1, SECOND_CATEGORY, secondCategoryItems, listOf(Pair(1, 2), Pair(1, 2), Pair(1, 2)))
checkCategoryDetails(2, THIRD_CATEGORY, thirdCategoryItems, listOf(Pair(0, 1), Pair(1, 0), Pair(0, 1)))
}
private fun checkStep6() {
studyCategory(2)
checkLearningPairStudyScreenData(item301, Pair(0, 1), "1/3")
passWithCorrect(item301)
checkLearningPairStudyScreenData(item302, Pair(1, 0), "2/3")
passWithCorrect(item302)
checkLearningPairStudyScreenData(item303, Pair(0, 1), "3/3")
passWithCorrect(item303)
closeResultsScreen(THIRD_CATEGORY, 3, 3)
checkLearningPairsListData(THIRD_CATEGORY, thirdCategoryItems, listOf(Pair(1, 1), Pair(2, 0), Pair(1, 1)))
Espresso.pressBack()
checkCategory(0, "$FIRST_CATEGORY (3)", 6, 0)
checkCategory(1, "$SECOND_CATEGORY (3)", 3, 6)
checkCategory(2, "$THIRD_CATEGORY (3)", 4, 2)
checkCategoryDetails(0, FIRST_CATEGORY, firstCategoryItems, listOf(Pair(2, 0), Pair(2, 0), Pair(2, 0)))
checkCategoryDetails(1, SECOND_CATEGORY, secondCategoryItems, listOf(Pair(1, 2), Pair(1, 2), Pair(1, 2)))
checkCategoryDetails(2, THIRD_CATEGORY, thirdCategoryItems, listOf(Pair(1, 1), Pair(2, 0), Pair(1, 1)))
}
private fun checkStep7() {
studyCategory(0)
checkLearningPairStudyScreenData(item101, Pair(2, 0), "1/3")
inputIncorrect()
checkLearningPairStudyScreenData(item101, Pair(2, 1), "1/3")
skipItem()
checkLearningPairStudyScreenData(item102, Pair(2, 0), "2/3")
inputIncorrect()
checkLearningPairStudyScreenData(item102, Pair(2, 1), "2/3")
skipItem()
checkLearningPairStudyScreenData(item103, Pair(2, 0), "3/3")
inputIncorrect()
checkLearningPairStudyScreenData(item103, Pair(2, 1), "3/3")
skipItem()
closeResultsScreen(FIRST_CATEGORY, 0, 3)
checkLearningPairsListData(FIRST_CATEGORY, firstCategoryItems, listOf(Pair(2, 2), Pair(2, 2), Pair(2, 2)))
Espresso.pressBack()
checkCategory(0, "$FIRST_CATEGORY (3)", 6, 6)
checkCategory(1, "$SECOND_CATEGORY (3)", 3, 6)
checkCategory(2, "$THIRD_CATEGORY (3)", 4, 2)
checkCategoryDetails(0, FIRST_CATEGORY, firstCategoryItems, listOf(Pair(2, 2), Pair(2, 2), Pair(2, 2)))
checkCategoryDetails(1, SECOND_CATEGORY, secondCategoryItems, listOf(Pair(1, 2), Pair(1, 2), Pair(1, 2)))
checkCategoryDetails(2, THIRD_CATEGORY, thirdCategoryItems, listOf(Pair(1, 1), Pair(2, 0), Pair(1, 1)))
}
private fun checkStep8() {
studyCategory(1)
checkLearningPairStudyScreenData(item201, Pair(1, 2), "1/3")
skipItem()
checkLearningPairStudyScreenData(item202, Pair(1, 2), "2/3")
skipItem()
checkLearningPairStudyScreenData(item203, Pair(1, 2), "3/3")
skipItem()
closeResultsScreen(SECOND_CATEGORY, 0, 3)
checkLearningPairsListData(SECOND_CATEGORY, secondCategoryItems, listOf(Pair(1, 3), Pair(1, 3), Pair(1, 3)))
Espresso.pressBack()
checkCategory(0, "$FIRST_CATEGORY (3)", 6, 6)
checkCategory(1, "$SECOND_CATEGORY (3)", 3, 9)
checkCategory(2, "$THIRD_CATEGORY (3)", 4, 2)
checkCategoryDetails(0, FIRST_CATEGORY, firstCategoryItems, listOf(Pair(2, 2), Pair(2, 2), Pair(2, 2)))
checkCategoryDetails(1, SECOND_CATEGORY, secondCategoryItems, listOf(Pair(1, 3), Pair(1, 3), Pair(1, 3)))
checkCategoryDetails(2, THIRD_CATEGORY, thirdCategoryItems, listOf(Pair(1, 1), Pair(2, 0), Pair(1, 1)))
}
private fun checkStep9() {
studyCategory(2)
checkLearningPairStudyScreenData(item301, Pair(1, 1), "1/3")
skipItem()
checkLearningPairStudyScreenData(item302, Pair(2, 0), "2/3")
passWithCorrect(item302)
checkLearningPairStudyScreenData(item303, Pair(1, 1), "3/3")
Espresso.pressBack()
confirmExitFromStudyScreen()
checkLearningPairsListData(THIRD_CATEGORY, thirdCategoryItems, listOf(Pair(1, 2), Pair(3, 0), Pair(1, 1)))
Espresso.pressBack()
checkCategory(0, "$FIRST_CATEGORY (3)", 6, 6)
checkCategory(1, "$SECOND_CATEGORY (3)", 3, 9)
checkCategory(2, "$THIRD_CATEGORY (3)", 5, 3)
checkCategoryDetails(0, FIRST_CATEGORY, firstCategoryItems, listOf(Pair(2, 2), Pair(2, 2), Pair(2, 2)))
checkCategoryDetails(1, SECOND_CATEGORY, secondCategoryItems, listOf(Pair(1, 3), Pair(1, 3), Pair(1, 3)))
checkCategoryDetails(2, THIRD_CATEGORY, thirdCategoryItems, listOf(Pair(1, 2), Pair(3, 0), Pair(1, 1)))
}
private fun checkStep10() {
goHomeAndReturnToApp()
checkCategory(0, "$FIRST_CATEGORY (3)", 6, 6)
checkCategory(1, "$SECOND_CATEGORY (3)", 3, 9)
checkCategory(2, "$THIRD_CATEGORY (3)", 5, 3)
checkCategoryDetails(0, FIRST_CATEGORY, firstCategoryItems, listOf(Pair(2, 2), Pair(2, 2), Pair(2, 2)))
checkCategoryDetails(1, SECOND_CATEGORY, secondCategoryItems, listOf(Pair(1, 3), Pair(1, 3), Pair(1, 3)))
checkCategoryDetails(2, THIRD_CATEGORY, thirdCategoryItems, listOf(Pair(1, 2), Pair(3, 0), Pair(1, 1)))
}
//endregion
//region other methods
private fun confirmExitFromStudyScreen() = alertDialogPage.positiveButton.click()
private fun checkLearningPairsListData(
categoryName: String,
items: List<InitialData>,
answersPairs: List<Pair<Int, Int>>
) {
checkTitle(categoryName)
with(listPage) {
items.forEachIndexed { index, item ->
checkSourceTextAtPosition(index, item.source)
checkCorrectsCountAtPosition(index, answersPairs[index].first.toString())
checkIncorrectsCountAtPosition(index, answersPairs[index].second.toString())
}
}
}
private fun closeResultsScreen(categoryName: String, corrects: Int, total: Int) {
with(alertDialogPage) {
title.checkText(studyPage.resultsTitle)
message.checkText(studyPage.resultsBody(corrects, total))
positiveButton.click()
}
checkTitle(categoryName)
}
private fun checkLearningPairStudyScreenData(item: InitialData, answersPair: Pair<Int, Int>, positionText: String) {
checkTitle(item.category)
with(studyPage) {
position.checkText(positionText)
correctsCount.checkText(answersPair.first.toString())
incorrectsCount.checkText(answersPair.second.toString())
skipButton.checkViewIsVisible()
checkButton.checkViewIsVisible()
source.checkText(item.source)
translationField.checkText("")
}
}
private fun passWithCorrect(item: InitialData) = with(studyPage) {
translationField.typeText(item.translation)
checkButton.click()
}
private fun inputIncorrect() = with(studyPage) {
translationField.typeText("somethingWrong")
checkButton.click()
}
private fun skipItem() = studyPage.skipButton.click()
private fun checkCategoryDetails(
position: Int,
category: String,
items: List<InitialData>,
answersPairs: List<Pair<Int, Int>>
) {
listPage.recyclerViewId.clickRecyclerViewItemAtPosition(position)
checkTitle(category)
items.forEachIndexed { index, data ->
with(listPage) {
checkSourceTextAtPosition(index, data.source)
checkCorrectsCountAtPosition(index, answersPairs[index].first.toString())
checkIncorrectsCountAtPosition(index, answersPairs[index].second.toString())
}
}
Espresso.pressBack()
}
private fun studyCategory(position: Int) = listPage.clickStudyOnCategoryAtPosition(position)
private fun checkCategory(position: Int, name: String, corrects: Int, incorrects: Int) = with(listPage) {
checkCategoryTitleAtPosition(position, name)
checkCorrectsCountAtPosition(position, corrects.toString())
checkIncorrectsCountAtPosition(position, incorrects.toString())
}
private fun addItem(data: InitialData) {
mainPage.addButton.click()
with(addNewPairPage) {
addCategoryEditText.typeText(data.category)
sourceValueEditText.typeText(data.source)
translationValueEditText.typeText(data.translation)
saveButton.click()
}
}
//endregion
}
data class InitialData(val category: String, val source: String, val translation: String)
You can’t perform that action at this time.