mirror of https://github.com/iSoron/uhabits.git
Merge 7bd9d094b4
into 2b24759d6f
commit
1c18ddb31c
@ -0,0 +1,54 @@
|
||||
package org.isoron.uhabits
|
||||
|
||||
import io.qameta.allure.Feature
|
||||
import io.qameta.allure.junit4.DisplayName
|
||||
import org.isoron.uhabits.acceptance.steps.CommonSteps.launchApp
|
||||
import org.isoron.uhabits.pages.MainPage
|
||||
import org.isoron.uhabits.pages.NewHabitPage
|
||||
import org.junit.Test
|
||||
|
||||
@Feature("Habits smoke test")
|
||||
//@RunWith(AllureAndroidJUnit4::class)
|
||||
//@RunWith(AndroidJUnit4::class)
|
||||
class HabitsSmokeTest : BaseUserInterfaceTest() {
|
||||
|
||||
@Test
|
||||
@DisplayName("Create new habit")
|
||||
fun createNewHabit() {
|
||||
launchApp()
|
||||
MainPage.openNewHabitPage()
|
||||
NewHabitPage.fillDefaultHabit("Test Name", "Test Question")
|
||||
MainPage.checkHabitPresentOnScroller("Test Name")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Delete habit")
|
||||
fun deleteHabit() {
|
||||
launchApp()
|
||||
with(MainPage) {
|
||||
checkHabitPresentOnScroller("Wake up early")
|
||||
deleteHabit("Wake up early")
|
||||
checkHabitIsNotPresentOnScroller("Wake up early")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Hide completed habits")
|
||||
fun hideCompleted() {
|
||||
launchApp()
|
||||
with(MainPage) {
|
||||
hideCompleted()
|
||||
checkHabitIsNotPresentOnScroller("Track time")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Hide archived habits")
|
||||
fun hideArchived() {
|
||||
launchApp()
|
||||
with(MainPage) {
|
||||
makeArchived("Track time")
|
||||
checkHabitIsNotPresentOnScroller("Track time")
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
package org.isoron.uhabits.pages
|
||||
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.ViewInteraction
|
||||
import androidx.test.espresso.action.ViewActions
|
||||
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.matcher.ViewMatchers
|
||||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||
import io.qameta.allure.Step
|
||||
import org.hamcrest.CoreMatchers
|
||||
import org.hamcrest.Matchers.allOf
|
||||
import org.hamcrest.Matchers.endsWith
|
||||
import org.isoron.uhabits.BaseUserInterfaceTest.Companion.device
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.acceptance.steps.CommonSteps.scrollToText
|
||||
|
||||
object MainPage {
|
||||
|
||||
private val addHabitButton by lazy { onView(withId(R.id.actionCreateHabit)) }
|
||||
private val sortMenuButton by lazy { onView(withId(R.id.action_filter)) }
|
||||
private val moreMenuButton by lazy {
|
||||
onView(
|
||||
CoreMatchers.allOf(
|
||||
ViewMatchers.withContentDescription("More options"),
|
||||
ViewMatchers.withParent(
|
||||
ViewMatchers.withParent(
|
||||
ViewMatchers.withClassName(
|
||||
endsWith("Toolbar")
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// More menu window
|
||||
private val deleteMenuButton by lazy { onView(withText(R.string.delete)) }
|
||||
private val yesDeleteMenuButton by lazy { onView(withText("Yes")) }
|
||||
|
||||
// Sort window
|
||||
private val hideCompleted by lazy { onView(withText(R.string.hide_completed)) }
|
||||
private val hideArchived by lazy { onView(withText(R.string.hide_archived)) }
|
||||
private val archive by lazy { onView(withText(R.string.archive)) }
|
||||
private val sort by lazy { onView(withText("Sort")) }
|
||||
|
||||
private val habitsScrollerRow =
|
||||
Getter<String, ViewInteraction> { habitName ->
|
||||
onView(
|
||||
allOf(
|
||||
ViewMatchers.hasDescendant(withText(habitName)),
|
||||
ViewMatchers.withClassName(endsWith("HabitCardView"))
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun interface Getter<V, R> {
|
||||
operator fun get(value: V): R
|
||||
}
|
||||
|
||||
private val habitTypeWindow by lazy { onView(withText(R.string.yes_or_no_example)) }
|
||||
private val habitTypeYesOnNo by lazy { onView(withText("Yes or No")) }
|
||||
|
||||
@Step("Open New Habit Page")
|
||||
fun openNewHabitPage() {
|
||||
addHabitButton.perform(ViewActions.click())
|
||||
habitTypeWindow.check(matches(isDisplayed()))
|
||||
habitTypeYesOnNo.perform(ViewActions.click())
|
||||
}
|
||||
|
||||
@Step("Hide completed")
|
||||
fun hideCompleted() {
|
||||
sortMenuButton.perform(ViewActions.click())
|
||||
hideCompleted.perform(ViewActions.click())
|
||||
}
|
||||
|
||||
@Step("Hide archived")
|
||||
fun hideArchived() {
|
||||
sortMenuButton.perform(ViewActions.click())
|
||||
hideArchived.perform(ViewActions.click())
|
||||
}
|
||||
|
||||
@Step("Change sort on {sortText}")
|
||||
fun changeSort(sortText: String) {
|
||||
sortMenuButton.perform(ViewActions.click())
|
||||
sort.perform(ViewActions.click())
|
||||
onView(withText(sortText)).perform(ViewActions.click())
|
||||
}
|
||||
|
||||
@Step("Delete habit with name {habitName}")
|
||||
fun deleteHabit(habitName: String) {
|
||||
scrollToText(habitName)
|
||||
onView(withText(habitName)).perform(ViewActions.longClick())
|
||||
device.waitForIdle()
|
||||
moreMenuButton.perform(ViewActions.click())
|
||||
deleteMenuButton.perform(ViewActions.click())
|
||||
yesDeleteMenuButton.perform(ViewActions.click())
|
||||
}
|
||||
|
||||
@Step("Check habit with name {habitName} present on scroller")
|
||||
fun checkHabitPresentOnScroller(habitName: String) {
|
||||
scrollToText(habitName)
|
||||
habitsScrollerRow[habitName].check(matches(isDisplayed()))
|
||||
}
|
||||
|
||||
@Step("Check habit with name {habitName} is not present on scroller")
|
||||
fun checkHabitIsNotPresentOnScroller(habitName: String) {
|
||||
onView(withText(habitName)).check(doesNotExist())
|
||||
}
|
||||
|
||||
@Step("Check habit with name {habitName} is not present on scroller")
|
||||
fun makeArchived(habitName: String) {
|
||||
scrollToText(habitName)
|
||||
onView(withText(habitName)).perform(ViewActions.longClick())
|
||||
device.waitForIdle()
|
||||
moreMenuButton.perform(ViewActions.click())
|
||||
archive.perform(ViewActions.click())
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package org.isoron.uhabits.pages
|
||||
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.action.ViewActions
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
import org.isoron.uhabits.R
|
||||
|
||||
object NewHabitPage {
|
||||
|
||||
private val nameInput by lazy { onView(withId(R.id.nameInput)) }
|
||||
private val questionInput by lazy { onView(withId(R.id.questionInput)) }
|
||||
private val frequencyPicker by lazy { onView(withId(R.id.boolean_frequency_picker)) }
|
||||
private val notesInput by lazy { onView(withId(R.id.notesInput)) }
|
||||
private val colorButton by lazy { onView(withId(R.id.colorButton)) }
|
||||
|
||||
private val save by lazy { onView(withId(R.id.buttonSave)) }
|
||||
|
||||
fun fillDefaultHabit(name: String, question: String, note: String? = null) {
|
||||
nameInput.perform(
|
||||
ViewActions.clearText(),
|
||||
ViewActions.typeText(name),
|
||||
ViewActions.closeSoftKeyboard()
|
||||
)
|
||||
|
||||
questionInput.perform(
|
||||
ViewActions.clearText(),
|
||||
ViewActions.typeText(question),
|
||||
ViewActions.closeSoftKeyboard()
|
||||
)
|
||||
|
||||
note?.let {
|
||||
notesInput.perform(
|
||||
ViewActions.clearText(),
|
||||
ViewActions.typeText(it),
|
||||
ViewActions.closeSoftKeyboard()
|
||||
)
|
||||
}
|
||||
|
||||
save.perform(ViewActions.click())
|
||||
}
|
||||
}
|
Loading…
Reference in new issue