Add EspressoIntroTests and EspressoNewHabbitTests

pull/2093/head
Бардашёва Юлия 8 months ago
parent 48a4b9ffa1
commit 528de1a05b

@ -0,0 +1,134 @@
package org.isoron.uhabits.esp
import android.util.Log
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isClickable
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import junit.framework.Assert.fail
import org.hamcrest.CoreMatchers.not
import org.isoron.uhabits.R
import org.isoron.uhabits.activities.intro.IntroActivity
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class EspressoIntroTests {
@get:Rule
val activityRule = ActivityScenarioRule(IntroActivity::class.java)
private fun checkIntroText(title: String, text: String) { //проверка текста
onView(withText(title)).check(matches(isDisplayed()))
onView(withText(text)).check(matches(isDisplayed()))
}
private fun checkVisibility(viewId: Int) { //проверка видимости
onView(withId(viewId)).check(matches(isDisplayed()))
}
private fun clickIntroStep(viewId: Int) { //клик
onView(withId(viewId)).perform(click())
}
@Test
fun testCheckFirstIntroElements() { //чек 1 интро
try {
checkIntroText("Welcome", "Loop Habit Tracker helps you create and maintain good habits.")
checkVisibility(R.id.bottom)
onView(withId(R.id.skip)).check(matches(isDisplayed())).check(matches(isClickable()))
onView(withId(R.id.next)).check(matches(isDisplayed())).check(matches(isClickable()))
onView(withId(R.id.back)).check(matches(not(isDisplayed())))
onView(withId(R.id.done)).check(matches(not(isDisplayed())))
} catch (e: Exception) {
Log.e("Тест первого интро не пройден", "Текст не совпадает или элементы не отображаются")
fail("Тест первого интро не пройден, текст не совпадает или элементы не отображаются")
}
}
@Test
fun testCheckSecondIntroElements() { //чек 2 интро
try {
clickIntroStep(R.id.next)
checkIntroText("Create some new habits", "Every day, after performing your habit, put a checkmark on the app.")
checkVisibility(R.id.bottom)
checkVisibility(R.id.skip)
} catch (e: Exception) {
Log.e("Тест второго интро не пройден", "Текст не совпадает или элементы не отображаются")
fail("Тест второго интро не пройден, текст не совпадает или элементы не отображаются")
}
}
@Test
fun testCheckThirdIntroElements() { //чек 3 интро
try {
clickIntroStep(R.id.next)
clickIntroStep(R.id.next)
checkIntroText("Track your progress", "Detailed graphs show you how your habits improved over time.")
clickIntroStep(R.id.done)
} catch (e: Exception) {
Log.e("Тест третьего интро не пройден", "Текст не совпадает или элементы не отображаются")
fail("Тест третьего интро не пройден, текст не совпадает или элементы не отображаются")
}
}
@Test
fun testFirstIntroRecreate() { //рекреейт 1 интро
try {
checkIntroText("Welcome", "Loop Habit Tracker helps you create and maintain good habits.")
checkVisibility(R.id.bottom)
onView(withId(R.id.skip)).check(matches(isDisplayed())).check(matches(isClickable()))
onView(withId(R.id.next)).check(matches(isDisplayed())).check(matches(isClickable()))
onView(withId(R.id.back)).check(matches(not(isDisplayed())))
onView(withId(R.id.done)).check(matches(not(isDisplayed())))
activityRule.scenario.recreate()
checkIntroText("Welcome", "Loop Habit Tracker helps you create and maintain good habits.")
checkVisibility(R.id.bottom)
onView(withId(R.id.skip)).check(matches(isDisplayed())).check(matches(isClickable()))
onView(withId(R.id.next)).check(matches(isDisplayed())).check(matches(isClickable()))
onView(withId(R.id.back)).check(matches(not(isDisplayed())))
onView(withId(R.id.done)).check(matches(not(isDisplayed())))
} catch (e: Exception) {
Log.e("Тест recreate не пройден", "Тест recreate первого интро не пройден ")
fail("Тест recreate первого интро не пройден")
}
}
@Test
fun testSecondIntroRecreate() { //рекреейт 2 интро
try {
clickIntroStep(R.id.next)
checkIntroText("Create some new habits", "Every day, after performing your habit, put a checkmark on the app.")
checkVisibility(R.id.bottom)
checkVisibility(R.id.skip)
activityRule.scenario.recreate()
checkIntroText("Create some new habits", "Every day, after performing your habit, put a checkmark on the app.")
checkVisibility(R.id.bottom)
checkVisibility(R.id.skip)
} catch (e: Exception) {
Log.e("Тест recreate не пройден", "Тест recreate второго интро не пройден")
fail("Тест recreate второго интро не пройден")
}
}
@Test
fun testThirdIntroRecreate() { //рекреейт 3 интро
try {
clickIntroStep(R.id.next)
clickIntroStep(R.id.next)
checkIntroText("Track your progress", "Detailed graphs show you how your habits improved over time.")
checkVisibility(R.id.done)
activityRule.scenario.recreate()
checkIntroText("Track your progress", "Detailed graphs show you how your habits improved over time.")
clickIntroStep(R.id.done)
} catch (e: Exception) {
Log.e("Тест recreate не пройден", "Тест recreate второго интро не пройден")
fail("Тест recreate второго интро не пройден")
}
}
}

