Write some UI tests for NotificationsActivity
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
parent
3bba95365c
commit
76c20b22db
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
@ -8,13 +8,14 @@ if [ $# -lt 2 ]; then
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sed -i s'#<bool name="is_beta">false</bool>#<bool name="is_beta">true</bool>#'g src/main/res/values/setup.xml
|
|
||||||
|
|
||||||
emulator -writable-system -avd uiComparison -no-snapshot -gpu swiftshader_indirect -no-audio -skin 500x833 &
|
|
||||||
|
|
||||||
cd src/androidTest/java
|
cd src/androidTest/java
|
||||||
|
|
||||||
class=$(find | grep $2 | grep java | head -n1|sed s'/\//\./'g | sed s'#^\.\.##' | sed s'#\.java##')
|
class=$(find | grep $2 | grep -E "java$|kt$" | head -n1|sed s'/\//\./'g | sed s'#^\.\.##' | sed s'#\.java##'| sed s'#\.kt##')
|
||||||
|
|
||||||
|
if [[ -z $class ]]; then
|
||||||
|
echo "Class not found!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
cd ../../../
|
cd ../../../
|
||||||
|
|
||||||
@ -28,6 +29,12 @@ if [ -e $3 ] ; then
|
|||||||
method=""
|
method=""
|
||||||
else
|
else
|
||||||
method="#$3"
|
method="#$3"
|
||||||
|
|
||||||
|
# check if method exists
|
||||||
|
if [[ $(grep -c $3 $(find | grep $2 | grep -E "java$|kt$" | head -n1)) -eq 0 ]]; then
|
||||||
|
echo "Method not found!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
./gradlew gplayDebugExecuteScreenshotTests $record \
|
./gradlew gplayDebugExecuteScreenshotTests $record \
|
||||||
|
@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Nextcloud Android client application
|
||||||
|
*
|
||||||
|
* @author Tobias Kaminsky
|
||||||
|
* Copyright (C) 2020 Tobias Kaminsky
|
||||||
|
* Copyright (C) 2020 Nextcloud GmbH
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.owncloud.android.ui.activity
|
||||||
|
|
||||||
|
import androidx.test.espresso.intent.rule.IntentsTestRule
|
||||||
|
import com.facebook.testing.screenshot.Screenshot
|
||||||
|
import com.owncloud.android.AbstractIT
|
||||||
|
import com.owncloud.android.lib.resources.notifications.models.Action
|
||||||
|
import com.owncloud.android.lib.resources.notifications.models.Notification
|
||||||
|
import com.owncloud.android.lib.resources.notifications.models.RichObject
|
||||||
|
import com.owncloud.android.utils.ScreenshotTest
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import java.util.GregorianCalendar
|
||||||
|
|
||||||
|
class NotificationsActivityIT : AbstractIT() {
|
||||||
|
@get:Rule
|
||||||
|
var activityRule = IntentsTestRule(NotificationsActivity::class.java, true, false)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@ScreenshotTest
|
||||||
|
fun loading() {
|
||||||
|
val sut: NotificationsActivity = activityRule.launchActivity(null)
|
||||||
|
|
||||||
|
Screenshot.snapActivity(sut).record()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@ScreenshotTest
|
||||||
|
fun empty() {
|
||||||
|
val sut: NotificationsActivity = activityRule.launchActivity(null)
|
||||||
|
|
||||||
|
sut.runOnUiThread { sut.populateList(ArrayList<Notification>()) }
|
||||||
|
|
||||||
|
shortSleep()
|
||||||
|
|
||||||
|
Screenshot.snapActivity(sut).record()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@ScreenshotTest
|
||||||
|
fun showNotifications() {
|
||||||
|
val sut: NotificationsActivity = activityRule.launchActivity(null)
|
||||||
|
|
||||||
|
val date = GregorianCalendar()
|
||||||
|
date.set(110, 2, 2, 10, 20, 30)
|
||||||
|
|
||||||
|
val notifications = ArrayList<Notification>()
|
||||||
|
notifications.add(Notification(1,
|
||||||
|
"files",
|
||||||
|
"user",
|
||||||
|
date.time,
|
||||||
|
"objectType",
|
||||||
|
"objectId",
|
||||||
|
"App recommendation: Tasks",
|
||||||
|
"SubjectRich",
|
||||||
|
HashMap<String, RichObject>(),
|
||||||
|
"Sync tasks from various devices with your Nextcloud and edit them online.",
|
||||||
|
"MessageRich",
|
||||||
|
HashMap<String, RichObject>(),
|
||||||
|
"link",
|
||||||
|
"icon",
|
||||||
|
ArrayList<Action>()))
|
||||||
|
|
||||||
|
val actions = ArrayList<Action>()
|
||||||
|
actions.add(Action("Send usage", "link", "url", true))
|
||||||
|
actions.add(Action("Not now", "link", "url", false))
|
||||||
|
|
||||||
|
notifications.add(Notification(1,
|
||||||
|
"files",
|
||||||
|
"user",
|
||||||
|
date.time,
|
||||||
|
"objectType",
|
||||||
|
"objectId",
|
||||||
|
"Help improve Nextcloud",
|
||||||
|
"SubjectRich",
|
||||||
|
HashMap<String, RichObject>(),
|
||||||
|
"Do you want to help us to improve Nextcloud by providing some anonymize data about your setup and usage?",
|
||||||
|
"MessageRich",
|
||||||
|
HashMap<String, RichObject>(),
|
||||||
|
"link",
|
||||||
|
"icon",
|
||||||
|
actions))
|
||||||
|
|
||||||
|
sut.runOnUiThread { sut.populateList(notifications) }
|
||||||
|
|
||||||
|
shortSleep()
|
||||||
|
|
||||||
|
Screenshot.snapActivity(sut).record()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@ScreenshotTest
|
||||||
|
fun error() {
|
||||||
|
val sut: NotificationsActivity = activityRule.launchActivity(null)
|
||||||
|
|
||||||
|
shortSleep()
|
||||||
|
|
||||||
|
sut.runOnUiThread { sut.setEmptyContent("Error", "Error! Please try again later!") }
|
||||||
|
|
||||||
|
Screenshot.snapActivity(sut).record()
|
||||||
|
}
|
||||||
|
}
|
@ -60,6 +60,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
@ -249,8 +250,18 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
|||||||
fetchAndSetData();
|
fetchAndSetData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populateList(List<Notification> notifications) {
|
@VisibleForTesting
|
||||||
|
public void populateList(List<Notification> notifications) {
|
||||||
adapter.setNotificationItems(notifications);
|
adapter.setNotificationItems(notifications);
|
||||||
|
|
||||||
|
if (notifications.size() > 0) {
|
||||||
|
swipeEmptyListRefreshLayout.setVisibility(View.GONE);
|
||||||
|
swipeListRefreshLayout.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
setEmptyContent(noResultsHeadline, noResultsMessage);
|
||||||
|
swipeListRefreshLayout.setVisibility(View.GONE);
|
||||||
|
swipeEmptyListRefreshLayout.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchAndSetData() {
|
private void fetchAndSetData() {
|
||||||
@ -275,17 +286,7 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
|||||||
if (result.isSuccess() && result.getNotificationData() != null) {
|
if (result.isSuccess() && result.getNotificationData() != null) {
|
||||||
final List<Notification> notifications = result.getNotificationData();
|
final List<Notification> notifications = result.getNotificationData();
|
||||||
|
|
||||||
runOnUiThread(() -> {
|
runOnUiThread(() -> populateList(notifications));
|
||||||
populateList(notifications);
|
|
||||||
if (notifications.size() > 0) {
|
|
||||||
swipeEmptyListRefreshLayout.setVisibility(View.GONE);
|
|
||||||
swipeListRefreshLayout.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
setEmptyContent(noResultsHeadline, noResultsMessage);
|
|
||||||
swipeListRefreshLayout.setVisibility(View.GONE);
|
|
||||||
swipeEmptyListRefreshLayout.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
Log_OC.d(TAG, result.getLogMessage());
|
Log_OC.d(TAG, result.getLogMessage());
|
||||||
// show error
|
// show error
|
||||||
@ -344,7 +345,8 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
|||||||
emptyContentProgressBar.setVisibility(View.VISIBLE);
|
emptyContentProgressBar.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setEmptyContent(String headline, String message) {
|
@VisibleForTesting
|
||||||
|
public void setEmptyContent(String headline, String message) {
|
||||||
if (emptyContentContainer != null && emptyContentMessage != null) {
|
if (emptyContentContainer != null && emptyContentMessage != null) {
|
||||||
emptyContentHeadline.setText(headline);
|
emptyContentHeadline.setText(headline);
|
||||||
emptyContentMessage.setText(message);
|
emptyContentMessage.setText(message);
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
package com.owncloud.android.ui.adapter;
|
package com.owncloud.android.ui.adapter;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.ColorStateList;
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.graphics.drawable.PictureDrawable;
|
import android.graphics.drawable.PictureDrawable;
|
||||||
@ -154,7 +153,7 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
|
|||||||
|
|
||||||
Resources resources = notificationsActivity.getResources();
|
Resources resources = notificationsActivity.getResources();
|
||||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
params.setMargins(20, 0, 20, 0);
|
params.setMargins(20, 0, 20, 0);
|
||||||
|
|
||||||
for (Action action : notification.getActions()) {
|
for (Action action : notification.getActions()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user