From 8cc8f2500e8f58e7f14922871b6c7151ea11984c Mon Sep 17 00:00:00 2001 From: Silthus Date: Sun, 27 Feb 2022 06:42:44 +0100 Subject: [PATCH] test: adjust ui to new minimessage format --- .../schat/platform/config/ConfigTests.java | 9 +++++---- .../ui/format/MiniMessageFormatTest.java | 6 +++--- .../views/tabbed/TabbedChannelsViewTests.java | 20 +++++++++---------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/platform/src/test/java/net/silthus/schat/platform/config/ConfigTests.java b/platform/src/test/java/net/silthus/schat/platform/config/ConfigTests.java index 5cd802608..22c4fd4d1 100644 --- a/platform/src/test/java/net/silthus/schat/platform/config/ConfigTests.java +++ b/platform/src/test/java/net/silthus/schat/platform/config/ConfigTests.java @@ -28,7 +28,6 @@ import java.util.Optional; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; -import net.kyori.adventure.text.minimessage.MiniMessage; import net.silthus.schat.channel.Channel; import net.silthus.schat.chatter.ChatterMock; import net.silthus.schat.commands.CreatePrivateChannelCommand; @@ -42,8 +41,11 @@ import org.junit.jupiter.api.io.TempDir; import static net.kyori.adventure.text.Component.text; +import static net.kyori.adventure.text.format.NamedTextColor.AQUA; import static net.kyori.adventure.text.format.NamedTextColor.GRAY; +import static net.kyori.adventure.text.format.NamedTextColor.GREEN; import static net.kyori.adventure.text.format.NamedTextColor.YELLOW; +import static net.kyori.adventure.text.format.TextDecoration.UNDERLINED; import static net.silthus.schat.channel.ChannelHelper.channelWith; import static net.silthus.schat.channel.ChannelRepository.createInMemoryChannelRepository; import static net.silthus.schat.channel.ChannelSettings.PROTECTED; @@ -62,7 +64,6 @@ class ConfigTests { - private static final MiniMessage FORMATTER = MiniMessage.miniMessage(); private SChatConfig config; @BeforeEach @@ -118,7 +119,7 @@ void set_values_writes_and_loads_when_reloaded() { void loads_custom_private_chat_message_format() { final Component format = config.get(VIEW_CONFIG).format().get(MESSAGE_FORMAT) .format(View.empty(), message("Hey").source(identity("Bob")).create()); - assertThat(FORMATTER.serialize(format)).isEqualTo("[Bob]: Hey"); + assertThat(format).isEqualTo(text().append(text("[Bob]", AQUA)).append(text(": Hey")).build()); } @Test @@ -132,7 +133,7 @@ void uses_default_format_if_no_config_is_set() { final Tab tab = mock(Tab.class); when(tab.get(Tab.CHANNEL)).thenReturn(Optional.of(channel)); final Component format = config.get(VIEW_CONFIG).privateChatFormat().get(ACTIVE_TAB_FORMAT).format(view, tab); - assertThat(FORMATTER.serialize(format)).isEqualTo("Karl"); + assertThat(format).isEqualTo(text("Karl", GREEN, UNDERLINED)); } } } diff --git a/ui/src/test/java/net/silthus/schat/ui/format/MiniMessageFormatTest.java b/ui/src/test/java/net/silthus/schat/ui/format/MiniMessageFormatTest.java index b7acd3355..fc1ed48a0 100644 --- a/ui/src/test/java/net/silthus/schat/ui/format/MiniMessageFormatTest.java +++ b/ui/src/test/java/net/silthus/schat/ui/format/MiniMessageFormatTest.java @@ -61,7 +61,7 @@ void simple_text_only_message() { void formatted_text_message() { assertFormat("", message(text("Hi").append(text(" there!", RED, BOLD))), - "Hi there!" + "Hi there!" ); } @@ -69,7 +69,7 @@ void formatted_text_message() { void message_without_source_but_source_format() { assertFormat(": ", message("Hey"), - ": Hey" + "\\: Hey" ); } @@ -89,7 +89,7 @@ void formats_complex_message() { assertFormat("() : ", message, - "(Test) Bobby: Hey @Silthus" + "(Test) Bobby: Hey @Silthus" ); } } diff --git a/ui/src/test/java/net/silthus/schat/ui/views/tabbed/TabbedChannelsViewTests.java b/ui/src/test/java/net/silthus/schat/ui/views/tabbed/TabbedChannelsViewTests.java index 80016a0cb..7a1dcd296 100644 --- a/ui/src/test/java/net/silthus/schat/ui/views/tabbed/TabbedChannelsViewTests.java +++ b/ui/src/test/java/net/silthus/schat/ui/views/tabbed/TabbedChannelsViewTests.java @@ -134,15 +134,15 @@ private void assertTextDoesNotContain(String... unexpected) { } private void assertViewRenders(String expected) { - assertEquals(expected, COMPONENT_SERIALIZER.serialize(view.render()).trim()); + assertEquals(expected, COMPONENT_SERIALIZER.serialize(view.render()).replaceAll("

", "\n").trim()); } private void assertViewDoesNotContain(String... unexpected) { - assertThat(COMPONENT_SERIALIZER.serialize(view.render()).trim()).doesNotContain(unexpected); + assertThat(COMPONENT_SERIALIZER.serialize(view.render()).replaceAll("

", "\n").trim()).doesNotContain(unexpected); } private void assertViewContains(String... expected) { - assertThat(COMPONENT_SERIALIZER.serialize(view.render()).trim()).contains(expected); + assertThat(COMPONENT_SERIALIZER.serialize(view.render()).replaceAll("

", "\n").trim()).contains(expected); } private void assertColorOnlyViewContains(String... expected) { @@ -213,7 +213,7 @@ void renders_both_messages() { sendMessageWithSource("Silthus", "Yo"); assertViewRenders(""" Hey - Silthus: Yo""" + Silthus: Yo
""" ); } } @@ -257,7 +257,7 @@ void setUp() { @Test void underlines_channel() { - assertViewRenders("| test\\\">\">test |"); + assertViewRenders("| test'>\">❌test |"); } @Nested @@ -271,7 +271,7 @@ void setUp() { @Test void uses_custom_format() { - assertViewRenders("| test\\\">\">test |"); + assertViewRenders("| test'>\">❌test |"); } } } @@ -285,7 +285,7 @@ void setUp() { @Test void then_channel_click_executes_join_command() { - assertViewContains("test"); + assertViewContains(""); } } @@ -330,8 +330,8 @@ void displays_private_messages() throws InterruptedException { Thread.sleep(1L); sendPrivateMessage(target, chatter, text("Hey back")); assertViewContains(""" - : Hi - target: Hey back"""); + : Hi + target: Hey back"""); } } @@ -464,7 +464,7 @@ void renders_full_view() { No Source! Player: Hey Player2: Hello - | zzz\\">">zzz | aaa\\">">aaa |"""); + | zzz'>">❌zzz | aaa'>">❌">aaa |"""); } }