From e261bbebe9e9e2f6b1cad358698b2e5df2eced46 Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Thu, 7 Dec 2023 11:39:49 -0600 Subject: [PATCH 1/4] Strip search term --- .../slimefun4/implementation/guide/SurvivalSlimefunGuide.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java index 2e86296008..b9d0b70b9a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java @@ -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.strip(input.toLowerCase(Locale.ROOT)); if (addToHistory) { profile.getGuideHistory().add(searchTerm); From d0963697ca682f58411ffecbd0ab787834dcf85c Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Thu, 7 Dec 2023 11:48:45 -0600 Subject: [PATCH 2/4] use proper method name --- .../slimefun4/implementation/guide/SurvivalSlimefunGuide.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java index b9d0b70b9a..621431efc1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java @@ -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 = ChatColor.strip(input.toLowerCase(Locale.ROOT)); + String searchTerm = ChatColor.stripColor(input.toLowerCase(Locale.ROOT)); if (addToHistory) { profile.getGuideHistory().add(searchTerm); From e83c9f704e8ca78756aa0ef1bb32457ef0dbc54e Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Thu, 7 Dec 2023 12:48:57 -0600 Subject: [PATCH 3/4] Add test for both normal and colored seearches --- .../core/guide/TestGuideOpening.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/core/guide/TestGuideOpening.java b/src/test/java/io/github/thebusybiscuit/slimefun4/core/guide/TestGuideOpening.java index 8ed5d838b9..586800bec4 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/core/guide/TestGuideOpening.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/core/guide/TestGuideOpening.java @@ -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; @@ -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 { + 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"); + + guide.openSearch(profile, coloredQuery, false); + 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 testOpenSearchHistory() throws InterruptedException { String query = "electric"; SlimefunGuideImplementation guide = Mockito.mock(SlimefunGuideImplementation.class); From 82c8c91451306158a6211d7ce3375fe2cfc566ce Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Thu, 7 Dec 2023 16:28:39 -0600 Subject: [PATCH 4/4] Suggestions and consistency --- .../core/guide/TestGuideOpening.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/core/guide/TestGuideOpening.java b/src/test/java/io/github/thebusybiscuit/slimefun4/core/guide/TestGuideOpening.java index 586800bec4..a8685b9736 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/core/guide/TestGuideOpening.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/core/guide/TestGuideOpening.java @@ -93,10 +93,10 @@ void testOpenItemStack() throws InterruptedException { } @Test - @DisplayName("Test if the Slimefun Search works with normal and colored querys") - void testOpenSearch() throws InterruptedException { - String normalQuery = "iron"; - String coloredQuery = ChatColor.DARK_PURPLE + "iron"; + @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); @@ -105,21 +105,23 @@ void testOpenSearch() throws InterruptedException { PlayerProfile profile = TestUtilities.awaitProfile(player); SlimefunGuideImplementation guide = new SurvivalSlimefunGuide(false, false); - guide.openSearch(profile, normalQuery, 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, coloredQuery, false); + 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 testOpenSearchHistory() throws InterruptedException { - String query = "electric"; + 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