Skip to content

Commit

Permalink
Fix crash caused by #290, discovered by pre-launch report
Browse files Browse the repository at this point in the history
  • Loading branch information
TWiStErRob committed Aug 30, 2023
1 parent 7e6acfc commit 12124d6
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import static org.hamcrest.Matchers.emptyString;
import static org.hamcrest.Matchers.not;

import androidx.test.ext.junit.runners.AndroidJUnit4;

import net.twisterrob.inventory.android.activity.data.ItemEditActivity;
Expand Down Expand Up @@ -60,4 +63,11 @@ public class ItemEditActivityTest_Edit {
// changes applied
db.assertItemHasType(TEST_ITEM, TEST_ITEM_CATEGORY_OTHER);
}

@Category({On.Category.class})
@Test public void testShowKeywords() {
KeywordsDialogActor keywords = itemEdit.help().showKeywords();
keywords.assertKeywords(not(emptyString()));
keywords.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package net.twisterrob.inventory.android.test.actors;

import net.twisterrob.inventory.android.R;
import net.twisterrob.inventory.android.activity.data.CategoryActivity;

public class CategoryActivityActor extends ItemContainingViewActivityActor {
public CategoryActivityActor() {
super(CategoryActivity.class);
}

@Override public void assertShowing(String itemName) {
assertActionTitle(itemName);
}

public CategoryActivityActor flatten() {
clickActionBar(R.id.action_category_viewAllItems);
CategoryActivityActor activity = new CategoryActivityActor();
activity.assertIsInFront();
return activity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ public void checkType(@StringRes int type) {
public void checkPicture(@ColorInt int backgroundColor) {
onView(imageMatcher).perform(scrollTo()).check(matches(withBitmap(hasBackgroundColor(backgroundColor))));
}
public InfoPopupActor help() {
onView(withId(R.id.help)).perform(click());
InfoPopupActor popup = new InfoPopupActor();
popup.assertDisplayed();
return popup;
}
public SaveResultActor save() {
onView(withId(R.id.btn_save)).perform(click());
return new SaveResultActor();
Expand Down Expand Up @@ -161,4 +167,28 @@ public final void checkToastAlreadyExists() {
assertToastMessage(withText(matcher));
}
}

public static class InfoPopupActor {
public void assertDisplayed() {
onRoot(isPlatformPopup()).check(matches(isCompletelyDisplayed()));
}

public KeywordsDialogActor showKeywords() {
onData(withMenuItemId(R.id.action_category_keywords)).perform(click());
KeywordsDialogActor dialog = new KeywordsDialogActor();
dialog.assertDisplayed();
return dialog;
}

public CategoryActivityActor jumpToCategory() {
onData(withMenuItemId(R.id.action_category_goto)).perform(click());
CategoryActivityActor activity = new CategoryActivityActor();
activity.assertIsInFront();
return activity;
}

public void suggestCategories() {
onData(withMenuItemId(R.id.action_category_suggest)).perform(click());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package net.twisterrob.inventory.android.test.actors;

import org.hamcrest.Matcher;

import static org.hamcrest.Matchers.anyOf;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.test.espresso.Espresso;

Expand All @@ -28,6 +31,9 @@ public class KeywordsDialogActor extends AlertDialogActor {
public void assertKeywords(@StringRes int keywords) {
assertDialogMessage(withText(keywords));
}
public void assertKeywords(@NonNull Matcher<String> matcher) {
assertDialogMessage(withText(matcher));
}

public void close() {
// Could also "tap outside", but not sure how to do that.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import javax.inject.Inject;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources.NotFoundException;
import android.text.SpannableStringBuilder;
Expand Down Expand Up @@ -95,8 +96,8 @@ public CategoryVisuals(
}
}

public void showKeywords(long categoryID) {
public void showKeywords(@NonNull Activity activity, long categoryID) {
CharSequence keywords = getKeywords(cache.getCategoryKey(categoryID), true);
ChangeTypeDialog.showKeywords(context, cache.getCategoryPath(categoryID), keywords);
ChangeTypeDialog.showKeywords(activity, cache.getCategoryPath(categoryID), keywords);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public void onClick(View v) {
Hinter.unhighlight(name.getText());
}
@Override public void categoryQueried(long categoryID) {
visuals.showKeywords(categoryID);
visuals.showKeywords(requireActivity(), categoryID);
}
});
hint.setAdapter(hinter.getAdapter());
Expand Down Expand Up @@ -281,7 +281,7 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
// CONSIDER setOnItemLongClickListener is not supported, any way to work around? So user has the same "tooltip" as in ChangeTypeDialog
type.setOnLongClickListener(new OnLongClickListener() {
@Override public boolean onLongClick(View view) {
visuals.showKeywords(getTypeId());
visuals.showKeywords(requireActivity(), getTypeId());
return true;
}
});
Expand Down Expand Up @@ -330,7 +330,7 @@ private void onPrepareContextMenu(Menu menu, MenuInflater inflater) {
updateHint(name.getText(), true);
return true;
} else if (id == R.id.action_category_keywords) {
visuals.showKeywords(getTypeId());
visuals.showKeywords(requireActivity(), getTypeId());
return true;
} else {
return super.onContextItemSelected(item);
Expand Down

0 comments on commit 12124d6

Please sign in to comment.