FileDisplayActivityIT.java 7.4 KB

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