Skip to content

Commit

Permalink
Merge pull request #20940 from wordpress-mobile/issue/20033-show-list…
Browse files Browse the repository at this point in the history
…s-directly-dropdown-menu-if-2-or-fewer-items

[Reader] Show custom lists directly if there are 2 or fewer items
  • Loading branch information
RenanLukas authored Jun 5, 2024
2 parents a24e5d1 + 03b73d8 commit fe8a023
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,30 @@ class ReaderTopBarMenuHelper @Inject constructor(
.takeIf { it.isNotEmpty() }
?.let { customListsArray ->
add(MenuElementData.Divider)
add(createCustomListsItem(customListsArray))
createCustomListsItems(customListsArray)
}
}
}

private fun MutableList<MenuElementData>.createCustomListsItems(
customListsArray: SparseArrayCompat<ReaderTag>
) {
if (customListsArray.size() > 2) {
// If custom lists has more than 2 items, we add a submenu called "Lists"
add(createCustomListsItem(customListsArray))
} else {
// If the custom lists has 2 or less items, we add the items directly without submenu
customListsArray.forEach { index, readerTag ->
add(
MenuElementData.Item.Single(
id = getMenuItemIdFromReaderTagIndex(index),
text = UiString.UiStringText(readerTag.tagTitle),
)
)
}
}
}

private fun createDiscoverItem(id: String): MenuElementData.Item.Single {
return MenuElementData.Item.Single(
id = id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,27 @@ class ReaderTopBarMenuHelperTest {
assertThat(customList3Item.text).isEqualTo(UiStringText("custom-list-3"))
}

@Test
fun `GIVEN custom lists has 2 items or less WHEN createMenu THEN custom lists items are shown outside a submenu`() {
val tags = ReaderTagList().apply {
add(mockFollowingTag()) // item 0
add(mockDiscoverTag()) // item 1
add(mockSavedTag()) // item 2
add(mockLikedTag()) // item 3
add(mockA8CTag()) // item 4
add(mockFollowedP2sTag()) // item 5
add(createCustomListTag("custom-list-1")) // item 6
add(createCustomListTag("custom-list-2")) // item 7
}
val menu = helper.createMenu(tags)

val customListItem1 = menu.findSingleItem { it.id == "6" }!!
assertThat(customListItem1.text).isEqualTo(UiStringText("custom-list-1"))

val customListItem2 = menu.findSingleItem { it.id == "7" }!!
assertThat(customListItem2.text).isEqualTo(UiStringText("custom-list-2"))
}

@Test
fun `GIVEN all tags are available and tags FF enabled WHEN createMenu THEN all items are created correctly`() {
whenever(readerTagsFeedFeatureConfig.isEnabled()).thenReturn(true)
Expand Down

0 comments on commit fe8a023

Please sign in to comment.