2021-03-02 18:18:01 +00:00
// 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.Linq ;
using NUnit.Framework ;
using osu.Framework.Bindables ;
using osu.Framework.Testing ;
using osu.Game.Overlays.Settings ;
2021-05-14 15:01:17 +00:00
using osu.Game.Overlays ;
2021-03-02 18:18:01 +00:00
namespace osu.Game.Tests.Visual.Settings
{
[TestFixture]
public class TestSceneSettingsItem : OsuTestScene
{
[Test]
public void TestRestoreDefaultValueButtonVisibility ( )
{
2021-07-10 16:56:44 +00:00
SettingsTextBox textBox = null ;
RestoreDefaultValueButton < string > restoreDefaultValueButton = null ;
2021-03-02 18:18:01 +00:00
2021-07-10 16:56:44 +00:00
AddStep ( "create settings item" , ( ) = >
2021-03-02 18:18:01 +00:00
{
2021-07-10 16:56:44 +00:00
Child = textBox = new SettingsTextBox
2021-03-02 18:18:01 +00:00
{
2021-07-10 16:56:44 +00:00
Current = new Bindable < string >
{
Default = "test" ,
Value = "test"
}
} ;
restoreDefaultValueButton = textBox . ChildrenOfType < RestoreDefaultValueButton < string > > ( ) . Single ( ) ;
2021-03-02 18:18:01 +00:00
} ) ;
2021-07-10 16:56:44 +00:00
AddAssert ( "restore button hidden" , ( ) = > restoreDefaultValueButton . Alpha = = 0 ) ;
2021-03-02 18:18:01 +00:00
AddStep ( "change value from default" , ( ) = > textBox . Current . Value = "non-default" ) ;
2021-07-10 16:56:44 +00:00
AddUntilStep ( "restore button shown" , ( ) = > restoreDefaultValueButton . Alpha > 0 ) ;
2021-03-02 18:18:01 +00:00
AddStep ( "restore default" , ( ) = > textBox . Current . SetDefault ( ) ) ;
2021-07-10 16:56:44 +00:00
AddUntilStep ( "restore button hidden" , ( ) = > restoreDefaultValueButton . Alpha = = 0 ) ;
2021-03-02 18:18:01 +00:00
}
2021-07-10 16:56:44 +00:00
/// <summary>
2021-07-11 15:26:00 +00:00
/// Ensures that the reset to default button uses the correct implementation of IsDefault to determine whether it should be shown or not.
/// Values have been chosen so that after being set, Value != Default (but they are close enough that the difference is negligible compared to Precision).
2021-07-10 16:56:44 +00:00
/// </summary>
[TestCase(4.2f)]
[TestCase(9.9f)]
public void TestRestoreDefaultValueButtonPrecision ( float initialValue )
2021-03-02 18:18:01 +00:00
{
2021-07-11 15:26:00 +00:00
BindableFloat current = null ;
2021-07-10 16:56:44 +00:00
SettingsSlider < float > sliderBar = null ;
RestoreDefaultValueButton < float > restoreDefaultValueButton = null ;
AddStep ( "create settings item" , ( ) = >
{
Child = sliderBar = new SettingsSlider < float >
{
2021-07-11 15:26:00 +00:00
Current = current = new BindableFloat ( initialValue )
2021-07-10 16:56:44 +00:00
{
MinValue = 0f ,
MaxValue = 10f ,
Precision = 0.1f ,
}
} ;
restoreDefaultValueButton = sliderBar . ChildrenOfType < RestoreDefaultValueButton < float > > ( ) . Single ( ) ;
} ) ;
AddAssert ( "restore button hidden" , ( ) = > restoreDefaultValueButton . Alpha = = 0 ) ;
2021-07-11 15:26:00 +00:00
AddStep ( "change value to next closest" , ( ) = > sliderBar . Current . Value + = current . Precision * 0.6f ) ;
2021-07-10 16:56:44 +00:00
AddUntilStep ( "restore button shown" , ( ) = > restoreDefaultValueButton . Alpha > 0 ) ;
AddStep ( "restore default" , ( ) = > sliderBar . Current . SetDefault ( ) ) ;
AddUntilStep ( "restore button hidden" , ( ) = > restoreDefaultValueButton . Alpha = = 0 ) ;
2021-03-02 18:18:01 +00:00
}
}
2021-07-10 16:56:44 +00:00
}