aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorHelfull <admin@helfull.de>2023-10-17 12:30:23 +0200
committerGitHub <noreply@github.com>2023-10-17 12:30:23 +0200
commit48a41d5dd03a7fa591827f3bcb0f9d6f2dc27e9a (patch)
tree5374eb81ed19d929187eb98a0a88433329e32b88 /src/test
parent8116fb8434a724b67be01e1369ef902b865d5c49 (diff)
downloadskyhanni-48a41d5dd03a7fa591827f3bcb0f9d6f2dc27e9a.tar.gz
skyhanni-48a41d5dd03a7fa591827f3bcb0f9d6f2dc27e9a.tar.bz2
skyhanni-48a41d5dd03a7fa591827f3bcb0f9d6f2dc27e9a.zip
Internal Changes: Refactor VisitorAPI to event based interaction (#561)
Split up GardenVisitorFeatures into multiple useful events #561
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/at/hannibal2/skyhanni/test/garden/VisitorAPITest.kt51
-rw-r--r--src/test/java/at/hannibal2/skyhanni/test/garden/VisitorListenerTest.kt83
-rw-r--r--src/test/java/at/hannibal2/skyhanni/test/garden/VisitorToolTipParserTest.kt65
3 files changed, 199 insertions, 0 deletions
diff --git a/src/test/java/at/hannibal2/skyhanni/test/garden/VisitorAPITest.kt b/src/test/java/at/hannibal2/skyhanni/test/garden/VisitorAPITest.kt
new file mode 100644
index 000000000..74baf866a
--- /dev/null
+++ b/src/test/java/at/hannibal2/skyhanni/test/garden/VisitorAPITest.kt
@@ -0,0 +1,51 @@
+package at.hannibal2.skyhanni.test.garden
+
+import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI
+import org.junit.jupiter.api.Test
+
+class VisitorAPITest {
+
+ @Test
+ fun testFromHypixelName() {
+ assert(VisitorAPI.fromHypixelName(" §r Jacob") == "§fJacob")
+ assert(VisitorAPI.fromHypixelName("§r Jacob") == "§fJacob")
+ assert(VisitorAPI.fromHypixelName("§rJacob") == "§fJacob")
+ assert(VisitorAPI.fromHypixelName("Jacob") == "§fJacob")
+ assert(VisitorAPI.fromHypixelName(" Jacob ") == "§fJacob")
+ assert(VisitorAPI.fromHypixelName("§cSpaceman") == "§cSpaceman")
+ assert(VisitorAPI.fromHypixelName("§cGrandma Wolf") == "§cGrandma Wolf")
+ }
+
+ @Test
+ fun testIsVisitorInfo() {
+
+ // To short
+ assert(
+ VisitorAPI.isVisitorInfo(mutableListOf(
+ "§a§lVisitor Info",
+ "§7§oClick to view info about this visitor."
+ )) == false
+ )
+
+ // To long
+ assert(
+ VisitorAPI.isVisitorInfo(mutableListOf(
+ "§a§lVisitor Info",
+ "§7§oClick to view info about this visitor.",
+ "§7§oClick to view info about this visitor.",
+ "§7§oClick to view info about this visitor.",
+ "§7§oClick to view info about this visitor.",
+ )) == false
+ )
+
+ // Third line is §7Offers Accepted: §a
+ assert(
+ VisitorAPI.isVisitorInfo(mutableListOf(
+ "§a§lVisitor Info",
+ "§7§oClick to view info about this visitor.",
+ "§7§oClick to view info about this visitor.",
+ "§7Offers Accepted: §a",
+ )) == true
+ )
+ }
+} \ No newline at end of file
diff --git a/src/test/java/at/hannibal2/skyhanni/test/garden/VisitorListenerTest.kt b/src/test/java/at/hannibal2/skyhanni/test/garden/VisitorListenerTest.kt
new file mode 100644
index 000000000..13e96a019
--- /dev/null
+++ b/src/test/java/at/hannibal2/skyhanni/test/garden/VisitorListenerTest.kt
@@ -0,0 +1,83 @@
+package at.hannibal2.skyhanni.test.garden
+
+import at.hannibal2.skyhanni.events.TabListUpdateEvent
+import at.hannibal2.skyhanni.features.garden.GardenAPI
+import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI
+import at.hannibal2.skyhanni.features.garden.visitor.VisitorListener
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import io.mockk.every
+import io.mockk.mockk
+import io.mockk.mockkObject
+import io.mockk.verify
+import org.junit.jupiter.api.BeforeEach
+import org.junit.jupiter.api.Test
+
+
+class VisitorListenerTest {
+ private lateinit var listener: VisitorListener
+ @BeforeEach
+ fun setUp() {
+ mockkObject(GardenAPI)
+ every { GardenAPI.inGarden() } returns true
+
+ mockkObject(LorenzUtils)
+ every { LorenzUtils.getPlayerName() } returns "ThePlayerName"
+
+ mockkObject(VisitorAPI)
+ every { VisitorAPI.addVisitor(any()) } returns true
+
+ listener = VisitorListener()
+ }
+
+ @Test
+ fun `onTablistUpdate it should add new visitors to the list`() {
+ listener.onTabListUpdate(
+ TabListUpdateEvent(mutableListOf(
+ "§b§lVisitors:",
+ "§cSpaceman",
+ "§cGrandma Wolf",
+ "ThePlayerName",
+ "Jacob",
+ "",
+ ))
+ )
+
+ verify { VisitorAPI.addVisitor("§fJacob") }
+ verify { VisitorAPI.addVisitor("§cSpaceman") }
+ verify { VisitorAPI.addVisitor("§cGrandma Wolf") }
+ }
+
+ @Test
+ fun `onTablistUpdate it should remove visitors from the list`() {
+ every { VisitorAPI.getVisitors() } returns listOf(
+ mockk { every { visitorName } returns "§fJacob" },
+ )
+
+ listener.onTabListUpdate(
+ TabListUpdateEvent(mutableListOf(
+ "§b§lVisitors:",
+ "",
+ ))
+ )
+
+ verify { VisitorAPI.removeVisitor("§fJacob") }
+ }
+
+ @Test
+ fun `onTablistUpdate it should not remove visitors if the timeout is not hit`() {
+ every { VisitorAPI.getVisitors() } returns listOf(
+ mockk { every { visitorName } returns "§fJacob" },
+ )
+
+ every { LorenzUtils.lastWorldSwitch } returns System.currentTimeMillis()
+
+ listener.onTabListUpdate(
+ TabListUpdateEvent(mutableListOf(
+ "§b§lVisitors:",
+ "",
+ ))
+ )
+
+ verify(exactly = 0) { VisitorAPI.removeVisitor("§fJacob") }
+ }
+} \ No newline at end of file
diff --git a/src/test/java/at/hannibal2/skyhanni/test/garden/VisitorToolTipParserTest.kt b/src/test/java/at/hannibal2/skyhanni/test/garden/VisitorToolTipParserTest.kt
new file mode 100644
index 000000000..9418b3db8
--- /dev/null
+++ b/src/test/java/at/hannibal2/skyhanni/test/garden/VisitorToolTipParserTest.kt
@@ -0,0 +1,65 @@
+package at.hannibal2.skyhanni.test.garden
+
+import at.hannibal2.skyhanni.config.features.GardenConfig
+import at.hannibal2.skyhanni.features.garden.visitor.VisitorTooltipParser
+import org.junit.jupiter.api.Test
+
+class VisitorToolTipParserTest {
+ private val lore = mutableListOf(
+ "§7Items Required:",
+ " §aEnchanted Hay Bale §8x28",
+ "",
+ "§7Rewards:",
+ " §8+§37.2k §7Farming XP",
+ " §8+§215 §7Garden Experience",
+ " §8+§c23 Copper",
+ " §8+§b10 Bits",
+ " §aJacob's Ticket",
+ " §9Flowering Bouquet",
+ "",
+ "§eClick to give!"
+ )
+
+ @Test
+ fun testParseItemsNeeded() {
+ val parsedData = VisitorTooltipParser.parse(lore, GardenConfig())
+ assert(parsedData.itemsNeeded.isNotEmpty()) {
+ "Visitor items needed is ${parsedData.itemsNeeded.count()} instead of 1"
+ }
+ assert(parsedData.itemsNeeded.get("§aEnchanted Hay Bale") == 28) {
+ "Visitor items needed does not contain '§aEnchanted Hay Bale'"
+ }
+ }
+
+ @Test
+ fun testParseRewards() {
+ val parsedData = VisitorTooltipParser.parse(lore, GardenConfig())
+ assert(parsedData.rewards.isNotEmpty()) {
+ "Visitor rewards is ${parsedData.rewards.count()} instead of 6"
+ }
+
+ val assertions = mutableMapOf(
+ "§7Farming XP" to 7200,
+ "§7Garden Experience" to 15,
+ "Copper" to 23,
+ "Bits" to 10,
+ "§aJacob's Ticket" to 1,
+ "§9Flowering Bouquet" to 1
+ )
+
+ for ((itemName, amount) in assertions) {
+ assert(parsedData.rewards.get(itemName) == amount) {
+ "Visitor rewards does not contain '$itemName' with amount '$amount'"
+ }
+ }
+ }
+
+ @Test
+ fun testParseCopper() {
+ val parsedData = VisitorTooltipParser.parse(lore, GardenConfig())
+ val copper = parsedData.rewards.get("Copper")
+ assert(copper == 23) {
+ "Visitor rewards does not contain 'Copper' with amount '23'"
+ }
+ }
+} \ No newline at end of file