Skip to content

Commit

Permalink
test: adjust ui to new minimessage format
Browse files Browse the repository at this point in the history
  • Loading branch information
Silthus committed Feb 27, 2022
1 parent f8901ce commit 8cc8f25
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -62,7 +64,6 @@

class ConfigTests {

private static final MiniMessage FORMATTER = MiniMessage.miniMessage();
private SChatConfig config;

@BeforeEach
Expand Down Expand Up @@ -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("<aqua>[Bob]</aqua>: Hey");
assertThat(format).isEqualTo(text().append(text("[Bob]", AQUA)).append(text(": Hey")).build());
}

@Test
Expand All @@ -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("<green><underlined>Karl");
assertThat(format).isEqualTo(text("Karl", GREEN, UNDERLINED));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ void simple_text_only_message() {
void formatted_text_message() {
assertFormat("<gray><text>",
message(text("Hi").append(text(" there!", RED, BOLD))),
"<gray>Hi</gray><red><bold> there!"
"<gray>Hi<bold><red> there!"
);
}

@Test
void message_without_source_but_source_format() {
assertFormat("<source>: <text>",
message("Hey"),
"<source>: Hey"
"\\<source>: Hey"
);
}

Expand All @@ -89,7 +89,7 @@ void formats_complex_message() {

assertFormat("<aqua>(<source.active_channel.name><aqua>) <yellow><source.display_name><gray>: <text>",
message,
"<aqua>(</aqua><green>Test</green><aqua>) </aqua><yellow></yellow><dark_red>Bobby</dark_red><gray>: Hey </gray><red><bold>@Silthus"
"<aqua>(<green>Test</green>) <yellow><dark_red>Bobby</dark_red><gray>: Hey <bold><red>@Silthus"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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("<br></br>", "\n").trim());
}

private void assertViewDoesNotContain(String... unexpected) {
assertThat(COMPONENT_SERIALIZER.serialize(view.render()).trim()).doesNotContain(unexpected);
assertThat(COMPONENT_SERIALIZER.serialize(view.render()).replaceAll("<br></br>", "\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("<br></br>", "\n").trim()).contains(expected);
}

private void assertColorOnlyViewContains(String... expected) {
Expand Down Expand Up @@ -213,7 +213,7 @@ void renders_both_messages() {
sendMessageWithSource("Silthus", "Yo");
assertViewRenders("""
Hey
<yellow>Silthus</yellow><gray>: Yo</gray>"""
<yellow>Silthus<gray>: </gray><gray>Yo</gray></yellow><br>"""
);
}
}
Expand Down Expand Up @@ -257,7 +257,7 @@ void setUp() {

@Test
void underlines_channel() {
assertViewRenders("| <red><hover:show_text:\"<lang:schat.hover.leave-channel:\\\"<gray>test\\\">\"><click:run_command:\"/channel leave test\">❌</red><green><underlined>test</click></hover></underlined></green> |");
assertViewRenders("| <red><click:run_command:'/channel leave test'><hover:show_text:\"<lang:schat.hover.leave-channel:'<gray>test'>\">❌<underlined><green>test</green></underlined></hover></click></red> |");
}

@Nested
Expand All @@ -271,7 +271,7 @@ void setUp() {

@Test
void uses_custom_format() {
assertViewRenders("| <red><hover:show_text:\"<lang:schat.hover.leave-channel:\\\"<gray>test\\\">\"><click:run_command:\"/channel leave test\">❌<underlined>test</click></hover></underlined></red> |");
assertViewRenders("| <red><click:run_command:'/channel leave test'><hover:show_text:\"<lang:schat.hover.leave-channel:'<gray>test'>\">❌<underlined><red>test</red></underlined></hover></click></red> |");
}
}
}
Expand All @@ -285,7 +285,7 @@ void setUp() {

@Test
void then_channel_click_executes_join_command() {
assertViewContains("<click:run_command:\"/channel join test\">test</click>");
assertViewContains("<click:run_command:'/channel join test'>");
}
}

Expand Down Expand Up @@ -330,8 +330,8 @@ void displays_private_messages() throws InterruptedException {
Thread.sleep(1L);
sendPrivateMessage(target, chatter, text("Hey back"));
assertViewContains("""
<yellow><lang:schat.chat.message.you></yellow><gray>: Hi</gray>
<aqua>target</aqua><gray>: Hey back</gray>""");
<yellow><lang:schat.chat.message.you><gray>: </gray><gray>Hi</gray></lang></yellow>
<aqua>target<gray>: </gray><gray>Hey back</gray></aqua>""");
}
}

Expand Down Expand Up @@ -464,7 +464,7 @@ void renders_full_view() {
No Source!
Player: Hey
Player2: Hello
| <red><hover:show_text:"<lang:schat.hover.leave-channel:\\"<gray>zzz\\">"><click:run_command:"/channel leave zzz">❌</red><green><underlined>zzz</click></hover></underlined></green> | <red><hover:show_text:"<lang:schat.hover.leave-channel:\\"<gray>aaa\\">"><click:run_command:"/channel leave aaa">❌</click></red><gray><click:run_command:"/channel join aaa">aaa</click></hover></gray> |""");
| <red><click:run_command:'/channel leave zzz'><hover:show_text:"<lang:schat.hover.leave-channel:'<gray>zzz'>">❌<underlined><green>zzz</green></underlined></hover></click></red> | <red><click:run_command:'/channel leave aaa'><hover:show_text:"<lang:schat.hover.leave-channel:'<gray>aaa'>">❌<gray><click:run_command:'/channel join aaa'><hover:show_text:"<gray><lang:schat.hover.join-channel:'aaa'>">aaa</hover></click></gray></hover></click></red> |""");
}
}

Expand Down

0 comments on commit 8cc8f25

Please sign in to comment.