FileDisplayActivityIT.kt 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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.app.Activity
  24. import androidx.test.espresso.Espresso
  25. import androidx.test.espresso.Espresso.onView
  26. import androidx.test.espresso.action.ViewActions.click
  27. import androidx.test.espresso.action.ViewActions.closeSoftKeyboard
  28. import androidx.test.espresso.assertion.ViewAssertions.matches
  29. import androidx.test.espresso.contrib.DrawerActions
  30. import androidx.test.espresso.contrib.NavigationViewActions
  31. import androidx.test.espresso.contrib.RecyclerViewActions
  32. import androidx.test.espresso.intent.rule.IntentsTestRule
  33. import androidx.test.espresso.matcher.ViewMatchers
  34. import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
  35. import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
  36. import androidx.test.espresso.matcher.ViewMatchers.withId
  37. import androidx.test.espresso.matcher.ViewMatchers.withText
  38. import androidx.test.platform.app.InstrumentationRegistry
  39. import com.nextcloud.test.RetryTestRule
  40. import com.owncloud.android.AbstractOnServerIT
  41. import com.owncloud.android.R
  42. import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation
  43. import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation
  44. import com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation
  45. import com.owncloud.android.lib.resources.shares.CreateShareRemoteOperation
  46. import com.owncloud.android.lib.resources.shares.OCShare
  47. import com.owncloud.android.lib.resources.shares.ShareType
  48. import com.owncloud.android.operations.CreateFolderOperation
  49. import com.owncloud.android.ui.activity.FileDisplayActivity
  50. import com.owncloud.android.ui.adapter.OCFileListItemViewHolder
  51. import org.junit.Assert
  52. import org.junit.Rule
  53. import org.junit.Test
  54. class FileDisplayActivityIT : AbstractOnServerIT() {
  55. @get:Rule
  56. val activityRule = IntentsTestRule(
  57. FileDisplayActivity::class.java,
  58. true,
  59. false
  60. )
  61. @get:Rule
  62. val retryRule = RetryTestRule() // showShares is flaky
  63. // @ScreenshotTest // todo run without real server
  64. @Test
  65. fun showShares() {
  66. Assert.assertTrue(ExistenceCheckRemoteOperation("/shareToAdmin/", true).execute(client).isSuccess)
  67. Assert.assertTrue(CreateFolderRemoteOperation("/shareToAdmin/", true).execute(client).isSuccess)
  68. Assert.assertTrue(CreateFolderRemoteOperation("/shareToGroup/", true).execute(client).isSuccess)
  69. Assert.assertTrue(CreateFolderRemoteOperation("/shareViaLink/", true).execute(client).isSuccess)
  70. Assert.assertTrue(CreateFolderRemoteOperation("/noShare/", true).execute(client).isSuccess)
  71. // assertTrue(new CreateFolderRemoteOperation("/shareToCircle/", true).execute(client).isSuccess());
  72. // share folder to user "admin"
  73. Assert.assertTrue(
  74. CreateShareRemoteOperation(
  75. "/shareToAdmin/",
  76. ShareType.USER,
  77. "admin",
  78. false,
  79. "",
  80. OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER
  81. ).execute(client).isSuccess
  82. )
  83. // share folder via public link
  84. Assert.assertTrue(
  85. CreateShareRemoteOperation(
  86. "/shareViaLink/",
  87. ShareType.PUBLIC_LINK,
  88. "",
  89. true,
  90. "",
  91. OCShare.READ_PERMISSION_FLAG
  92. ).execute(client).isSuccess
  93. )
  94. // share folder to group
  95. Assert.assertTrue(
  96. CreateShareRemoteOperation(
  97. "/shareToGroup/",
  98. ShareType.GROUP,
  99. "users",
  100. false,
  101. "",
  102. OCShare.NO_PERMISSION
  103. ).execute(client).isSuccess
  104. )
  105. // share folder to circle
  106. // get share
  107. // RemoteOperationResult searchResult = new GetShareesRemoteOperation("publicCircle", 1, 50).execute(client);
  108. // assertTrue(searchResult.getLogMessage(), searchResult.isSuccess());
  109. //
  110. // JSONObject resultJson = (JSONObject) searchResult.getData().get(0);
  111. // String circleId = resultJson.getJSONObject("value").getString("shareWith");
  112. //
  113. // assertTrue(new CreateShareRemoteOperation("/shareToCircle/",
  114. // ShareType.CIRCLE,
  115. // circleId,
  116. // false,
  117. // "",
  118. // OCShare.DEFAULT_PERMISSION)
  119. // .execute(client).isSuccess());
  120. val sut: Activity = activityRule.launchActivity(null)
  121. InstrumentationRegistry.getInstrumentation().waitForIdleSync()
  122. // open drawer
  123. onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())
  124. // click "shared"
  125. onView(withId(R.id.nav_view))
  126. .perform(NavigationViewActions.navigateTo(R.id.nav_shared))
  127. shortSleep()
  128. shortSleep()
  129. // screenshot(sut) // todo run without real server
  130. }
  131. @Test
  132. fun allFiles() {
  133. val sut = activityRule.launchActivity(null)
  134. // given test folder
  135. Assert.assertTrue(
  136. CreateFolderOperation("/test/", user, targetContext, storageManager)
  137. .execute(client)
  138. .isSuccess
  139. )
  140. // navigate into it
  141. val test = storageManager.getFileByPath("/test/")
  142. sut.file = test
  143. sut.startSyncFolderOperation(test, false)
  144. Assert.assertEquals(storageManager.getFileByPath("/test/"), sut.currentDir)
  145. // open drawer
  146. onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())
  147. // click "all files"
  148. onView(withId(R.id.nav_view))
  149. .perform(NavigationViewActions.navigateTo(R.id.nav_all_files))
  150. // then should be in root again
  151. shortSleep()
  152. Assert.assertEquals(storageManager.getFileByPath("/"), sut.currentDir)
  153. }
  154. @Test
  155. fun checkToolbarTitleOnNavigation() {
  156. // Create folder structure
  157. val topFolder = "folder1"
  158. val childFolder = "folder2"
  159. CreateFolderOperation("/$topFolder/", user, targetContext, storageManager)
  160. .execute(client)
  161. CreateFolderOperation("/$topFolder/$childFolder/", user, targetContext, storageManager)
  162. .execute(client)
  163. activityRule.launchActivity(null)
  164. shortSleep()
  165. // go into "foo"
  166. onView(withText(topFolder)).perform(click())
  167. shortSleep()
  168. // check title is right
  169. checkToolbarTitle(topFolder)
  170. // go into "bar"
  171. onView(withText(childFolder)).perform(click())
  172. shortSleep()
  173. // check title is right
  174. checkToolbarTitle(childFolder)
  175. // browse back up, we should be back in "foo"
  176. Espresso.pressBack()
  177. shortSleep()
  178. // check title is right
  179. checkToolbarTitle(topFolder)
  180. }
  181. private fun checkToolbarTitle(childFolder: String) {
  182. onView(withId(R.id.appbar)).check(
  183. matches(
  184. hasDescendant(
  185. withText(childFolder)
  186. )
  187. )
  188. )
  189. }
  190. @Test
  191. fun browseFavoriteAndBack() {
  192. // Create folder structure
  193. val topFolder = "folder1"
  194. CreateFolderOperation("/$topFolder/", user, targetContext, storageManager)
  195. .execute(client)
  196. ToggleFavoriteRemoteOperation(true, "/$topFolder/")
  197. .execute(client)
  198. val sut = activityRule.launchActivity(null)
  199. // navigate to favorites
  200. onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())
  201. onView(withId(R.id.nav_view))
  202. .perform(NavigationViewActions.navigateTo(R.id.nav_favorites))
  203. shortSleep()
  204. // check sort button is not shown, favorites are not sortable
  205. onView(withId(R.id.sort_button)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)))
  206. // browse into folder
  207. onView(withId(R.id.list_root))
  208. .perform(closeSoftKeyboard())
  209. .perform(
  210. RecyclerViewActions.actionOnItemAtPosition<OCFileListItemViewHolder>(
  211. 0,
  212. click()
  213. )
  214. )
  215. shortSleep()
  216. checkToolbarTitle(topFolder)
  217. // sort button should now be visible
  218. onView(withId(R.id.sort_button)).check(matches(ViewMatchers.isDisplayed()))
  219. // browse back, should be back to All Files
  220. Espresso.pressBack()
  221. checkToolbarTitle(sut.getString(R.string.app_name))
  222. onView(withId(R.id.sort_button)).check(matches(ViewMatchers.isDisplayed()))
  223. }
  224. @Test
  225. fun switchToGridView() {
  226. activityRule.launchActivity(null)
  227. Assert.assertTrue(
  228. CreateFolderOperation("/test/", user, targetContext, storageManager)
  229. .execute(client)
  230. .isSuccess
  231. )
  232. onView(withId(R.id.switch_grid_view_button)).perform(click())
  233. }
  234. @Test
  235. fun openAccountSwitcher() {
  236. activityRule.launchActivity(null)
  237. onView(withId(R.id.switch_account_button)).perform(click())
  238. }
  239. }