FileDisplayActivityIT.kt 9.6 KB

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