Add full tests

This commit is contained in:
Dean Herbert 2018-12-07 14:00:16 +09:00
parent 2f9de149dd
commit d42c45c87e
1 changed files with 31 additions and 34 deletions

View File

@ -4,15 +4,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.MathUtils;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.Chat;
using osu.Game.Overlays.Chat.Tabs;
using osu.Game.Users;
@ -74,50 +71,50 @@ public TestCaseChannelTabControl()
channelTabControl.OnRequestLeave += channel => channelTabControl.RemoveChannel(channel);
channelTabControl.Current.ValueChanged += channel => currentText.Text = "Currently selected channel: " + channel.ToString();
AddStep("Add random private channel", addRandomUser);
AddStep("Add random private channel", addRandomPrivateChannel);
AddAssert("There is only one channels", () => channelTabControl.Items.Count() == 2);
AddRepeatStep("Add 3 random private channels", addRandomUser, 3);
AddRepeatStep("Add 3 random private channels", addRandomPrivateChannel, 3);
AddAssert("There are four channels", () => channelTabControl.Items.Count() == 5);
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())), 20);
}
AddRepeatStep("Select a random channel", () => channelTabControl.Current.Value = channelTabControl.Items.ElementAt(RNG.Next(channelTabControl.Items.Count() - 1)), 20);
private List<User> users;
Channel channelBefore = channelTabControl.Items.First();
AddStep("set first channel", () => channelTabControl.Current.Value = channelBefore);
private void addRandomUser()
{
channelTabControl.AddChannel(new Channel
AddStep("select selector tab", () => channelTabControl.Current.Value = channelTabControl.Items.Last());
AddAssert("selector tab is active", () => channelTabControl.ChannelSelectorActive.Value);
AddAssert("check channel unchanged", () => channelBefore == channelTabControl.Current.Value);
AddStep("set second channel", () => channelTabControl.Current.Value = channelTabControl.Items.Skip(1).First());
AddAssert("selector tab is inactive", () => !channelTabControl.ChannelSelectorActive.Value);
AddUntilStep(() =>
{
Users =
{
users?.Count > 0
? users[RNG.Next(0, users.Count - 1)]
: new User
{
Id = RNG.Next(),
Username = "testuser" + RNG.Next(1000)
}
}
});
var first = channelTabControl.Items.First();
if (first.Name == "+")
return true;
channelTabControl.RemoveChannel(first);
return false;
}, "remove all channels");
AddAssert("selector tab is active", () => channelTabControl.ChannelSelectorActive.Value);
}
private void addChannel(string name)
{
private void addRandomPrivateChannel() =>
channelTabControl.AddChannel(new Channel(new User
{
Id = RNG.Next(1000, 10000000),
Username = "Test User " + RNG.Next(1000)
}));
private void addChannel(string name) =>
channelTabControl.AddChannel(new Channel
{
Type = ChannelType.Public,
Name = name
});
}
[BackgroundDependencyLoader]
private void load(IAPIProvider api)
{
GetUsersRequest req = new GetUsersRequest();
req.Success += list => users = list.Select(e => e.User).ToList();
api.Queue(req);
}
}
}