Skip to content

Commit

Permalink
Ensure joined channels are actually joined to avoid unexpected tab order
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Jun 28, 2022
1 parent d630b62 commit 21d31ee
Showing 1 changed file with 40 additions and 31 deletions.
71 changes: 40 additions & 31 deletions osu.Game.Tests/Visual/Online/TestSceneChatOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class TestSceneChatOverlay : OsuManualInputManagerTestScene
private ChannelManager channelManager;

private APIUser testUser;
private Channel testPMChannel;
private Channel[] testChannels;

private Channel testChannel1 => testChannels[0];
Expand All @@ -53,7 +52,6 @@ public class TestSceneChatOverlay : OsuManualInputManagerTestScene
public void SetUp() => Schedule(() =>
{
testUser = new APIUser { Username = "test user", Id = 5071479 };
testPMChannel = new Channel(testUser);
testChannels = Enumerable.Range(1, 10).Select(createPublicChannel).ToArray();

Child = new DependencyProvidingContainer
Expand Down Expand Up @@ -181,7 +179,7 @@ public void TestChannelSelection()
{
AddStep("Show overlay", () => chatOverlay.Show());
AddAssert("Listing is visible", () => listingIsVisible);
AddStep("Join channel 1", () => channelManager.JoinChannel(testChannel1));
joinTestChannel(0);
AddStep("Select channel 1", () => clickDrawable(getChannelListItem(testChannel1)));
waitForChannel1Visible();
}
Expand All @@ -203,12 +201,11 @@ public void TestSearchInListing()
[Test]
public void TestChannelCloseButton()
{
var testPMChannel = new Channel(testUser);

AddStep("Show overlay", () => chatOverlay.Show());
AddStep("Join PM and public channels", () =>
{
channelManager.JoinChannel(testChannel1);
channelManager.JoinChannel(testPMChannel);
});
joinTestChannel(0);
joinChannel(testPMChannel);
AddStep("Select PM channel", () => clickDrawable(getChannelListItem(testPMChannel)));
AddStep("Click close button", () =>
{
Expand All @@ -229,7 +226,7 @@ public void TestChannelCloseButton()
public void TestChatCommand()
{
AddStep("Show overlay", () => chatOverlay.Show());
AddStep("Join channel 1", () => channelManager.JoinChannel(testChannel1));
joinTestChannel(0);
AddStep("Select channel 1", () => clickDrawable(getChannelListItem(testChannel1)));
AddStep("Open chat with user", () => channelManager.PostCommand($"chat {testUser.Username}"));
AddAssert("PM channel is selected", () =>
Expand All @@ -248,14 +245,16 @@ public void TestChatCommand()
[Test]
public void TestMultiplayerChannelIsNotShown()
{
Channel multiplayerChannel = null;
Channel multiplayerChannel;

AddStep("Show overlay", () => chatOverlay.Show());
AddStep("Join multiplayer channel", () => channelManager.JoinChannel(multiplayerChannel = new Channel(new APIUser())

joinChannel(multiplayerChannel = new Channel(new APIUser())
{
Name = "#mp_1",
Type = ChannelType.Multiplayer,
}));
});

AddAssert("Channel is joined", () => channelManager.JoinedChannels.Contains(multiplayerChannel));
AddUntilStep("Channel not present in listing", () => !chatOverlay.ChildrenOfType<ChannelListingItem>()
.Where(item => item.IsPresent)
Expand All @@ -269,7 +268,7 @@ public void TestHighlightOnCurrentChannel()
Message message = null;

AddStep("Show overlay", () => chatOverlay.Show());
AddStep("Join channel 1", () => channelManager.JoinChannel(testChannel1));
joinTestChannel(0);
AddStep("Select channel 1", () => clickDrawable(getChannelListItem(testChannel1)));
AddStep("Send message in channel 1", () =>
{
Expand All @@ -291,8 +290,8 @@ public void TestHighlightOnAnotherChannel()
Message message = null;

AddStep("Show overlay", () => chatOverlay.Show());
AddStep("Join channel 1", () => channelManager.JoinChannel(testChannel1));
AddStep("Join channel 2", () => channelManager.JoinChannel(testChannel2));
joinTestChannel(0);
joinTestChannel(1);
AddStep("Select channel 1", () => clickDrawable(getChannelListItem(testChannel1)));
AddStep("Send message in channel 2", () =>
{
Expand All @@ -314,8 +313,8 @@ public void TestHighlightOnLeftChannel()
Message message = null;

AddStep("Show overlay", () => chatOverlay.Show());
AddStep("Join channel 1", () => channelManager.JoinChannel(testChannel1));
AddStep("Join channel 2", () => channelManager.JoinChannel(testChannel2));
joinTestChannel(0);
joinTestChannel(1);
AddStep("Select channel 1", () => clickDrawable(getChannelListItem(testChannel1)));
AddStep("Send message in channel 2", () =>
{
Expand All @@ -337,7 +336,7 @@ public void TestHighlightWhileChatNeverOpen()
{
Message message = null;

AddStep("Join channel 1", () => channelManager.JoinChannel(testChannel1));
joinTestChannel(0);
AddStep("Send message in channel 1", () =>
{
testChannel1.AddNewMessages(message = new Message
Expand All @@ -357,7 +356,7 @@ public void TestHighlightWithNullChannel()
{
Message message = null;

AddStep("Join channel 1", () => channelManager.JoinChannel(testChannel1));
joinTestChannel(0);
AddStep("Send message in channel 1", () =>
{
testChannel1.AddNewMessages(message = new Message
Expand All @@ -378,7 +377,7 @@ public void TestTextBoxRetainsFocus()
{
AddStep("Show overlay", () => chatOverlay.Show());
AddAssert("TextBox is focused", () => InputManager.FocusedDrawable == chatOverlayTextBox);
AddStep("Join channel 1", () => channelManager.JoinChannel(testChannel1));
joinTestChannel(0);
AddStep("Select channel 1", () => clickDrawable(getChannelListItem(testChannel1)));
waitForChannel1Visible();
AddAssert("TextBox is focused", () => InputManager.FocusedDrawable == chatOverlayTextBox);
Expand All @@ -404,11 +403,11 @@ public void TestSlowLoadingChannel()
chatOverlay.Show();
chatOverlay.SlowLoading = true;
});
AddStep("Join channel 1", () => channelManager.JoinChannel(testChannel1));
joinTestChannel(0);
AddStep("Select channel 1", () => clickDrawable(getChannelListItem(testChannel1)));
AddUntilStep("Channel 1 loading", () => !channelIsVisible && chatOverlay.GetSlowLoadingChannel(testChannel1).LoadState == LoadState.Loading);

AddStep("Join channel 2", () => channelManager.JoinChannel(testChannel2));
joinTestChannel(1);
AddStep("Select channel 2", () => clickDrawable(getChannelListItem(testChannel2)));
AddUntilStep("Channel 2 loading", () => !channelIsVisible && chatOverlay.GetSlowLoadingChannel(testChannel2).LoadState == LoadState.Loading);

Expand Down Expand Up @@ -461,15 +460,13 @@ public void TestKeyboardNextChannel()
Channel pmChannel1 = createPrivateChannel();
Channel pmChannel2 = createPrivateChannel();

AddStep("Show overlay with channels", () =>
{
channelManager.JoinChannel(testChannel1);
channelManager.JoinChannel(testChannel2);
channelManager.JoinChannel(pmChannel1);
channelManager.JoinChannel(pmChannel2);
channelManager.JoinChannel(announceChannel);
chatOverlay.Show();
});
joinTestChannel(0);
joinTestChannel(1);
joinChannel(pmChannel1);
joinChannel(pmChannel2);
joinChannel(announceChannel);

AddStep("Show overlay", () => chatOverlay.Show());

AddStep("Select channel 1", () => clickDrawable(getChannelListItem(testChannel1)));
waitForChannel1Visible();
Expand All @@ -490,6 +487,18 @@ public void TestKeyboardNextChannel()
waitForChannel1Visible();
}

private void joinTestChannel(int i)
{
AddStep($"Join test channel {i}", () => channelManager.JoinChannel(testChannels[i]));
AddUntilStep("wait for join completed", () => testChannels[i].Joined.Value);
}

private void joinChannel(Channel channel)
{
AddStep($"Join channel {channel}", () => channelManager.JoinChannel(channel));
AddUntilStep("wait for join completed", () => channel.Joined.Value);
}

private void waitForChannel1Visible() =>
AddUntilStep("Channel 1 is visible", () => channelIsVisible && currentDrawableChannel?.Channel == testChannel1);

Expand Down

0 comments on commit 21d31ee

Please sign in to comment.