File tree 2 files changed +41
-1
lines changed
main/java/org/wordpress/android/ui/reader/utils
test/java/org/wordpress/android/ui/reader/utils
2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -55,11 +55,30 @@ class ReaderTopBarMenuHelper @Inject constructor(
55
55
.takeIf { it.isNotEmpty() }
56
56
?.let { customListsArray ->
57
57
add(MenuElementData .Divider )
58
- add(createCustomListsItem( customListsArray) )
58
+ createCustomListsItems( customListsArray)
59
59
}
60
60
}
61
61
}
62
62
63
+ private fun MutableList<MenuElementData>.createCustomListsItems (
64
+ customListsArray : SparseArrayCompat <ReaderTag >
65
+ ) {
66
+ if (customListsArray.size() > 2 ) {
67
+ // If custom lists has more than 2 items, we add a submenu called "Lists"
68
+ add(createCustomListsItem(customListsArray))
69
+ } else {
70
+ // If the custom lists has 2 or less items, we add the items directly without submenu
71
+ customListsArray.forEach { index, readerTag ->
72
+ add(
73
+ MenuElementData .Item .Single (
74
+ id = getMenuItemIdFromReaderTagIndex(index),
75
+ text = UiString .UiStringText (readerTag.tagTitle),
76
+ )
77
+ )
78
+ }
79
+ }
80
+ }
81
+
63
82
private fun createDiscoverItem (id : String ): MenuElementData .Item .Single {
64
83
return MenuElementData .Item .Single (
65
84
id = id,
Original file line number Diff line number Diff line change @@ -72,6 +72,27 @@ class ReaderTopBarMenuHelperTest {
72
72
assertThat(customList3Item.text).isEqualTo(UiStringText (" custom-list-3" ))
73
73
}
74
74
75
+ @Test
76
+ fun `GIVEN custom lists has 2 items or less WHEN createMenu THEN custom lists items are shown outside a submenu` () {
77
+ val tags = ReaderTagList ().apply {
78
+ add(mockFollowingTag()) // item 0
79
+ add(mockDiscoverTag()) // item 1
80
+ add(mockSavedTag()) // item 2
81
+ add(mockLikedTag()) // item 3
82
+ add(mockA8CTag()) // item 4
83
+ add(mockFollowedP2sTag()) // item 5
84
+ add(createCustomListTag(" custom-list-1" )) // item 6
85
+ add(createCustomListTag(" custom-list-2" )) // item 7
86
+ }
87
+ val menu = helper.createMenu(tags)
88
+
89
+ val customListItem1 = menu.findSingleItem { it.id == " 6" }!!
90
+ assertThat(customListItem1.text).isEqualTo(UiStringText (" custom-list-1" ))
91
+
92
+ val customListItem2 = menu.findSingleItem { it.id == " 7" }!!
93
+ assertThat(customListItem2.text).isEqualTo(UiStringText (" custom-list-2" ))
94
+ }
95
+
75
96
@Test
76
97
fun `GIVEN all tags are available and tags FF enabled WHEN createMenu THEN all items are created correctly` () {
77
98
whenever(readerTagsFeedFeatureConfig.isEnabled()).thenReturn(true )
You can’t perform that action at this time.
0 commit comments