Skip to content

Commit c4306ad

Browse files
Add unit tests for testing against warnings that should be shown if actions are missing from the UI action map.
1 parent 4cbf7ec commit c4306ad

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

Assets/Tests/InputSystem/Plugins/InputForUITests.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using UnityEngine.InputSystem.Editor;
1515
#endif
1616
using UnityEngine.InputSystem.Plugins.InputForUI;
17+
using UnityEngine.InputSystem.Utilities;
1718
using Event = UnityEngine.InputForUI.Event;
1819
using EventProvider = UnityEngine.InputForUI.EventProvider;
1920
using Is = NUnit.Framework.Is;
@@ -535,19 +536,34 @@ public void DefaultActions_ShouldNotGenerateAnyVerificationWarnings(bool useProj
535536
LogAssert.NoUnexpectedReceived();
536537
}
537538

538-
[Ignore("We currently allow a PWA asset without an UI action map and rely on defaults instead. This allows users that do not want it or use something else to avoid using it.")]
539-
[Test(Description = "Verifies that user-supplied project-wide input actions generates warnings if action map is missing.")]
539+
[Test(Description = "Verifies that user-supplied project-wide actions do not generate warnings if action map is missing. We use default actions in this case.")]
540540
[Category(kTestCategory)]
541-
public void ActionsWithoutUIMap_ShouldGenerateWarnings()
541+
public void ActionsWithoutUIMap_ShouldNotGenerateWarnings()
542542
{
543543
var asset = ProjectWideActionsAsset.CreateDefaultAssetAtPath(kAssetPath);
544544
asset.RemoveActionMap(asset.FindActionMap("UI", throwIfNotFound: true));
545545

546546
InputSystem.s_Manager.actions = asset;
547547
Update();
548548

549+
LogAssert.NoUnexpectedReceived();
550+
}
551+
552+
[Test(Description = "Verifies that user-supplied project-wide input actions generates warnings if the UI map is present but actions are missing.")]
553+
[Category(kTestCategory)]
554+
public void ActionsWithUIMap_MissingActions_ShouldGenerateWarnings()
555+
{
556+
var asset = ProjectWideActionsAsset.CreateDefaultAssetAtPath(kAssetPath);
557+
var uiActionMap = asset.FindActionMap("UI", true);
558+
for (int i = uiActionMap.m_Actions.Length - 1; i >= 0; i--)
559+
{
560+
ArrayHelpers.EraseAt(ref uiActionMap.m_Actions, uiActionMap.m_Actions.Length - 1);
561+
}
562+
563+
InputSystem.s_Manager.actions = asset;
564+
Update();
565+
549566
var link = EditorHelpers.GetHyperlink(kAssetPath);
550-
LogAssert.Expect(LogType.Warning, new Regex($"^InputActionMap with path 'UI' in asset '{link}' could not be found."));
551567
if (InputActionAssetVerifier.DefaultReportPolicy == InputActionAssetVerifier.ReportPolicy.ReportAll)
552568
{
553569
LogAssert.Expect(LogType.Warning, new Regex($"^InputAction with path 'UI/Point' in asset '{link}' could not be found."));
@@ -559,8 +575,6 @@ public void ActionsWithoutUIMap_ShouldGenerateWarnings()
559575
LogAssert.Expect(LogType.Warning, new Regex($"^InputAction with path 'UI/RightClick' in asset '{link}' could not be found."));
560576
LogAssert.Expect(LogType.Warning, new Regex($"^InputAction with path 'UI/ScrollWheel' in asset '{link}' could not be found."));
561577
}
562-
// else: expect suppression of child errors
563-
LogAssert.NoUnexpectedReceived();
564578
}
565579

566580
[Test(Description = "Verifies that user-supplied project-wide input actions generates warnings if any required action is missing.")]

0 commit comments

Comments
 (0)