1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 00:27:25 +08:00
osu-lazer/osu.Game.Tests/Visual/TestCaseMatchSettingsOverlay.cs

160 lines
5.2 KiB
C#
Raw Normal View History

2018-12-22 13:48:15 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2018-12-22 14:00:35 +08:00
using System;
using System.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
2018-12-22 13:48:15 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
2018-12-26 17:38:58 +08:00
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
2018-12-22 13:48:15 +08:00
using osu.Game.Online.Multiplayer;
using osu.Game.Screens.Multi;
using osu.Game.Screens.Multi.Lounge.Components;
2018-12-22 13:48:15 +08:00
using osu.Game.Screens.Multi.Match.Components;
namespace osu.Game.Tests.Visual
{
public class TestCaseMatchSettingsOverlay : OsuTestCase
{
2018-12-22 14:00:35 +08:00
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(MatchSettingsOverlay)
2018-12-22 14:00:35 +08:00
};
[Cached(Type = typeof(IRoomManager))]
private TestRoomManager roomManager = new TestRoomManager();
private Room room;
private TestRoomSettings settings;
[SetUp]
public void Setup() => Schedule(() =>
2018-12-22 13:48:15 +08:00
{
room = new Room();
settings = new TestRoomSettings(room)
2018-12-22 13:48:15 +08:00
{
RelativeSizeAxes = Axes.Both,
State = Visibility.Visible
};
Child = settings;
});
[Test]
public void TestButtonEnabledOnlyWithNameAndBeatmap()
{
AddStep("clear name and beatmap", () =>
{
room.Name.Value = "";
room.Playlist.Clear();
});
AddAssert("button disabled", () => !settings.ApplyButton.Enabled);
AddStep("set name", () => room.Name.Value = "Room name");
AddAssert("button disabled", () => !settings.ApplyButton.Enabled);
AddStep("set beatmap", () => room.Playlist.Add(new PlaylistItem { Beatmap = new DummyWorkingBeatmap().BeatmapInfo }));
AddAssert("button enabled", () => settings.ApplyButton.Enabled);
AddStep("clear name", () => room.Name.Value = "");
AddAssert("button disabled", () => !settings.ApplyButton.Enabled);
}
[Test]
public void TestCorrectSettingsApplied()
{
const string expected_name = "expected name";
TimeSpan expectedDuration = TimeSpan.FromMinutes(15);
Room createdRoom = null;
AddStep("setup", () =>
{
settings.NameField.Current.Value = expected_name;
settings.DurationField.Current.Value = expectedDuration;
2018-12-26 17:38:58 +08:00
roomManager.CreateRequested = r =>
{
createdRoom = r;
return true;
};
});
AddStep("create room", () => settings.ApplyButton.Action.Invoke());
AddAssert("has correct name", () => createdRoom.Name.Value == expected_name);
AddAssert("has correct duration", () => createdRoom.Duration.Value == expectedDuration);
}
2018-12-26 17:38:58 +08:00
[Test]
public void TestCreationFailureDisplaysError()
{
bool fail;
AddStep("setup", () =>
{
fail = true;
roomManager.CreateRequested = _ => !fail;
});
AddAssert("error not displayed", () => !settings.ErrorText.IsPresent);
AddStep("create room", () => settings.ApplyButton.Action.Invoke());
AddAssert("error displayed", () => settings.ErrorText.IsPresent);
AddAssert("error has correct text", () => settings.ErrorText.Text == TestRoomManager.FAILED_TEXT);
AddStep("create room no fail", () =>
{
fail = false;
settings.ApplyButton.Action.Invoke();
});
AddUntilStep(() => !settings.ErrorText.IsPresent, "error not displayed");
}
2018-12-26 19:33:49 +08:00
private class TestRoomSettings : MatchSettingsOverlay
{
public new TriangleButton ApplyButton => base.ApplyButton;
public new OsuTextBox NameField => base.NameField;
public new OsuDropdown<TimeSpan> DurationField => base.DurationField;
2018-12-26 17:38:58 +08:00
public new OsuSpriteText ErrorText => base.ErrorText;
public TestRoomSettings(Room room)
: base(room)
{
}
}
private class TestRoomManager : IRoomManager
{
2018-12-26 17:38:58 +08:00
public const string FAILED_TEXT = "failed";
public Func<Room, bool> CreateRequested;
public IBindableCollection<Room> Rooms { get; } = null;
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
2018-12-26 17:38:58 +08:00
{
if (CreateRequested == null)
return;
if (!CreateRequested.Invoke(room))
onError?.Invoke(FAILED_TEXT);
else
onSuccess?.Invoke(room);
2018-12-26 17:38:58 +08:00
}
public void JoinRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null) => throw new NotImplementedException();
public void PartRoom() => throw new NotImplementedException();
public void Filter(FilterCriteria criteria) => throw new NotImplementedException();
2018-12-22 13:48:15 +08:00
}
}
}