@ -0,0 +1,122 @@
package org.isoron.uhabits.esp
import android.util.Log
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.typeText
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isClickable
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import junit.framework.Assert.fail
import org.isoron.uhabits.R
import org.isoron.uhabits.R.id.button
import org.isoron.uhabits.activities.habits.edit.EditHabitActivity
import org.junit.Rule
import org.junit.Test
class EspressoNewHabbitTests {
@get:Rule
val activityRule = ActivityScenarioRule(EditHabitActivity::class.java)
@Test
fun testCheckElemntsOnCreateHabbit() {
try {
onView(withId(R.id.toolbar)).check(matches(isDisplayed()))
onView(withText("Create habit")).check(matches(isDisplayed()))
onView(withText("Name")).check(matches(isDisplayed()))
onView(withText("Color")).check(matches(isDisplayed()))
onView(withId(R.id.colorButton)).check(matches(isDisplayed()))
onView(withText("Question")).check(matches(isDisplayed()))
onView(withId(R.id.text_frequency_picker)).check(matches(withText("Frequency")))
onView(withId(R.id.boolean_frequency_picker)).check(matches(isDisplayed()))
.check(matches(isClickable()))
onView(withId(R.id.numericalFrequencyPicker)).check(matches(withText("Every day")))
onView(withText("Reminder")).check(matches(isDisplayed()))
onView(withId(R.id.reminderTimePicker)).check(matches(withText("Off")))
onView(withText("Notes")).check(matches(isDisplayed()))
onView(withId(R.id.buttonSave)).check(matches(withText("SAVE"))).perform(click())
} catch (e: Exception) {
Log.e(
"Тест наличия элементов на экране создания привычки не пройден",
"Элементы или текст который они содержат не соответствует ожидаемому"
)
fail("Тест наличия элементов на экране создания привычки не пройден")
}
}
private fun checkAndTypeText(viewId: Int, text: String) { //чек элемента, инпут, чек инпута
onView(withId(viewId)).check(matches(isDisplayed())).perform(typeText(text))
onView(withId(viewId)).check(matches(withText(text)))
}
@Test
fun testCheckInputCreateHabbit() {
try {
checkAndTypeText(R.id.nameInput, "Run")
onView(withId(R.id.nameInput)).check(matches(withText("Run")))
checkAndTypeText(R.id.questionInput,"No")
onView(withId(R.id.questionInput)).check(matches(withText("No")))
onView(withId(R.id.text_frequency_picker)).check(matches(withText("Frequency")))
onView(withId(R.id.boolean_frequency_picker)).check(matches(isDisplayed())).perform(click())
onView(withText("Every day")).check(matches(isDisplayed()))
onView(withId(R.id.everyDayRadioButton)).check(matches(isDisplayed()))
onView(withId(R.id.everyXDaysRadioButton)).check(matches(isDisplayed())).perform(click())
onView(withText("Every")).check(matches(isDisplayed()))
onView(withId(R.id.everyXDaysTextView)).check(matches(isDisplayed()))
.perform(typeText("3"))
onView(withId(R.id.xTimesPerWeekTextView)).check(matches(isDisplayed()))
onView(withText("times per week")).check(matches(isDisplayed()))
onView(withId(R.id.xTimesPerMonthRadioButton)).check(matches(isDisplayed()))
onView(withText("times per month")).check(matches(isDisplayed()))
onView(withId(R.id.xTimesPerYDaysRadioButton)).check(matches(isDisplayed()))
onView(withText("times in")).check(matches(isDisplayed()))
onView(withId(R.id.xTimesPerYDaysYTextView)).check(matches(isDisplayed()))
onView(withId(android.R.id.button1)).check(matches(isDisplayed())).perform(click())
onView(withText("Every 33 days")).check(matches(isDisplayed()))
onView(withText("Reminder")).check(matches(isDisplayed()))
onView(withId(R.id.reminderTimePicker)).check(matches(withText("Off"))).perform(click())
onView(withId(R.id.time_display_background)).check(matches(isDisplayed()))
onView(withId(R.id.time_picker)).check(matches(isDisplayed()))
onView(withId(R.id.clear_button)).check(matches(isDisplayed()))
onView(withId(R.id.done_button)).check(matches(isDisplayed())).perform(click())
onView(withId(R.id.reminderTimePicker)).check(matches(withText("8:00 AM")))
onView(withId(R.id.reminderDatePicker)).check(matches(withText("Any day of the week")))
onView(withId(R.id.notesInput)).check(matches(isDisplayed()))
.perform(typeText("Some notes")).check(matches(withText("Some notes")))
onView(withId(R.id.notesInput)).check(matches(withText("Some notes")))
} catch (e: Exception) {
Log.e(
"Тест инпутов на экране создания привычки не пройден",
"Введенный в инпут текст не соответствует ожидаемому"
)
fail("Тест инпутов на экране создания привычки не пройден")
}
}
@Test
fun testElemntsCreateHabbitAfterRecreate() {
try {
onView(withId(R.id.nameInput)).check(matches(isDisplayed()))
.perform(typeText("Run"))
onView(withId(R.id.questionInput)).check(matches(isDisplayed()))
.perform(typeText("No"))
onView(withId(R.id.notesInput)).check(matches(isDisplayed()))
.perform(typeText("Some notes"))
activityRule.scenario.recreate()
onView(withId(R.id.nameInput)).check(matches(withText("Run")))
onView(withId(R.id.questionInput)).check(matches(withText("No")))
onView(withId(R.id.notesInput)).check(matches(withText("Some notes")))
} catch (e: Exception) {
Log.e(
"Тест recreate не пройден", "Введенный до recreate текст не сохраняется"
)
fail("Тест recreate не пройден, введенный до recreate текст не сохраняется")
}
}
}

@ -146,6 +146,7 @@
<LinearLayout style="@style/FormInnerBox"> <LinearLayout style="@style/FormInnerBox">
<TextView <TextView
style="@style/FormLabel" style="@style/FormLabel"
android:id="@+id/text_frequency_picker"
android:text="@string/frequency" /> android:text="@string/frequency" />
<TextView <TextView
style="@style/FormDropdown" style="@style/FormDropdown"

Loading…
Cancel
Save