Compare commits
7 Commits
master
...
swap_usern
Author | SHA1 | Date | |
---|---|---|---|
|
53f5a151ba | ||
|
f6e4804c77 | ||
|
2f921cda14 | ||
|
1b05eeedea | ||
|
d67d57b68c | ||
|
9ef319bb7e | ||
|
4b6003816b |
@ -1,6 +1,7 @@
|
||||
package org.pixeldroid.app
|
||||
|
||||
import android.content.Context
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
@ -18,6 +19,8 @@ import org.pixeldroid.app.testUtility.*
|
||||
import org.pixeldroid.app.utils.db.AppDatabase
|
||||
import org.junit.rules.Timeout
|
||||
import org.junit.runner.RunWith
|
||||
import org.pixeldroid.app.testUtility.ToolbarMatchers.withToolbarSubtitle
|
||||
import org.pixeldroid.app.testUtility.ToolbarMatchers.withToolbarTitle
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class DrawerMenuTest {
|
||||
@ -156,7 +159,8 @@ class DrawerMenuTest {
|
||||
|
||||
waitForView(R.id.profilePictureImageView)
|
||||
|
||||
onView(withId(R.id.accountNameTextView)).check(matches(withText("PixelDroid Developer")))
|
||||
onView(isAssignableFrom(Toolbar::class.java)).check(matches(withToolbarTitle("PixelDroid Developer")))
|
||||
onView(isAssignableFrom(Toolbar::class.java)).check(matches(withToolbarSubtitle("@pixeldroid")))
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -174,7 +178,8 @@ class DrawerMenuTest {
|
||||
onView(withText("@user2")).perform(click())
|
||||
waitForView(R.id.profilePictureImageView)
|
||||
|
||||
onView(withId(R.id.accountNameTextView)).check(matches(withText("User 2")))
|
||||
onView(isAssignableFrom(Toolbar::class.java)).check(matches(withToolbarTitle("User 2")))
|
||||
onView(isAssignableFrom(Toolbar::class.java)).check(matches(withToolbarSubtitle("@user2")))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2,6 +2,7 @@ package org.pixeldroid.app
|
||||
|
||||
|
||||
import android.content.Context
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
@ -180,7 +181,7 @@ class HomeFeedTest {
|
||||
onView(withId(R.id.list)).perform(
|
||||
actionOnItemAtPosition<StatusViewHolder>(0, clickChildViewWithId(R.id.username))
|
||||
)
|
||||
onView(withId(R.id.accountNameTextView)).check(matches(isDisplayed()))
|
||||
onView(withId(R.id.profilePictureImageView)).check(matches(isDisplayed()))
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -191,7 +192,7 @@ class HomeFeedTest {
|
||||
onView(withId(R.id.list)).perform(
|
||||
actionOnItemAtPosition<StatusViewHolder>(0, clickChildViewWithId(R.id.profilePic))
|
||||
)
|
||||
onView(withId(R.id.accountNameTextView)).check(matches(isDisplayed()))
|
||||
onView(withId(R.id.profilePictureImageView)).check(matches(isDisplayed()))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -0,0 +1,132 @@
|
||||
package org.pixeldroid.app.testUtility;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.view.View;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.test.espresso.matcher.BoundedMatcher;
|
||||
|
||||
public class ToolbarMatchers {
|
||||
|
||||
public static Matcher<View> withToolbarTitle(CharSequence text) {
|
||||
return new WithCharSequenceMatcher(is(text), ToolbarMethod.GET_TITLE);
|
||||
}
|
||||
|
||||
public static Matcher<View> withToolbarSubtitle(CharSequence text) {
|
||||
return new WithCharSequenceMatcher(is(text), ToolbarMethod.GET_SUBTITLE);
|
||||
}
|
||||
|
||||
|
||||
public static Matcher<View> withToolbarTitle(final int resourceId) {
|
||||
return new WithStringResourceMatcher(resourceId, ToolbarMethod.GET_TITLE);
|
||||
}
|
||||
|
||||
public static Matcher<View> withToolbarSubTitle(final int resourceId) {
|
||||
return new WithStringResourceMatcher(resourceId, ToolbarMethod.GET_SUBTITLE);
|
||||
}
|
||||
|
||||
|
||||
private static final class WithCharSequenceMatcher extends BoundedMatcher<View, Toolbar> {
|
||||
|
||||
private final Matcher<CharSequence> charSequenceMatcher;
|
||||
private final ToolbarMethod method;
|
||||
|
||||
private WithCharSequenceMatcher(Matcher<CharSequence> charSequenceMatcher, ToolbarMethod method) {
|
||||
super(Toolbar.class);
|
||||
this.charSequenceMatcher = charSequenceMatcher;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("with text: ");
|
||||
charSequenceMatcher.describeTo(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean matchesSafely(Toolbar toolbar) {
|
||||
|
||||
CharSequence actualText;
|
||||
switch (method) {
|
||||
case GET_TITLE:
|
||||
actualText = toolbar.getTitle();
|
||||
break;
|
||||
case GET_SUBTITLE:
|
||||
actualText = toolbar.getSubtitle();
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected Toolbar method: " + method.toString());
|
||||
}
|
||||
|
||||
return charSequenceMatcher.matches(actualText);
|
||||
}
|
||||
}
|
||||
|
||||
static final class WithStringResourceMatcher extends BoundedMatcher<View, Toolbar> {
|
||||
|
||||
private final int resourceId;
|
||||
|
||||
@Nullable
|
||||
private String resourceName;
|
||||
@Nullable
|
||||
private String expectedText;
|
||||
|
||||
private final ToolbarMethod method;
|
||||
|
||||
|
||||
private WithStringResourceMatcher(int resourceId, ToolbarMethod method) {
|
||||
super(Toolbar.class);
|
||||
this.resourceId = resourceId;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("with string from resource id: ").appendValue(resourceId);
|
||||
if (null != resourceName) {
|
||||
description.appendText("[").appendText(resourceName).appendText("]");
|
||||
}
|
||||
if (null != expectedText) {
|
||||
description.appendText(" value: ").appendText(expectedText);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesSafely(Toolbar toolbar) {
|
||||
if (null == expectedText) {
|
||||
try {
|
||||
expectedText = toolbar.getResources().getString(resourceId);
|
||||
resourceName = toolbar.getResources().getResourceEntryName(resourceId);
|
||||
} catch (Resources.NotFoundException ignored) {
|
||||
/* view could be from a context unaware of the resource id. */
|
||||
}
|
||||
}
|
||||
CharSequence actualText;
|
||||
switch (method) {
|
||||
case GET_TITLE:
|
||||
actualText = toolbar.getTitle();
|
||||
break;
|
||||
case GET_SUBTITLE:
|
||||
actualText = toolbar.getSubtitle();
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected Toolbar method: " + method.toString());
|
||||
}
|
||||
// FYI: actualText may not be string ... its just a char sequence convert to string.
|
||||
return null != expectedText
|
||||
&& null != actualText
|
||||
&& expectedText.equals(actualText.toString());
|
||||
}
|
||||
}
|
||||
|
||||
enum ToolbarMethod {
|
||||
GET_TITLE,
|
||||
GET_SUBTITLE
|
||||
}
|
||||
}
|
@ -46,7 +46,7 @@ class PostActivity : BaseActivity() {
|
||||
domain = user?.instance_uri.orEmpty()
|
||||
|
||||
|
||||
supportActionBar?.title = getString(R.string.post_title).format(status.account?.getDisplayName())
|
||||
supportActionBar?.title = getString(R.string.post_title).format(status.account?.username)
|
||||
|
||||
val holder = StatusViewHolder(binding.postFragmentSingle)
|
||||
|
||||
|
@ -89,13 +89,13 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
||||
) {
|
||||
//Setup username as a button that opens the profile
|
||||
binding.username.apply {
|
||||
text = status?.account?.getDisplayName() ?: ""
|
||||
text = status?.account?.username ?: ""
|
||||
setTypeface(null, Typeface.BOLD)
|
||||
setOnClickListener { status?.account?.openProfile(binding.root.context) }
|
||||
}
|
||||
|
||||
binding.usernameDesc.apply {
|
||||
text = status?.account?.getDisplayName() ?: ""
|
||||
text = status?.account?.username ?: ""
|
||||
setTypeface(null, Typeface.BOLD)
|
||||
}
|
||||
|
||||
|
@ -25,9 +25,9 @@ class FollowsActivity : BaseActivity() {
|
||||
|
||||
if(account == null) {
|
||||
val user = db.userDao().getActiveUser()!!
|
||||
startFragment(user.user_id, user.display_name, followers)
|
||||
startFragment(user.user_id, user.username, followers)
|
||||
} else {
|
||||
startFragment(account.id!!, account.getDisplayName(), followers)
|
||||
startFragment(account.id!!, account.username.orEmpty(), followers)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,11 +157,10 @@ class ProfileActivity : BaseActivity() {
|
||||
|
||||
val displayName = account.getDisplayName()
|
||||
|
||||
binding.accountNameTextView.text = displayName
|
||||
supportActionBar?.title = "@${account.acct}"
|
||||
|
||||
supportActionBar?.title = displayName
|
||||
if(displayName != "@${account.acct}") {
|
||||
supportActionBar?.subtitle = "@${account.acct}"
|
||||
supportActionBar?.subtitle = displayName
|
||||
}
|
||||
|
||||
binding.nbPostsTextView.text = resources.getQuantityString(
|
||||
|
@ -75,6 +75,7 @@ data class Account(
|
||||
}
|
||||
|
||||
fun anyAvatar(): String? = avatar_static ?: avatar
|
||||
|
||||
/**
|
||||
* @brief Open profile activity with given account
|
||||
*/
|
||||
|
@ -65,19 +65,6 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/nbFollowersTextView" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/accountNameTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:text="@string/no_username"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/profilePictureImageView" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/descriptionTextView"
|
||||
@ -88,7 +75,7 @@
|
||||
android:layout_marginRight="20dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/accountNameTextView" />
|
||||
app:layout_constraintTop_toBottomOf="@id/profilePictureImageView" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/followButton"
|
||||
|
@ -215,9 +215,9 @@ For more info about Pixelfed, you can check here: https://pixelfed.org"</string>
|
||||
<string name="license_info">PixelDroid is free and open source software, licensed under the GNU General Public License (version 3 or later)</string>
|
||||
<string name="about">About</string>
|
||||
<string name="post_title">%1$s\'s post</string>
|
||||
<string name="followers_title">%1$s\'s followers</string>
|
||||
<string name="followers_title">\@%1$s\'s followers</string>
|
||||
<string name="hashtag_title">#%1$s</string>
|
||||
<string name="follows_title">%1$s\'s follows</string>
|
||||
<string name="follows_title">\@%1$s\'s follows</string>
|
||||
<string name="search_empty_error">Search query can\'t be empty</string>
|
||||
<string name="status_more_options">More options</string>
|
||||
<string name="report">Report</string>
|
||||
|
@ -33,9 +33,6 @@ class PostUnitTest {
|
||||
@Test
|
||||
fun getProfilePicUrlReturnsAValidURL() = Assert.assertNotNull(status.getProfilePicUrl())
|
||||
|
||||
@Test
|
||||
fun getUsernameReturnsACorrectName() = Assert.assertEquals(status.account!!.display_name, status.account!!.getDisplayName())
|
||||
|
||||
/*@Test
|
||||
fun getUsernameReturnsOtherNameIfUsernameIsNull() {
|
||||
val emptyDescStatus = status.copy(account = status.account!!.copy(username = ""))
|
||||
|
Loading…
x
Reference in New Issue
Block a user