123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include <Tests/ActionManager/ActionManagerFixture.h>
- #include <AzToolsFramework/API/ToolsApplicationAPI.h>
- #include <QToolBar>
- namespace UnitTest
- {
- TEST_F(ActionManagerFixture, RegisterToolBar)
- {
- auto outcome = m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- EXPECT_TRUE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, RegisterToolBarTwice)
- {
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- auto outcome = m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, RegisterToolBarArea)
- {
- auto outcome = m_toolBarManagerInterface->RegisterToolBarArea("o3de.toolbararea.test", m_mainWindow, Qt::ToolBarArea::TopToolBarArea);
- EXPECT_TRUE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, RegisterToolBarAreaTwice)
- {
- m_toolBarManagerInterface->RegisterToolBarArea("o3de.toolbararea.test", m_mainWindow, Qt::ToolBarArea::TopToolBarArea);
- auto outcome = m_toolBarManagerInterface->RegisterToolBarArea("o3de.toolbararea.test", m_mainWindow, Qt::ToolBarArea::TopToolBarArea);
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, AddActionToUnregisteredToolBar)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- auto outcome = m_toolBarManagerInterface->AddActionToToolBar("o3de.toolbar.test", "o3de.action.test", 42);
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, AddActionToToolBar)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
-
- auto outcome = m_toolBarManagerInterface->AddActionToToolBar("o3de.toolbar.test", "o3de.action.test", 42);
- EXPECT_TRUE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, AddActionToToolBarTwice)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
-
- m_toolBarManagerInterface->AddActionToToolBar("o3de.toolbar.test", "o3de.action.test", 42);
- auto outcome = m_toolBarManagerInterface->AddActionToToolBar("o3de.toolbar.test", "o3de.action.test", 42);
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, AddActionsToToolBar)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test2", {}, []{});
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
-
- AZStd::vector<AZStd::pair<AZStd::string, int>> actions;
- actions.push_back(AZStd::make_pair("o3de.action.test", 42));
- actions.push_back(AZStd::make_pair("o3de.action.test2", 1));
- auto outcome = m_toolBarManagerInterface->AddActionsToToolBar("o3de.toolbar.test", actions);
- EXPECT_TRUE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, RemoveActionFromToolBar)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
-
- m_toolBarManagerInterface->AddActionToToolBar("o3de.toolbar.test", "o3de.action.test", 42);
-
- auto outcome = m_toolBarManagerInterface->RemoveActionFromToolBar("o3de.toolbar.test", "o3de.action.test");
- EXPECT_TRUE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, RemoveMissingActionFromToolBar)
- {
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
-
- auto outcome = m_toolBarManagerInterface->RemoveActionFromToolBar("o3de.toolbar.test", "o3de.action.test");
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, RemoveActionsFromToolBar)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test2", {}, []{});
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
-
- AZStd::vector<AZStd::pair<AZStd::string, int>> actions;
- actions.push_back(AZStd::make_pair("o3de.action.test", 42));
- actions.push_back(AZStd::make_pair("o3de.action.test2", 1));
- m_toolBarManagerInterface->AddActionsToToolBar("o3de.toolbar.test", actions);
- auto outcome = m_toolBarManagerInterface->RemoveActionsFromToolBar("o3de.toolbar.test", { "o3de.action.test", "o3de.action.test2" });
- EXPECT_TRUE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, RemoveMissingActionsFromToolBar)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test2", {}, []{});
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
-
- AZStd::vector<AZStd::pair<AZStd::string, int>> actions;
- actions.push_back(AZStd::make_pair("o3de.action.test", 42));
- m_toolBarManagerInterface->AddActionsToToolBar("o3de.toolbar.test", actions);
- auto outcome = m_toolBarManagerInterface->RemoveActionsFromToolBar("o3de.toolbar.test", { "o3de.action.test", "o3de.action.test2" });
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, GetUnregisteredToolBar)
- {
- QToolBar* toolBar = m_toolBarManagerInterface->GenerateToolBar("o3de.toolbar.test");
- EXPECT_TRUE(toolBar == nullptr);
- }
- TEST_F(ActionManagerFixture, GenerateToolBar)
- {
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
-
- QToolBar* toolBar = m_toolBarManagerInterface->GenerateToolBar("o3de.toolbar.test");
- EXPECT_TRUE(toolBar != nullptr);
- }
- TEST_F(ActionManagerFixture, VerifyActionInToolBar)
- {
- // Register ToolBar, get it and verify it's empty.
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- QToolBar* toolBar = m_toolBarManagerInterface->GenerateToolBar("o3de.toolbar.test");
- EXPECT_EQ(toolBar->actions().size(), 0);
- // Register a new action and add it to the ToolBar.
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- auto outcome = m_toolBarManagerInterface->AddActionToToolBar("o3de.toolbar.test", "o3de.action.test", 42);
- // Manually trigger ToolBar refresh - Editor will call this once per tick.
- m_toolBarManagerInternalInterface->RefreshToolBars();
- // Verify the action is now in the ToolBar.
- EXPECT_EQ(toolBar->actions().size(), 1);
- }
- TEST_F(ActionManagerFixture, VerifyActionOrderInToolBar)
- {
- // Register ToolBar, get it and verify it's empty.
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- QToolBar* toolBar = m_toolBarManagerInterface->GenerateToolBar("o3de.toolbar.test");
- EXPECT_EQ(toolBar->actions().size(), 0);
- // Register a new action and add it to the ToolBar.
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test1", {}, []{});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test2", {}, []{});
- m_toolBarManagerInterface->AddActionToToolBar("o3de.toolbar.test", "o3de.action.test2", 42);
- m_toolBarManagerInterface->AddActionToToolBar("o3de.toolbar.test", "o3de.action.test1", 1);
- // Manually trigger ToolBar refresh - Editor will call this once per tick.
- m_toolBarManagerInternalInterface->RefreshToolBars();
- // Verify the actions are now in the ToolBar.
- EXPECT_EQ(toolBar->actions().size(), 2);
- // Verify the order is correct.
- QAction* test1 = m_actionManagerInternalInterface->GetAction("o3de.action.test1");
- QAction* test2 = m_actionManagerInternalInterface->GetAction("o3de.action.test2");
- const auto& actions = toolBar->actions();
- EXPECT_EQ(actions[0], test1);
- EXPECT_EQ(actions[1], test2);
- }
- TEST_F(ActionManagerFixture, VerifyActionOrderInToolBarWithCollision)
- {
- // Register ToolBar, get it and verify it's empty.
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- QToolBar* toolBar = m_toolBarManagerInterface->GenerateToolBar("o3de.toolbar.test");
- EXPECT_EQ(toolBar->actions().size(), 0);
-
- // Register a new action and add it to the ToolBar.
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test1", {}, []{});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test2", {}, []{});
- m_toolBarManagerInterface->AddActionToToolBar("o3de.toolbar.test", "o3de.action.test2", 42);
- m_toolBarManagerInterface->AddActionToToolBar("o3de.toolbar.test", "o3de.action.test1", 42);
- // Manually trigger ToolBar refresh - Editor will call this once per tick.
- m_toolBarManagerInternalInterface->RefreshToolBars();
- // Verify the actions are now in the ToolBar.
- EXPECT_EQ(toolBar->actions().size(), 2);
- // Verify the order is correct (when a collision happens, items should be in order of addition).
- QAction* test1 = m_actionManagerInternalInterface->GetAction("o3de.action.test1");
- QAction* test2 = m_actionManagerInternalInterface->GetAction("o3de.action.test2");
- const auto& actions = toolBar->actions();
- EXPECT_EQ(actions[0], test2);
- EXPECT_EQ(actions[1], test1);
- }
- TEST_F(ActionManagerFixture, VerifySeparatorInToolBar)
- {
- // Register ToolBar, get it and verify it's empty.
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- QToolBar* toolBar = m_toolBarManagerInterface->GenerateToolBar("o3de.toolbar.test");
- EXPECT_EQ(toolBar->actions().size(), 0);
- // Add a separator to the ToolBar.
- m_toolBarManagerInterface->AddSeparatorToToolBar("o3de.toolbar.test", 42);
- // Manually trigger ToolBar refresh - Editor will call this once per tick.
- m_toolBarManagerInternalInterface->RefreshToolBars();
- // Verify the separator is now in the ToolBar.
- const auto& actions = toolBar->actions();
- EXPECT_EQ(actions.size(), 1);
- EXPECT_TRUE(actions[0]->isSeparator());
- }
- TEST_F(ActionManagerFixture, AddUnregisteredWidgetInToolBar)
- {
- // Register ToolBar.
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- // Try to add a nullptr widget.
- auto outcome = m_toolBarManagerInterface->AddWidgetToToolBar("o3de.toolbar.test", "someUnregisteredWidgetIdentifier", 42);
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, VerifyWidgetInToolBar)
- {
- // Register ToolBar and widget action.
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- QWidget* widget = new QWidget();
- m_actionManagerInterface->RegisterWidgetAction(
- "o3de.widgetAction.test",
- {},
- [widget]()
- {
- // Note: the WidgetAction generator function should create a new widget every time it's called.
- // This implementation is technically incorrect, but it allows us to test the correct behavior.
- return widget;
- }
- );
- // Add the widget to the ToolBar.
- m_toolBarManagerInterface->AddWidgetToToolBar("o3de.toolbar.test", "o3de.widgetAction.test", 42);
- // Manually trigger ToolBar refresh - Editor will call this once per tick.
- m_toolBarManagerInternalInterface->RefreshToolBars();
- // Verify the separator is now in the ToolBar.
- QToolBar* toolBar = m_toolBarManagerInterface->GenerateToolBar("o3de.toolbar.test");
- const auto& actions = toolBar->actions();
- EXPECT_EQ(actions.size(), 1);
- QWidgetAction* widgetAction = qobject_cast<QWidgetAction*>(actions[0]);
- EXPECT_TRUE(widgetAction != nullptr);
- EXPECT_TRUE(widgetAction->defaultWidget() == widget);
- }
- TEST_F(ActionManagerFixture, VerifyComplexToolBar)
- {
- // Combine multiple actions and separators.
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test1", {}, []{});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test2", {}, []{});
- // Create a ToolBar with this setup. Order of addition is intentionally scrambled to verify sortKeys.
- // - Test 1 Action
- // - Separator
- // - Test 2 Action
- m_toolBarManagerInterface->AddActionToToolBar("o3de.toolbar.test", "o3de.action.test2", 15);
- m_toolBarManagerInterface->AddActionToToolBar("o3de.toolbar.test", "o3de.action.test1", 1);
- m_toolBarManagerInterface->AddSeparatorToToolBar("o3de.toolbar.test", 10);
- // Verify the actions are now in the ToolBar in the expected order.
- QToolBar* toolBar = m_toolBarManagerInterface->GenerateToolBar("o3de.toolbar.test");
- QAction* test1 = m_actionManagerInternalInterface->GetAction("o3de.action.test1");
- QAction* test2 = m_actionManagerInternalInterface->GetAction("o3de.action.test2");
- // Manually trigger ToolBar refresh - Editor will call this once per tick.
- m_toolBarManagerInternalInterface->RefreshToolBars();
- // Note: separators are still QActions in the context of the ToolBar.
- const auto& actions = toolBar->actions();
- EXPECT_EQ(actions.size(), 3);
- // Verify the order is correct.
- EXPECT_EQ(actions[0], test1);
- EXPECT_TRUE(actions[1]->isSeparator());
- EXPECT_EQ(actions[2], test2);
- }
- TEST_F(ActionManagerFixture, AddToolBarToUnregisteredToolBarArea)
- {
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- auto outcome = m_toolBarManagerInterface->AddToolBarToToolBarArea("o3de.toolbararea.test", "o3de.toolbar.test", 42);
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, AddToolBarToToolBarArea)
- {
- m_toolBarManagerInterface->RegisterToolBarArea("o3de.toolbararea.test", m_mainWindow, Qt::ToolBarArea::TopToolBarArea);
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- auto outcome = m_toolBarManagerInterface->AddToolBarToToolBarArea("o3de.toolbararea.test", "o3de.toolbar.test", 42);
- EXPECT_TRUE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, AddToolBarToToolBarAreaTwice)
- {
- m_toolBarManagerInterface->RegisterToolBarArea("o3de.toolbararea.test", m_mainWindow, Qt::ToolBarArea::TopToolBarArea);
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- m_toolBarManagerInterface->AddToolBarToToolBarArea("o3de.toolbararea.test", "o3de.toolbar.test", 42);
- auto outcome = m_toolBarManagerInterface->AddToolBarToToolBarArea("o3de.toolbararea.test", "o3de.toolbar.test", 42);
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, VerifyToolBarInToolBarArea)
- {
- const char* TestToolBarName = "Test ToolBar";
- m_toolBarManagerInterface->RegisterToolBarArea("o3de.toolbararea.test", m_mainWindow, Qt::ToolBarArea::TopToolBarArea);
- AzToolsFramework::ToolBarProperties toolBarProperties;
- toolBarProperties.m_name = TestToolBarName;
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", toolBarProperties);
- // Add the ToolBar to the toolbar area.
- m_toolBarManagerInterface->AddToolBarToToolBarArea("o3de.toolbararea.test", "o3de.toolbar.test", 42);
- // Manually trigger ToolBar refresh - Editor will call this once per tick.
- m_toolBarManagerInternalInterface->RefreshToolBarAreas();
- // Verify the ToolBar is now in the ToolBar Area.
- auto toolBars = m_mainWindow->findChildren<QToolBar*>("");
- EXPECT_EQ(toolBars.size(), 1);
- EXPECT_EQ(toolBars[0]->windowTitle(), TestToolBarName);
- EXPECT_EQ(m_mainWindow->toolBarArea(toolBars[0]), Qt::ToolBarArea::TopToolBarArea);
- }
- TEST_F(ActionManagerFixture, GetSortKeyOfActionInToolBar)
- {
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- // Add the action to the ToolBar.
- m_toolBarManagerInterface->AddActionToToolBar("o3de.toolbar.test", "o3de.action.test", 42);
- // Verify the API returns the correct sort key.
- auto outcome = m_toolBarManagerInterface->GetSortKeyOfActionInToolBar("o3de.toolbar.test", "o3de.action.test");
- EXPECT_TRUE(outcome.IsSuccess());
- EXPECT_EQ(outcome.GetValue(), 42);
- }
- TEST_F(ActionManagerFixture, GetSortKeyOfUnregisteredActionInToolBar)
- {
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- // Verify the API fails as the action is not registered.
- auto outcome = m_toolBarManagerInterface->GetSortKeyOfActionInToolBar("o3de.toolbar.test", "o3de.action.test");
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, GetSortKeyOfActionNotInToolBar)
- {
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- // Verify the API fails as the action is registered but was not added to the ToolBar.
- auto outcome = m_toolBarManagerInterface->GetSortKeyOfActionInToolBar("o3de.toolbar.test", "o3de.action.test");
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, GetSortKeyOfWidgetInToolBar)
- {
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- m_actionManagerInterface->RegisterWidgetAction(
- "o3de.widgetAction.test",
- {},
- []() -> QWidget*
- {
- return nullptr;
- }
- );
- // Add the widget to the ToolBar.
- m_toolBarManagerInterface->AddWidgetToToolBar("o3de.toolbar.test", "o3de.widgetAction.test", 42);
- // Verify the API returns the correct sort key.
- auto outcome = m_toolBarManagerInterface->GetSortKeyOfWidgetInToolBar("o3de.toolbar.test", "o3de.widgetAction.test");
- EXPECT_TRUE(outcome.IsSuccess());
- EXPECT_EQ(outcome.GetValue(), 42);
- }
- TEST_F(ActionManagerFixture, GetSortKeyOfUnregisteredWidgetInToolBar)
- {
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- // Verify the API fails as the widget is not registered.
- auto outcome = m_toolBarManagerInterface->GetSortKeyOfWidgetInToolBar("o3de.toolbar.test", "o3de.widgetAction.test");
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, GetSortKeyOfWidgetNotInToolBar)
- {
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- m_actionManagerInterface->RegisterWidgetAction(
- "o3de.widgetAction.test",
- {},
- []() -> QWidget*
- {
- return nullptr;
- }
- );
- // Verify the API fails as the widget is registered but was not added to the ToolBar.
- auto outcome = m_toolBarManagerInterface->GetSortKeyOfWidgetInToolBar("o3de.toolbar.test", "o3de.widgetAction.test");
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, VerifyToolBarVisibilityHideWhenDisabled)
- {
- // Register toolbar, get it and verify it's empty.
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- QToolBar* toolBar = m_toolBarManagerInterface->GenerateToolBar("o3de.toolbar.test");
- EXPECT_EQ(toolBar->actions().size(), 0);
- // Register a new action and add it to the ToolBar. Have ToolBarVisibility set to HideWhenDisabled.
- AzToolsFramework::ActionProperties actionProperties;
- actionProperties.m_toolBarVisibility = AzToolsFramework::ActionVisibility::HideWhenDisabled;
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", actionProperties, []{});
- m_toolBarManagerInterface->AddActionToToolBar("o3de.toolbar.test", "o3de.action.test", 42);
- // Add enabled state callback.
- bool enabledState = true;
- m_actionManagerInterface->InstallEnabledStateCallback(
- "o3de.action.test",
- [&]()
- {
- return enabledState;
- }
- );
- // Manually trigger ToolBar refresh - Editor will call this once per tick.
- m_toolBarManagerInternalInterface->RefreshToolBars();
- // Verify the action is now in the ToolBar.
- EXPECT_EQ(toolBar->actions().size(), 1);
- // Set the action as disabled.
- enabledState = false;
- m_actionManagerInterface->UpdateAction("o3de.action.test");
- // Manually trigger ToolBar refresh - Editor will call this once per tick.
- m_toolBarManagerInternalInterface->RefreshToolBars();
- // Verify the action is no longer in the ToolBar.
- EXPECT_EQ(toolBar->actions().size(), 0);
- }
- TEST_F(ActionManagerFixture, VerifyDefaultToolBarVisibility)
- {
- // Register ToolBar, get it and verify it's empty.
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- QToolBar* toolBar = m_toolBarManagerInterface->GenerateToolBar("o3de.toolbar.test");
- EXPECT_EQ(toolBar->actions().size(), 0);
- // Register a new action and add it to the menu. ToolBarVisibility is set to OnlyInActiveMode by default.
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- m_toolBarManagerInterface->AddActionToToolBar("o3de.toolbar.test", "o3de.action.test", 42);
- // Add enabled state callback.
- bool enabledState = true;
- m_actionManagerInterface->InstallEnabledStateCallback(
- "o3de.action.test",
- [&]()
- {
- return enabledState;
- }
- );
- // Manually trigger ToolBar refresh - Editor will call this once per tick.
- m_toolBarManagerInternalInterface->RefreshToolBars();
- // Verify the action is now in the ToolBar.
- EXPECT_EQ(toolBar->actions().size(), 1);
- // Set the action as disabled.
- enabledState = false;
- m_actionManagerInterface->UpdateAction("o3de.action.test");
- // Manually trigger ToolBar refresh - Editor will call this once per tick.
- m_toolBarManagerInternalInterface->RefreshToolBars();
- // Verify the action is still in the ToolBar.
- EXPECT_EQ(toolBar->actions().size(), 1);
- }
- TEST_F(ActionManagerFixture, VerifyToolBarVisibilityAlwaysShowWhenChangingMode)
- {
- // Register ToolBar, get it and verify it's empty.
- m_toolBarManagerInterface->RegisterToolBar("o3de.toolbar.test", {});
- QToolBar* toolBar = m_toolBarManagerInterface->GenerateToolBar("o3de.toolbar.test");
- EXPECT_EQ(toolBar->actions().size(), 0);
- // Register a new action and add it to the default mode. Set ToolBarVisibility to AlwaysShow.
- AzToolsFramework::ActionProperties actionProperties;
- actionProperties.m_toolBarVisibility = AzToolsFramework::ActionVisibility::AlwaysShow;
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", actionProperties, []{});
- m_actionManagerInterface->AssignModeToAction(AzToolsFramework::DefaultActionContextModeIdentifier, "o3de.action.test");
- // Add the action to the ToolBar.
- m_toolBarManagerInterface->AddActionToToolBar("o3de.toolbar.test", "o3de.action.test", 42);
- // Manually trigger ToolBar refresh - Editor will call this once per tick.
- m_toolBarManagerInternalInterface->RefreshToolBars();
- // Verify the action is now in the ToolBar.
- EXPECT_EQ(toolBar->actions().size(), 1);
- // Register a new mode and switch to it.
- m_actionManagerInterface->RegisterActionContextMode("o3de.context.test", "testMode");
- m_actionManagerInterface->SetActiveActionContextMode("o3de.context.test", "testMode");
- // Manually trigger ToolBar refresh - Editor will call this once per tick.
- m_toolBarManagerInternalInterface->RefreshToolBars();
- // Verify the action is still in the ToolBar.
- EXPECT_EQ(toolBar->actions().size(), 1);
- }
- } // namespace UnitTest
|