Skip to content

Commit e5b46ad

Browse files
committed
Add Chat Box event test
1 parent fe24952 commit e5b46ad

File tree

4 files changed

+169
-1
lines changed

4 files changed

+169
-1
lines changed

src/testMod/kotlin/de/srendi/advancedperipherals/test/ChatBoxTest.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class ChatBoxTest {
9191
ClientTestEvents.toasts.clear()
9292
}
9393
thenComputerOk()
94+
9495
thenOnClient {
9596
// sendMessage
9697
context.assertChatContains(Component.literal("[§r").append("AP").append("]§r ").append("Default message"))
@@ -158,4 +159,14 @@ class ChatBoxTest {
158159
}
159160
}
160161

162+
@ClientGameTest
163+
fun chatBox_Events(context: GameTestHelper) = context.sequence {
164+
thenIdle(20)
165+
thenOnClient { Minecraft.getInstance().player!!.chatSigned("This is a normal chat message", null) }
166+
thenIdle(20)
167+
thenOnClient { Minecraft.getInstance().player!!.chatSigned("\$This is a hidden chat message", null) }
168+
thenIdle(20)
169+
thenComputerOk()
170+
}
171+
161172
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
--- Advanced Peripherals Chat Box tests
3+
--- Covers `sendMessage`, `sendMessageToPlayer`, `sendToastToPlayer`, `sendFormattedToastToPlayer`,
4+
--- `sendFormattedMessage`, `sendFormattedMessageToPlayer`
5+
---
6+
7+
chatBox = peripheral.find("chatBox")
8+
test.assert(chatBox, "Peripheral not found")
9+
10+
function assertMessage(msg, hidden)
11+
local event, username, message, uuid, isHidden = os.pullEvent("chat")
12+
test.eq("chat", event, "Event should be 'chat'")
13+
test.eq("Dev", username, "Username of sender should be 'Dev'")
14+
test.eq(msg, message, "Message should be '" .. msg .. "'")
15+
test.eq(hidden, isHidden, "Message should be " .. (hidden and "hidden" or "visible"))
16+
end
17+
18+
assertMessage("This is a normal chat message", false)
19+
assertMessage("This is a hidden chat message", true)

