TasksFragmentTest.kt 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package com.sduduzog.slimlauncher
  2. import android.view.KeyEvent
  3. import androidx.test.espresso.Espresso.onView
  4. import androidx.test.espresso.action.ViewActions.*
  5. import androidx.test.espresso.assertion.ViewAssertions.matches
  6. import androidx.test.espresso.matcher.RootMatchers
  7. import androidx.test.espresso.matcher.ViewMatchers.*
  8. import androidx.test.filters.LargeTest
  9. import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
  10. import androidx.test.rule.ActivityTestRule
  11. import org.hamcrest.CoreMatchers.allOf
  12. import org.hamcrest.Matchers
  13. import org.junit.Rule
  14. import org.junit.Test
  15. import org.junit.runner.RunWith
  16. @LargeTest
  17. @RunWith(AndroidJUnit4ClassRunner::class)
  18. class TasksFragmentTest {
  19. @Rule
  20. @JvmField
  21. var mActivityTestRule = ActivityTestRule(MainActivity::class.java)
  22. // private lateinit var sharedPreferences: SharedPreferences
  23. // @Before
  24. // fun clearPreferences() {
  25. // val context = InstrumentationRegistry.getInstrumentation().targetContext
  26. // sharedPreferences = context.getSharedPreferences(context.getString(R.string.prefs_settings), MODE_PRIVATE)
  27. // sharedPreferences.edit().clear().commit()
  28. // }
  29. @Test
  30. fun userCanAddTask() {
  31. val taskButton = onView(allOf(withText(R.string.home_fragment_tasks), isDisplayed()))
  32. taskButton.perform(click())
  33. val inputField = onView(allOf(withHint(R.string.tasks_fragment_enter_a_new_task), isDisplayed()))
  34. inputField.perform(typeText("Testing"))
  35. inputField.perform(pressKey(KeyEvent.KEYCODE_ENTER))
  36. val checkBox = onView(allOf(withText("Testing"), isDisplayed()))
  37. checkBox.check(matches(isNotChecked()))
  38. }
  39. @Test
  40. fun isStartButtonShown() {
  41. val button = onView(allOf(withText(R.string.setup_button_start)))
  42. button.check(matches(isDisplayed()))
  43. }
  44. @Test
  45. fun noAppsSelected() {
  46. val startButton = onView(allOf(withText(R.string.setup_button_start)))
  47. startButton.perform(click())
  48. val appCompatButton2 = onView(
  49. allOf(withText("DONE")))
  50. appCompatButton2.perform(scrollTo(), click())
  51. onView(withText(R.string.no_app_selected_toast_msg)).inRoot(
  52. RootMatchers.withDecorView(Matchers.not(Matchers.`is`(mActivityTestRule.activity.window.decorView))))
  53. .check(matches(isDisplayed()))
  54. }
  55. }