osu.Framework.Tests/Visual/UserInterface/TestCaseNestedMenus.cs
/// <summary>
/// Tests whether clicking outside the <see cref="Menu"/> structure closes all sub-menus.
/// </summary>
/// <param name="hoverPrevious">Whether the previous menu should first be hovered before clicking outside.</param>
Tests whether clicking outside the  structure closes all sub-menus.
Tests whether clicking outside the structure closes all sub - menus .
[TestCase(false)]
        [TestCase(true)]
        public void TestClickingOutsideClosesMenus(bool hoverPrevious)
        {
            for (int i = 0; i <= 3; i++)
            {
                int i2 = i;
                for (int j = 0; j <= i; j++)
                {
                    int menuToOpen = j;
                    int itemToOpen = menuToOpen == 0 ? 1 : 0;
                    AddStep("Click item", () => clickItem(menuToOpen, itemToOpen));
                }
                if (hoverPrevious && i > 0)
                    AddStep("Hover previous", () => InputManager.MoveMouseTo(menus.GetSubStructure(i2 - 1).GetMenuItems()[i2 > 1 ? 0 : 1]));
                AddStep("Remove hover", () => InputManager.MoveMouseTo(Vector2.Zero));
                AddStep("Click outside", () => InputManager.Click(MouseButton.Left));
                AddAssert("Check submenus closed", () =>
                {
                    for (int j = 1; j <= i2 + 1; j++)
                    {
                        int menuIndex2 = j;
                        if (menus.GetSubMenu(menuIndex2).State == MenuState.Open)
                            return false;
                    }
                    return true;
                });
            }
        }
[ TestCase ( false ) ] [ TestCase ( true ) ] public void TestClickingOutsideClosesMenus ( bool hoverPrevious ) { for ( int i = 0 ; i <= 3 ; i ++ ) { int i2 = i ; for ( int j = 0 ; j <= i ; j ++ ) { int menuToOpen = j ; int itemToOpen = menuToOpen == 0 ? 1 : 0 ; AddStep ( " " , ( ) => clickItem ( menuToOpen , itemToOpen ) ) ; } if ( hoverPrevious && i > 0 ) AddStep ( " " , ( ) => InputManager . MoveMouseTo ( menus . GetSubStructure ( i2 - 1 ) . GetMenuItems ( ) [ i2 > 1 ? 0 : 1 ] ) ) ; AddStep ( " " , ( ) => InputManager . MoveMouseTo ( Vector2 . Zero ) ) ; AddStep ( " " , ( ) => InputManager . Click ( MouseButton . Left ) ) ; AddAssert ( " " , ( ) => { for ( int j = 1 ; j <= i2 + 1 ; j ++ ) { int menuIndex2 = j ; if ( menus . GetSubMenu ( menuIndex2 ) . State == MenuState . Open ) return false ; } return true ; } ) ; } }
Tests whether clicking outside the  structure closes all sub-menus.
Tests whether clicking outside the structure closes all sub - menus .
hoverPrevious
bool
Whether the previous menu should first be hovered before clicking outside.
Whether the previous menu should first be hovered before clicking outside .