Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip colors from search term #4044

Merged
merged 4 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,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 @@ -90,8 +93,28 @@ void testOpenItemStack() throws InterruptedException {
}

@Test
@DisplayName("Test if the Slimefun Search can be opened from the History")
@DisplayName("Test if the Slimefun Search works with normal and colored querys")
void testOpenSearch() throws InterruptedException {
JustAHuman-xD marked this conversation as resolved.
Show resolved Hide resolved
String normalQuery = "iron";
String coloredQuery = 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, normalQuery, false);
Assertions.assertTrue(player.getOpenInventory().getTopInventory().contains(testItem.getItem()), "Failed on normal query");
JustAHuman-xD marked this conversation as resolved.
Show resolved Hide resolved

guide.openSearch(profile, coloredQuery, false);
Assertions.assertTrue(player.getOpenInventory().getTopInventory().contains(testItem.getItem()), "Failed on colored query");
JustAHuman-xD marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
@DisplayName("Test if the Slimefun Search can be opened from the History")
void testOpenSearchHistory() throws InterruptedException {
WalshyDev marked this conversation as resolved.
Show resolved Hide resolved
String query = "electric";

SlimefunGuideImplementation guide = Mockito.mock(SlimefunGuideImplementation.class);
Expand Down