FileDisplayActivityIT.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.lib.resources.files.CreateFolderRemoteOperation;
  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.ui.activity.FileDisplayActivity;
  34. import com.owncloud.android.ui.events.SearchEvent;
  35. import org.greenrobot.eventbus.EventBus;
  36. import org.junit.Assert;
  37. import org.junit.Rule;
  38. import org.junit.Test;
  39. import androidx.test.espresso.contrib.DrawerActions;
  40. import androidx.test.espresso.intent.rule.IntentsTestRule;
  41. import androidx.test.rule.GrantPermissionRule;
  42. import static androidx.test.espresso.Espresso.onView;
  43. import static androidx.test.espresso.action.ViewActions.click;
  44. import static androidx.test.espresso.matcher.ViewMatchers.withId;
  45. import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
  46. import static junit.framework.TestCase.assertTrue;
  47. public class FileDisplayActivityIT extends AbstractIT {
  48. @Rule public IntentsTestRule<FileDisplayActivity> activityRule = new IntentsTestRule<>(FileDisplayActivity.class,
  49. true,
  50. false);
  51. @Rule
  52. public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
  53. Manifest.permission.WRITE_EXTERNAL_STORAGE);
  54. @Test
  55. public void open() throws InterruptedException {
  56. Activity sut = activityRule.launchActivity(null);
  57. Thread.sleep(3000);
  58. Screenshot.snapActivity(sut).record();
  59. }
  60. @Test
  61. public void drawer() {
  62. Activity sut = activityRule.launchActivity(null);
  63. onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
  64. Screenshot.snapActivity(sut).record();
  65. }
  66. @Test
  67. public void showShares() {
  68. assertTrue(new CreateFolderRemoteOperation("/shareToAdmin/", false).execute(client).isSuccess());
  69. assertTrue(new CreateFolderRemoteOperation("/shareToGroup/", true).execute(client).isSuccess());
  70. assertTrue(new CreateFolderRemoteOperation("/shareViaLink/", true).execute(client).isSuccess());
  71. assertTrue(new CreateFolderRemoteOperation("/noShare/", true).execute(client).isSuccess());
  72. // share folder to user "admin"
  73. assertTrue(new CreateShareRemoteOperation("/shareToAdmin/",
  74. ShareType.USER,
  75. "admin",
  76. false,
  77. "",
  78. OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER)
  79. .execute(client).isSuccess());
  80. // share folder via public link
  81. assertTrue(new CreateShareRemoteOperation("/shareViaLink/",
  82. ShareType.PUBLIC_LINK,
  83. "",
  84. true,
  85. "",
  86. OCShare.READ_PERMISSION_FLAG)
  87. .execute(client).isSuccess());
  88. // share folder to group
  89. Assert.assertTrue(new CreateShareRemoteOperation("/shareToGroup/",
  90. ShareType.GROUP,
  91. "users",
  92. false,
  93. "",
  94. OCShare.DEFAULT_PERMISSION)
  95. .execute(client).isSuccess());
  96. Activity sut = activityRule.launchActivity(null);
  97. getInstrumentation().waitForIdleSync();
  98. EventBus.getDefault().post(new SearchEvent("",
  99. SearchRemoteOperation.SearchType.SHARED_FILTER));
  100. getInstrumentation().waitForIdleSync();
  101. Screenshot.snapActivity(sut).record();
  102. }
  103. @Test
  104. public void showAccounts() {
  105. Activity sut = activityRule.launchActivity(null);
  106. onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
  107. onView(withId(R.id.drawer_active_user)).perform(click());
  108. Screenshot.snapActivity(sut).record();
  109. }
  110. }