FileDisplayActivityScreenshotIT.kt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Nextcloud - Android Client
  3. *
  4. * SPDX-FileCopyrightText: 2019 Tobias Kaminsky <tobias@kaminsky.me>
  5. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH
  6. * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
  7. */
  8. package com.nextcloud.client
  9. import android.Manifest
  10. import androidx.test.espresso.Espresso
  11. import androidx.test.espresso.contrib.DrawerActions
  12. import androidx.test.espresso.contrib.NavigationViewActions
  13. import androidx.test.espresso.intent.rule.IntentsTestRule
  14. import androidx.test.espresso.matcher.ViewMatchers
  15. import androidx.test.rule.GrantPermissionRule
  16. import com.owncloud.android.AbstractIT
  17. import com.owncloud.android.R
  18. import com.owncloud.android.lib.common.utils.Log_OC
  19. import com.owncloud.android.ui.activity.FileDisplayActivity
  20. import com.owncloud.android.utils.ScreenshotTest
  21. import org.junit.Assert
  22. import org.junit.Rule
  23. import org.junit.Test
  24. class FileDisplayActivityScreenshotIT : AbstractIT() {
  25. @get:Rule
  26. val activityRule = IntentsTestRule(
  27. FileDisplayActivity::class.java,
  28. true,
  29. false
  30. )
  31. @get:Rule
  32. val permissionRule: GrantPermissionRule = GrantPermissionRule.grant(
  33. Manifest.permission.WRITE_EXTERNAL_STORAGE
  34. )
  35. companion object {
  36. private const val TAG = "FileDisplayActivityScreenshotIT"
  37. }
  38. @Test
  39. @ScreenshotTest
  40. fun open() {
  41. try {
  42. val sut = activityRule.launchActivity(null)
  43. shortSleep()
  44. sut.runOnUiThread {
  45. sut.listOfFilesFragment!!.setFabEnabled(false)
  46. sut.resetScrolling(true)
  47. sut.listOfFilesFragment!!.setEmptyListLoadingMessage()
  48. sut.listOfFilesFragment!!.isLoading = false
  49. }
  50. shortSleep()
  51. waitForIdleSync()
  52. screenshot(sut)
  53. } catch (e: SecurityException) {
  54. Log_OC.e(TAG, "Error caught at open $e")
  55. }
  56. }
  57. @Test
  58. @ScreenshotTest
  59. fun showMediaThenAllFiles() {
  60. try {
  61. val fileDisplayActivity = activityRule.launchActivity(null)
  62. val sut = fileDisplayActivity.listOfFilesFragment
  63. Assert.assertNotNull(sut)
  64. sut!!.setFabEnabled(false)
  65. sut.setEmptyListLoadingMessage()
  66. sut.isLoading = false
  67. // open drawer
  68. Espresso.onView(ViewMatchers.withId(R.id.drawer_layout)).perform(DrawerActions.open())
  69. // click "all files"
  70. Espresso.onView(ViewMatchers.withId(R.id.nav_view))
  71. .perform(NavigationViewActions.navigateTo(R.id.nav_gallery))
  72. // wait
  73. shortSleep()
  74. // click "all files"
  75. Espresso.onView(ViewMatchers.withId(R.id.drawer_layout)).perform(DrawerActions.open())
  76. Espresso.onView(ViewMatchers.withId(R.id.nav_view))
  77. .perform(NavigationViewActions.navigateTo(R.id.nav_all_files))
  78. // then compare screenshot
  79. shortSleep()
  80. sut.setFabEnabled(false)
  81. sut.setEmptyListLoadingMessage()
  82. sut.isLoading = false
  83. shortSleep()
  84. screenshot(fileDisplayActivity)
  85. } catch (e: SecurityException) {
  86. Log_OC.e(TAG, "Error caught at open $e")
  87. }
  88. }
  89. @Test
  90. @ScreenshotTest
  91. fun drawer() {
  92. try {
  93. val sut = activityRule.launchActivity(null)
  94. Espresso.onView(ViewMatchers.withId(R.id.drawer_layout)).perform(DrawerActions.open())
  95. shortSleep()
  96. sut.runOnUiThread {
  97. sut.hideInfoBox()
  98. sut.resetScrolling(true)
  99. sut.listOfFilesFragment!!.setFabEnabled(false)
  100. sut.listOfFilesFragment!!.setEmptyListLoadingMessage()
  101. sut.listOfFilesFragment!!.isLoading = false
  102. }
  103. shortSleep()
  104. waitForIdleSync()
  105. screenshot(sut)
  106. } catch (e: SecurityException) {
  107. Log_OC.e(TAG, "Error caught at open $e")
  108. }
  109. }
  110. }