Skip to content

Commit

Permalink
Merge pull request #4044 from JustAHuman-xD/fix/colored-search-term
Browse files Browse the repository at this point in the history
  • Loading branch information
Sfiguz7 authored Dec 8, 2023
2 parents 1a71d83 + 82c8c91 commit 123e3b5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public void openSearch(PlayerProfile profile, String input, boolean addToHistory
}

ChestMenu menu = new ChestMenu(Slimefun.getLocalization().getMessage(p, "guide.search.inventory").replace("%item%", ChatUtils.crop(ChatColor.WHITE, input)));
String searchTerm = input.toLowerCase(Locale.ROOT);
String searchTerm = ChatColor.stripColor(input.toLowerCase(Locale.ROOT));

if (addToHistory) {
profile.getGuideHistory().add(searchTerm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;

import io.github.thebusybiscuit.slimefun4.implementation.guide.SurvivalSlimefunGuide;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -89,14 +92,36 @@ void testOpenItemStack() throws InterruptedException {
Mockito.verify(guide).displayItem(profile, item, 1, false);
}

@Test
@DisplayName("Test if the Slimefun Search works with normal and colored terms")
void testOpenSearch_withColoredSearchTerm() throws InterruptedException {
String normalTerm = "iron";
String coloredTerm = ChatColor.DARK_PURPLE + "iron";

SlimefunItem testItem = TestUtilities.mockSlimefunItem(plugin, "IRON_ITEM", new CustomItemStack(Material.IRON_INGOT, "iron item"));
testItem.register(plugin);

Player player = server.addPlayer();
PlayerProfile profile = TestUtilities.awaitProfile(player);
SlimefunGuideImplementation guide = new SurvivalSlimefunGuide(false, false);

guide.openSearch(profile, normalTerm, false);
// Assert we can open with a non-coloured search term
Assertions.assertTrue(player.getOpenInventory().getTopInventory().contains(testItem.getItem()), "Failed on normal query");

guide.openSearch(profile, coloredTerm, false);
// Assert we can open with a coloured search term
Assertions.assertTrue(player.getOpenInventory().getTopInventory().contains(testItem.getItem()), "Failed on colored query");
}

@Test
@DisplayName("Test if the Slimefun Search can be opened from the History")
void testOpenSearch() throws InterruptedException {
String query = "electric";
void testOpenSearchHistory() throws InterruptedException {
String term = "electric";

SlimefunGuideImplementation guide = Mockito.mock(SlimefunGuideImplementation.class);
PlayerProfile profile = prepare(guide, history -> history.add(query));
Mockito.verify(guide).openSearch(profile, query, false);
PlayerProfile profile = prepare(guide, history -> history.add(term));
Mockito.verify(guide).openSearch(profile, term, false);
}

@Test
Expand Down

0 comments on commit 123e3b5

Please sign in to comment.