FileDisplayActivityIT.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 android.app.Activity;
  25. import com.facebook.testing.screenshot.Screenshot;
  26. import com.owncloud.android.AbstractIT;
  27. import com.owncloud.android.R;
  28. import com.owncloud.android.datamodel.OCFile;
  29. import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation;
  30. import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;
  31. import com.owncloud.android.lib.resources.files.SearchRemoteOperation;
  32. import com.owncloud.android.lib.resources.shares.CreateShareRemoteOperation;
  33. import com.owncloud.android.lib.resources.shares.OCShare;
  34. import com.owncloud.android.lib.resources.shares.ShareType;
  35. import com.owncloud.android.operations.CreateFolderOperation;
  36. import com.owncloud.android.ui.activity.FileDisplayActivity;
  37. import com.owncloud.android.ui.events.SearchEvent;
  38. import com.owncloud.android.utils.ScreenshotTest;
  39. import org.greenrobot.eventbus.EventBus;
  40. import org.junit.Assert;
  41. import org.junit.Rule;
  42. import org.junit.Test;
  43. import androidx.test.espresso.contrib.DrawerActions;
  44. import androidx.test.espresso.contrib.NavigationViewActions;
  45. import androidx.test.espresso.intent.rule.IntentsTestRule;
  46. import androidx.test.rule.GrantPermissionRule;
  47. import static androidx.test.espresso.Espresso.onView;
  48. import static androidx.test.espresso.action.ViewActions.click;
  49. import static androidx.test.espresso.matcher.ViewMatchers.withId;
  50. import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
  51. import static junit.framework.TestCase.assertEquals;
  52. import static junit.framework.TestCase.assertTrue;
  53. public class FileDisplayActivityIT extends AbstractIT {
  54. @Rule public IntentsTestRule<FileDisplayActivity> activityRule = new IntentsTestRule<>(FileDisplayActivity.class,
  55. true,
  56. false);
  57. @Rule
  58. public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
  59. Manifest.permission.WRITE_EXTERNAL_STORAGE);
  60. @Test
  61. @ScreenshotTest
  62. public void open() {
  63. Activity sut = activityRule.launchActivity(null);
  64. shortSleep();
  65. Screenshot.snapActivity(sut).record();
  66. }
  67. @Test
  68. @ScreenshotTest
  69. public void drawer() {
  70. Activity sut = activityRule.launchActivity(null);
  71. onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
  72. waitForIdleSync();
  73. Screenshot.snapActivity(sut).record();
  74. }
  75. @Test
  76. @ScreenshotTest
  77. public void showShares() {
  78. assertTrue(new ExistenceCheckRemoteOperation("/shareToAdmin/", true).execute(client).isSuccess());
  79. assertTrue(new CreateFolderRemoteOperation("/shareToAdmin/", true).execute(client).isSuccess());
  80. assertTrue(new CreateFolderRemoteOperation("/shareToGroup/", true).execute(client).isSuccess());
  81. assertTrue(new CreateFolderRemoteOperation("/shareViaLink/", true).execute(client).isSuccess());
  82. assertTrue(new CreateFolderRemoteOperation("/noShare/", true).execute(client).isSuccess());
  83. // assertTrue(new CreateFolderRemoteOperation("/shareToCircle/", true).execute(client).isSuccess());
  84. // share folder to user "admin"
  85. assertTrue(new CreateShareRemoteOperation("/shareToAdmin/",
  86. ShareType.USER,
  87. "admin",
  88. false,
  89. "",
  90. OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER)
  91. .execute(client).isSuccess());
  92. // share folder via public link
  93. assertTrue(new CreateShareRemoteOperation("/shareViaLink/",
  94. ShareType.PUBLIC_LINK,
  95. "",
  96. true,
  97. "",
  98. OCShare.READ_PERMISSION_FLAG)
  99. .execute(client).isSuccess());
  100. // share folder to group
  101. Assert.assertTrue(new CreateShareRemoteOperation("/shareToGroup/",
  102. ShareType.GROUP,
  103. "users",
  104. false,
  105. "",
  106. OCShare.DEFAULT_PERMISSION)
  107. .execute(client).isSuccess());
  108. // share folder to circle
  109. // get share
  110. // RemoteOperationResult searchResult = new GetShareesRemoteOperation("publicCircle", 1, 50).execute(client);
  111. // assertTrue(searchResult.getLogMessage(), searchResult.isSuccess());
  112. //
  113. // JSONObject resultJson = (JSONObject) searchResult.getData().get(0);
  114. // String circleId = resultJson.getJSONObject("value").getString("shareWith");
  115. //
  116. // assertTrue(new CreateShareRemoteOperation("/shareToCircle/",
  117. // ShareType.CIRCLE,
  118. // circleId,
  119. // false,
  120. // "",
  121. // OCShare.DEFAULT_PERMISSION)
  122. // .execute(client).isSuccess());
  123. Activity sut = activityRule.launchActivity(null);
  124. getInstrumentation().waitForIdleSync();
  125. EventBus.getDefault().post(new SearchEvent("", SearchRemoteOperation.SearchType.SHARED_FILTER));
  126. getInstrumentation().waitForIdleSync();
  127. Screenshot.snapActivity(sut).record();
  128. }
  129. @Test
  130. @ScreenshotTest
  131. public void showAccounts() {
  132. Activity sut = activityRule.launchActivity(null);
  133. onView(withId(R.id.switch_account_button)).perform(click());
  134. Screenshot.snapActivity(sut).record();
  135. }
  136. @Test
  137. public void allFiles() {
  138. FileDisplayActivity sut = activityRule.launchActivity(null);
  139. // given test folder
  140. assertTrue(new CreateFolderOperation("/test/", account, targetContext)
  141. .execute(client, getStorageManager())
  142. .isSuccess());
  143. // navigate into it
  144. OCFile test = getStorageManager().getFileByPath("/test/");
  145. sut.setFile(test);
  146. sut.startSyncFolderOperation(test, false);
  147. assertEquals(getStorageManager().getFileByPath("/test/"), sut.getCurrentDir());
  148. // open drawer
  149. onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
  150. // click "all files"
  151. onView(withId(R.id.nav_view))
  152. .perform(NavigationViewActions.navigateTo(R.id.nav_all_files));
  153. // then should be in root again
  154. shortSleep();
  155. assertEquals(getStorageManager().getFileByPath("/"), sut.getCurrentDir());
  156. }
  157. }