FileDisplayActivityScreenshotIT.kt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. *
  3. * Nextcloud Android client application
  4. *
  5. * @author Tobias Kaminsky
  6. * Copyright (C) 2019 Tobias Kaminsky
  7. * Copyright (C) 2019 Nextcloud GmbH
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. package com.nextcloud.client
  23. import android.Manifest
  24. import androidx.test.espresso.Espresso
  25. import androidx.test.espresso.contrib.DrawerActions
  26. import androidx.test.espresso.contrib.NavigationViewActions
  27. import androidx.test.espresso.intent.rule.IntentsTestRule
  28. import androidx.test.espresso.matcher.ViewMatchers
  29. import androidx.test.rule.GrantPermissionRule
  30. import com.owncloud.android.AbstractIT
  31. import com.owncloud.android.R
  32. import com.owncloud.android.ui.activity.FileDisplayActivity
  33. import com.owncloud.android.utils.ScreenshotTest
  34. import org.junit.Assert
  35. import org.junit.Rule
  36. import org.junit.Test
  37. class FileDisplayActivityScreenshotIT : AbstractIT() {
  38. @get:Rule
  39. val activityRule = IntentsTestRule(
  40. FileDisplayActivity::class.java,
  41. true,
  42. false
  43. )
  44. @get:Rule
  45. val permissionRule = GrantPermissionRule.grant(
  46. Manifest.permission.WRITE_EXTERNAL_STORAGE
  47. )
  48. @Test
  49. @ScreenshotTest
  50. fun open() {
  51. val sut = activityRule.launchActivity(null)
  52. shortSleep()
  53. sut.runOnUiThread {
  54. sut.listOfFilesFragment!!.setFabEnabled(false)
  55. sut.resetScrolling()
  56. sut.listOfFilesFragment!!.setEmptyListLoadingMessage()
  57. sut.listOfFilesFragment!!.isLoading = false
  58. }
  59. shortSleep()
  60. waitForIdleSync()
  61. screenshot(sut)
  62. }
  63. @Test
  64. @ScreenshotTest
  65. fun showMediaThenAllFiles() {
  66. val fileDisplayActivity = activityRule.launchActivity(null)
  67. val sut = fileDisplayActivity.listOfFilesFragment
  68. Assert.assertNotNull(sut)
  69. sut!!.setFabEnabled(false)
  70. sut.setEmptyListLoadingMessage()
  71. sut.isLoading = false
  72. // open drawer
  73. Espresso.onView(ViewMatchers.withId(R.id.drawer_layout)).perform(DrawerActions.open())
  74. // click "all files"
  75. Espresso.onView(ViewMatchers.withId(R.id.nav_view))
  76. .perform(NavigationViewActions.navigateTo(R.id.nav_gallery))
  77. // wait
  78. shortSleep()
  79. // click "all files"
  80. Espresso.onView(ViewMatchers.withId(R.id.drawer_layout)).perform(DrawerActions.open())
  81. Espresso.onView(ViewMatchers.withId(R.id.nav_view))
  82. .perform(NavigationViewActions.navigateTo(R.id.nav_all_files))
  83. // then compare screenshot
  84. shortSleep()
  85. sut.setFabEnabled(false)
  86. sut.setEmptyListLoadingMessage()
  87. sut.isLoading = false
  88. shortSleep()
  89. screenshot(fileDisplayActivity)
  90. }
  91. @Test
  92. @ScreenshotTest
  93. fun drawer() {
  94. val sut = activityRule.launchActivity(null)
  95. Espresso.onView(ViewMatchers.withId(R.id.drawer_layout)).perform(DrawerActions.open())
  96. shortSleep()
  97. sut.runOnUiThread {
  98. sut.hideInfoBox()
  99. sut.resetScrolling()
  100. sut.listOfFilesFragment!!.setFabEnabled(false)
  101. sut.listOfFilesFragment!!.setEmptyListLoadingMessage()
  102. sut.listOfFilesFragment!!.isLoading = false
  103. }
  104. shortSleep()
  105. waitForIdleSync()
  106. screenshot(sut)
  107. }
  108. }