mirror of
https://github.com/osukey/osukey.git
synced 2025-06-07 20:37:57 +09:00
Merge branch 'fix-channeltabcontrol-test' into update-framework
This commit is contained in:
commit
9709b80c88
@ -5,6 +5,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
@ -25,7 +26,7 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
typeof(ChannelTabControl),
|
typeof(ChannelTabControl),
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly ChannelTabControl channelTabControl;
|
private readonly TestTabControl channelTabControl;
|
||||||
|
|
||||||
public TestSceneChannelTabControl()
|
public TestSceneChannelTabControl()
|
||||||
{
|
{
|
||||||
@ -37,7 +38,7 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
channelTabControl = new ChannelTabControl
|
channelTabControl = new TestTabControl
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
@ -73,32 +74,40 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
channelTabControl.Current.ValueChanged += channel => currentText.Text = "Currently selected channel: " + channel.NewValue;
|
channelTabControl.Current.ValueChanged += channel => currentText.Text = "Currently selected channel: " + channel.NewValue;
|
||||||
|
|
||||||
AddStep("Add random private channel", addRandomPrivateChannel);
|
AddStep("Add random private channel", addRandomPrivateChannel);
|
||||||
AddAssert("There is only one channels", () => channelTabControl.Items.Count() == 2);
|
AddAssert("There is only one channels", () => channelTabControl.Items.Count == 2);
|
||||||
AddRepeatStep("Add 3 random private channels", addRandomPrivateChannel, 3);
|
AddRepeatStep("Add 3 random private channels", addRandomPrivateChannel, 3);
|
||||||
AddAssert("There are four channels", () => channelTabControl.Items.Count() == 5);
|
AddAssert("There are four channels", () => channelTabControl.Items.Count == 5);
|
||||||
AddStep("Add random public channel", () => addChannel(RNG.Next().ToString()));
|
AddStep("Add random public channel", () => addChannel(RNG.Next().ToString()));
|
||||||
|
|
||||||
AddRepeatStep("Select a random channel", () => channelTabControl.Current.Value = channelTabControl.Items.ElementAt(RNG.Next(channelTabControl.Items.Count() - 1)), 20);
|
AddRepeatStep("Select a random channel", () =>
|
||||||
|
{
|
||||||
|
List<Channel> validChannels = channelTabControl.Items.Where(c => !(c is ChannelSelectorTabItem.ChannelSelectorTabChannel)).ToList();
|
||||||
|
channelTabControl.SelectChannel(validChannels[RNG.Next(0, validChannels.Count)]);
|
||||||
|
}, 20);
|
||||||
|
|
||||||
Channel channelBefore = channelTabControl.Items.First();
|
Channel channelBefore = null;
|
||||||
AddStep("set first channel", () => channelTabControl.Current.Value = channelBefore);
|
AddStep("set first channel", () => channelTabControl.SelectChannel(channelBefore = channelTabControl.Items.First(c => !(c is ChannelSelectorTabItem.ChannelSelectorTabChannel))));
|
||||||
|
|
||||||
AddStep("select selector tab", () => channelTabControl.Current.Value = channelTabControl.Items.Last());
|
AddStep("select selector tab", () => channelTabControl.SelectChannel(channelTabControl.Items.Single(c => c is ChannelSelectorTabItem.ChannelSelectorTabChannel)));
|
||||||
AddAssert("selector tab is active", () => channelTabControl.ChannelSelectorActive.Value);
|
AddAssert("selector tab is active", () => channelTabControl.ChannelSelectorActive.Value);
|
||||||
|
|
||||||
AddAssert("check channel unchanged", () => channelBefore == channelTabControl.Current.Value);
|
AddAssert("check channel unchanged", () => channelBefore == channelTabControl.Current.Value);
|
||||||
|
|
||||||
AddStep("set second channel", () => channelTabControl.Current.Value = channelTabControl.Items.Skip(1).First());
|
AddStep("set second channel", () => channelTabControl.SelectChannel(channelTabControl.Items.GetNext(channelBefore)));
|
||||||
AddAssert("selector tab is inactive", () => !channelTabControl.ChannelSelectorActive.Value);
|
AddAssert("selector tab is inactive", () => !channelTabControl.ChannelSelectorActive.Value);
|
||||||
|
|
||||||
AddUntilStep("remove all channels", () =>
|
AddUntilStep("remove all channels", () =>
|
||||||
{
|
{
|
||||||
var first = channelTabControl.Items.First();
|
foreach (var item in channelTabControl.Items.ToList())
|
||||||
if (first is ChannelSelectorTabItem.ChannelSelectorTabChannel)
|
{
|
||||||
return true;
|
if (item is ChannelSelectorTabItem.ChannelSelectorTabChannel)
|
||||||
|
continue;
|
||||||
|
|
||||||
channelTabControl.RemoveChannel(first);
|
channelTabControl.RemoveChannel(item);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert("selector tab is active", () => channelTabControl.ChannelSelectorActive.Value);
|
AddAssert("selector tab is active", () => channelTabControl.ChannelSelectorActive.Value);
|
||||||
@ -117,5 +126,10 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
Type = ChannelType.Public,
|
Type = ChannelType.Public,
|
||||||
Name = name
|
Name = name
|
||||||
});
|
});
|
||||||
|
|
||||||
|
private class TestTabControl : ChannelTabControl
|
||||||
|
{
|
||||||
|
public void SelectChannel(Channel channel) => base.SelectTab(TabMap[channel]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,10 @@ namespace osu.Game.Overlays.Chat.Tabs
|
|||||||
RemoveItem(channel);
|
RemoveItem(channel);
|
||||||
|
|
||||||
if (Current.Value == channel)
|
if (Current.Value == channel)
|
||||||
Current.Value = Items.FirstOrDefault();
|
{
|
||||||
|
// Prefer non-selector channels first
|
||||||
|
Current.Value = Items.FirstOrDefault(c => !(c is ChannelSelectorTabItem.ChannelSelectorTabChannel)) ?? Items.FirstOrDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SelectTab(TabItem<Channel> tab)
|
protected override void SelectTab(TabItem<Channel> tab)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user