Skip to content

Commit

Permalink
fix(cmd): reload not removing console target from channel if `console…
Browse files Browse the repository at this point in the history
…: false`
  • Loading branch information
Silthus committed Nov 15, 2021
1 parent d3d0211 commit f77794f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/main/java/net/silthus/chat/conversations/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ public void setConfig(ChannelConfig config) {
this.config = config;
if (config.name() != null)
setDisplayName(Component.text(config.name()));

if (config.sendToConsole())
addTarget(Console.console());
else
removeTarget(Console.console());

setFormat(config.format());
}

Expand Down
43 changes: 39 additions & 4 deletions src/test/java/net/silthus/chat/identities/ChannelTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package net.silthus.chat.identities;

import be.seeseemelk.mockbukkit.entity.PlayerMock;
import net.kyori.adventure.text.Component;
import net.silthus.chat.*;
import net.silthus.chat.config.ChannelConfig;
import net.silthus.chat.conversations.Channel;
Expand All @@ -31,6 +30,7 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import static net.kyori.adventure.text.Component.text;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
Expand Down Expand Up @@ -60,7 +60,7 @@ void create() {
Constants.Permissions.CHANNEL_PERMISSION + ".test"
);
assertThat(channel.getDisplayName())
.isEqualTo(Component.text("test"));
.isEqualTo(text("test"));
assertThat(channel.getConfig())
.extracting(ChannelConfig::name)
.isEqualTo(null);
Expand Down Expand Up @@ -226,7 +226,7 @@ void sendMessage_storesLastMessage() {
.extracting(
m -> m.getSource().getDisplayName()
).isEqualTo(
Component.text("Player1")
text("Player1")
);
} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -434,6 +434,41 @@ void close_unsubscribesAllTargets() {
assertThat(chatter.getConversations()).doesNotContain(channel);
}

@Test
void setConfig_changesDisplayName() {
final Channel channel = createChannel(config -> config.name("Test 123"));
channel.setConfig(ChannelConfig.builder().name("Foobar").build());

assertThat(channel.getDisplayName()).isEqualTo(text("Foobar"));
}

@Test
void setConfig_removeConsoleSender() {
final Channel channel = createChannel(config -> config.sendToConsole(true));
assertThat(channel.getTargets()).contains(Console.console());

channel.setConfig(ChannelConfig.builder().sendToConsole(false).build());
assertThat(channel.getTargets()).doesNotContain(Console.console());
}

@Test
void setConfig_addsConsoleSender() {
final Channel channel = createChannel(config -> config.sendToConsole(false));
assertThat(channel.getTargets()).doesNotContain(Console.console());

channel.setConfig(ChannelConfig.builder().sendToConsole(true).build());
assertThat(channel.getTargets()).contains(Console.console());
}

@Test
void setConfig_updatesChannelFormat() {
final Channel channel = createChannel(config -> config.format(Format.noFormat()));
assertThat(channel.getFormat()).isEqualTo(Format.noFormat());

channel.setConfig(ChannelConfig.builder().format(Format.channelFormat()).build());
assertThat(channel.getFormat()).isEqualTo(Format.channelFormat());
}

@Nested
@DisplayName("with config")
class WithConfig {
Expand All @@ -450,7 +485,7 @@ void createFromConfig() {

Channel channel = Channel.channel("config-test", ChannelConfig.of(cfg));

assertThat(channel.getDisplayName()).isEqualTo(Component.text("Test"));
assertThat(channel.getDisplayName()).isEqualTo(text("Test"));
assertThat(channel.getConfig())
.extracting(
ChannelConfig::format,
Expand Down

0 comments on commit f77794f

Please sign in to comment.