src/testMod/resources/data/advancedperipheralstest/structures/chatboxtest.chatbox.snbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
{pos: [1, 1, 3], state: "minecraft:air"},
3939
{pos: [1, 1, 4], state: "minecraft:air"},
4040
{pos: [2, 1, 0], state: "minecraft:air"},
41-
{pos: [2, 1, 1], state: "computercraft:computer_advanced{facing:west,state:on}", nbt: {ComputerId: 1, ForgeCaps: {}, Label: "chatboxtest.chatbox_events", On: 1b, id: "computercraft:computer_advanced"}},
41+
{pos: [2, 1, 1], state: "minecraft:air"},
4242
{pos: [2, 1, 2], state: "advancedperipherals:chat_box{orientation:west_up}", nbt: {ForgeCaps: {}, ForgeData: {CustomName: "[Chat Box]"}, Items: [], id: "advancedperipherals:chat_box", peripheralSettings: {cooldowns: {chatMessage: 1717353228235L}}}},
4343
{pos: [2, 1, 3], state: "computercraft:computer_advanced{facing:west,state:on}", nbt: {ComputerId: 0, ForgeCaps: {}, Label: "chatboxtest.chatbox", On: 1b, id: "computercraft:computer_advanced"}},
4444
{pos: [2, 1, 4], state: "minecraft:air"},
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
{
2+
DataVersion: 3120,
3+
size: [5, 5, 5],
4+
data: [
5+
{pos: [0, 0, 0], state: "minecraft:polished_andesite"},
6+
{pos: [0, 0, 1], state: "minecraft:polished_andesite"},
7+
{pos: [0, 0, 2], state: "minecraft:polished_andesite"},
8+
{pos: [0, 0, 3], state: "minecraft:polished_andesite"},
9+
{pos: [0, 0, 4], state: "minecraft:polished_andesite"},
10+
{pos: [1, 0, 0], state: "minecraft:polished_andesite"},
11+
{pos: [1, 0, 1], state: "minecraft:polished_andesite"},
12+
{pos: [1, 0, 2], state: "minecraft:polished_andesite"},
13+
{pos: [1, 0, 3], state: "minecraft:polished_andesite"},
14+
{pos: [1, 0, 4], state: "minecraft:polished_andesite"},
15+
{pos: [2, 0, 0], state: "minecraft:polished_andesite"},
16+
{pos: [2, 0, 1], state: "minecraft:polished_andesite"},
17+
{pos: [2, 0, 2], state: "minecraft:polished_andesite"},
18+
{pos: [2, 0, 3], state: "minecraft:polished_andesite"},
19+
{pos: [2, 0, 4], state: "minecraft:polished_andesite"},
20+
{pos: [3, 0, 0], state: "minecraft:polished_andesite"},
21+
{pos: [3, 0, 1], state: "minecraft:polished_andesite"},
22+
{pos: [3, 0, 2], state: "minecraft:polished_andesite"},
23+
{pos: [3, 0, 3], state: "minecraft:polished_andesite"},
24+
{pos: [3, 0, 4], state: "minecraft:polished_andesite"},
25+
{pos: [4, 0, 0], state: "minecraft:polished_andesite"},
26+
{pos: [4, 0, 1], state: "minecraft:polished_andesite"},
27+
{pos: [4, 0, 2], state: "minecraft:polished_andesite"},
28+
{pos: [4, 0, 3], state: "minecraft:polished_andesite"},
29+
{pos: [4, 0, 4], state: "minecraft:polished_andesite"},
30+
{pos: [0, 1, 0], state: "minecraft:air"},
31+
{pos: [0, 1, 1], state: "minecraft:air"},
32+
{pos: [0, 1, 2], state: "minecraft:air"},
33+
{pos: [0, 1, 3], state: "minecraft:air"},
34+
{pos: [0, 1, 4], state: "minecraft:air"},
35+
{pos: [1, 1, 0], state: "minecraft:air"},
36+
{pos: [1, 1, 1], state: "minecraft:air"},
37+
{pos: [1, 1, 2], state: "minecraft:air"},
38+
{pos: [1, 1, 3], state: "minecraft:air"},
39+
{pos: [1, 1, 4], state: "minecraft:air"},
40+
{pos: [2, 1, 0], state: "minecraft:air"},
41+
{pos: [2, 1, 1], state: "minecraft:air"},
42+
{pos: [2, 1, 2], state: "advancedperipherals:chat_box{orientation:west_up}", nbt: {ForgeCaps: {}, ForgeData: {CustomName: "[Chat Box]"}, Items: [], id: "advancedperipherals:chat_box", peripheralSettings: {cooldowns: {chatMessage: 1717353228235L}}}},
43+
{pos: [2, 1, 3], state: "computercraft:computer_advanced{facing:west,state:on}", nbt: {ComputerId: 0, ForgeCaps: {}, Label: "chatboxtest.chatbox_events", On: 1b, id: "computercraft:computer_advanced"}},
44+
{pos: [2, 1, 4], state: "minecraft:air"},
45+
{pos: [3, 1, 0], state: "minecraft:air"},
46+
{pos: [3, 1, 1], state: "minecraft:air"},
47+
{pos: [3, 1, 2], state: "minecraft:air"},
48+
{pos: [3, 1, 3], state: "minecraft:air"},
49+
{pos: [3, 1, 4], state: "minecraft:air"},
50+
{pos: [4, 1, 0], state: "minecraft:air"},
51+
{pos: [4, 1, 1], state: "minecraft:air"},
52+
{pos: [4, 1, 2], state: "minecraft:air"},
53+
{pos: [4, 1, 3], state: "minecraft:air"},
54+
{pos: [4, 1, 4], state: "minecraft:air"},
55+
{pos: [0, 2, 0], state: "minecraft:air"},
56+
{pos: [0, 2, 1], state: "minecraft:air"},
57+
{pos: [0, 2, 2], state: "minecraft:air"},
58+
{pos: [0, 2, 3], state: "minecraft:air"},
59+
{pos: [0, 2, 4], state: "minecraft:air"},
60+
{pos: [1, 2, 0], state: "minecraft:air"},
61+
{pos: [1, 2, 1], state: "minecraft:air"},
62+
{pos: [1, 2, 2], state: "minecraft:air"},
63+
{pos: [1, 2, 3], state: "minecraft:air"},
64+
{pos: [1, 2, 4], state: "minecraft:air"},
65+
{pos: [2, 2, 0], state: "minecraft:air"},
66+
{pos: [2, 2, 1], state: "minecraft:air"},
67+
{pos: [2, 2, 2], state: "minecraft:air"},
68+
{pos: [2, 2, 3], state: "minecraft:air"},
69+
{pos: [2, 2, 4], state: "minecraft:air"},
70+
{pos: [3, 2, 0], state: "minecraft:air"},
71+
{pos: [3, 2, 1], state: "minecraft:air"},
72+
{pos: [3, 2, 2], state: "minecraft:air"},
73+
{pos: [3, 2, 3], state: "minecraft:air"},
74+
{pos: [3, 2, 4], state: "minecraft:air"},
75+
{pos: [4, 2, 0], state: "minecraft:air"},
76+
{pos: [4, 2, 1], state: "minecraft:air"},
77+
{pos: [4, 2, 2], state: "minecraft:air"},
78+
{pos: [4, 2, 3], state: "minecraft:air"},
79+
{pos: [4, 2, 4], state: "minecraft:air"},
80+
{pos: [0, 3, 0], state: "minecraft:air"},
81+
{pos: [0, 3, 1], state: "minecraft:air"},
82+
{pos: [0, 3, 2], state: "minecraft:air"},
83+
{pos: [0, 3, 3], state: "minecraft:air"},
84+
{pos: [0, 3, 4], state: "minecraft:air"},
85+
{pos: [1, 3, 0], state: "minecraft:air"},
86+
{pos: [1, 3, 1], state: "minecraft:air"},
87+
{pos: [1, 3, 2], state: "minecraft:air"},
88+
{pos: [1, 3, 3], state: "minecraft:air"},
89+
{pos: [1, 3, 4], state: "minecraft:air"},
90+
{pos: [2, 3, 0], state: "minecraft:air"},
91+
{pos: [2, 3, 1], state: "minecraft:air"},
92+
{pos: [2, 3, 2], state: "minecraft:air"},
93+
{pos: [2, 3, 3], state: "minecraft:air"},
94+
{pos: [2, 3, 4], state: "minecraft:air"},
95+
{pos: [3, 3, 0], state: "minecraft:air"},
96+
{pos: [3, 3, 1], state: "minecraft:air"},
97+
{pos: [3, 3, 2], state: "minecraft:air"},
98+
{pos: [3, 3, 3], state: "minecraft:air"},
99+
{pos: [3, 3, 4], state: "minecraft:air"},
100+
{pos: [4, 3, 0], state: "minecraft:air"},
101+
{pos: [4, 3, 1], state: "minecraft:air"},
102+
{pos: [4, 3, 2], state: "minecraft:air"},
103+
{pos: [4, 3, 3], state: "minecraft:air"},
104+
{pos: [4, 3, 4], state: "minecraft:air"},
105+
{pos: [0, 4, 0], state: "minecraft:air"},
106+
{pos: [0, 4, 1], state: "minecraft:air"},
107+
{pos: [0, 4, 2], state: "minecraft:air"},
108+
{pos: [0, 4, 3], state: "minecraft:air"},
109+
{pos: [0, 4, 4], state: "minecraft:air"},
110+
{pos: [1, 4, 0], state: "minecraft:air"},
111+
{pos: [1, 4, 1], state: "minecraft:air"},
112+
{pos: [1, 4, 2], state: "minecraft:air"},
113+
{pos: [1, 4, 3], state: "minecraft:air"},
114+
{pos: [1, 4, 4], state: "minecraft:air"},
115+
{pos: [2, 4, 0], state: "minecraft:air"},
116+
{pos: [2, 4, 1], state: "minecraft:air"},
117+
{pos: [2, 4, 2], state: "minecraft:air"},
118+
{pos: [2, 4, 3], state: "minecraft:air"},
119+
{pos: [2, 4, 4], state: "minecraft:air"},
120+
{pos: [3, 4, 0], state: "minecraft:air"},
121+
{pos: [3, 4, 1], state: "minecraft:air"},
122+
{pos: [3, 4, 2], state: "minecraft:air"},
123+
{pos: [3, 4, 3], state: "minecraft:air"},
124+
{pos: [3, 4, 4], state: "minecraft:air"},
125+
{pos: [4, 4, 0], state: "minecraft:air"},
126+
{pos: [4, 4, 1], state: "minecraft:air"},
127+
{pos: [4, 4, 2], state: "minecraft:air"},
128+
{pos: [4, 4, 3], state: "minecraft:air"},
129+
{pos: [4, 4, 4], state: "minecraft:air"}
130+
],
131+
entities: [],
132+
palette: [
133+
"minecraft:polished_andesite",
134+
"minecraft:air",
135+
"computercraft:computer_advanced{facing:west,state:on}",
136+
"advancedperipherals:chat_box{orientation:west_up}"
137+
]
138+
}

0 commit comments

Comments
 (0)