mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 02:22:56 +08:00
Combine similar tests
This commit is contained in:
parent
82cc6aa0c5
commit
54da8e4035
@ -3,24 +3,82 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
{
|
{
|
||||||
public class TestSceneStatefulMenuItem : OsuTestScene
|
public class TestSceneStatefulMenuItem : ManualInputManagerTestScene
|
||||||
{
|
{
|
||||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
{
|
{
|
||||||
typeof(OsuMenu),
|
typeof(OsuMenu),
|
||||||
typeof(StatefulMenuItem),
|
typeof(StatefulMenuItem),
|
||||||
typeof(DrawableStatefulMenuItem)
|
typeof(ThreeStateMenuItem),
|
||||||
|
typeof(DrawableStatefulMenuItem),
|
||||||
};
|
};
|
||||||
|
|
||||||
public TestSceneStatefulMenuItem()
|
[Test]
|
||||||
|
public void TestTernaryMenuItem()
|
||||||
{
|
{
|
||||||
Add(new OsuMenu(Direction.Vertical, true)
|
OsuMenu menu = null;
|
||||||
|
|
||||||
|
Bindable<TernaryState> state = new Bindable<TernaryState>(TernaryState.Indeterminate);
|
||||||
|
|
||||||
|
AddStep("create menu", () =>
|
||||||
|
{
|
||||||
|
state.Value = TernaryState.Indeterminate;
|
||||||
|
|
||||||
|
Child = menu = new OsuMenu(Direction.Vertical, true)
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Items = new[]
|
||||||
|
{
|
||||||
|
new ThreeStateMenuItem("First"),
|
||||||
|
new ThreeStateMenuItem("Second") { State = { BindTarget = state } },
|
||||||
|
new ThreeStateMenuItem("Third") { State = { Value = TernaryState.True } },
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
checkState(TernaryState.Indeterminate);
|
||||||
|
|
||||||
|
click();
|
||||||
|
checkState(TernaryState.True);
|
||||||
|
|
||||||
|
click();
|
||||||
|
checkState(TernaryState.False);
|
||||||
|
|
||||||
|
click();
|
||||||
|
checkState(TernaryState.True);
|
||||||
|
|
||||||
|
click();
|
||||||
|
checkState(TernaryState.False);
|
||||||
|
|
||||||
|
AddStep("change state via bindable", () => state.Value = TernaryState.True);
|
||||||
|
|
||||||
|
void click() =>
|
||||||
|
AddStep("click", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(menu.ScreenSpaceDrawQuad.Centre);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
void checkState(TernaryState expected)
|
||||||
|
=> AddAssert($"state is {expected}", () => state.Value == expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestCustomState()
|
||||||
|
{
|
||||||
|
AddStep("create menu", () =>
|
||||||
|
{
|
||||||
|
Child = new OsuMenu(Direction.Vertical, true)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
@ -30,6 +88,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
new TestMenuItem("Second", MenuItemType.Standard, getNextState) { State = { Value = TestStates.State2 } },
|
new TestMenuItem("Second", MenuItemType.Standard, getNextState) { State = { Value = TestStates.State2 } },
|
||||||
new TestMenuItem("Third", MenuItemType.Standard, getNextState) { State = { Value = TestStates.State3 } },
|
new TestMenuItem("Third", MenuItemType.Standard, getNextState) { State = { Value = TestStates.State3 } },
|
||||||
}
|
}
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Game.Graphics.UserInterface;
|
|
||||||
using osuTK.Input;
|
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
|
||||||
{
|
|
||||||
public class TestSceneTernaryMenuItem : ManualInputManagerTestScene
|
|
||||||
{
|
|
||||||
private readonly OsuMenu menu;
|
|
||||||
|
|
||||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
|
||||||
{
|
|
||||||
typeof(OsuMenu),
|
|
||||||
typeof(ThreeStateMenuItem),
|
|
||||||
typeof(DrawableStatefulMenuItem)
|
|
||||||
};
|
|
||||||
|
|
||||||
private readonly Bindable<TernaryState> state = new Bindable<TernaryState>(TernaryState.Indeterminate);
|
|
||||||
|
|
||||||
public TestSceneTernaryMenuItem()
|
|
||||||
{
|
|
||||||
Add(menu = new OsuMenu(Direction.Vertical, true)
|
|
||||||
{
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
Items = new[]
|
|
||||||
{
|
|
||||||
new ThreeStateMenuItem("First"),
|
|
||||||
new ThreeStateMenuItem("Second") { State = { BindTarget = state } },
|
|
||||||
new ThreeStateMenuItem("Third") { State = { Value = TernaryState.True } },
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
checkState(TernaryState.Indeterminate);
|
|
||||||
|
|
||||||
click();
|
|
||||||
checkState(TernaryState.True);
|
|
||||||
|
|
||||||
click();
|
|
||||||
checkState(TernaryState.False);
|
|
||||||
|
|
||||||
click();
|
|
||||||
checkState(TernaryState.True);
|
|
||||||
|
|
||||||
click();
|
|
||||||
checkState(TernaryState.False);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void click() =>
|
|
||||||
AddStep("click", () =>
|
|
||||||
{
|
|
||||||
InputManager.MoveMouseTo(menu.ScreenSpaceDrawQuad.Centre);
|
|
||||||
InputManager.Click(MouseButton.Left);
|
|
||||||
});
|
|
||||||
|
|
||||||
private void checkState(TernaryState expected)
|
|
||||||
=> AddAssert($"state is {expected}", () => state.Value == expected);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user