-
Notifications
You must be signed in to change notification settings - Fork 324
/
Copy pathCustomProcessorEnumTest.cs
113 lines (88 loc) · 3.24 KB
/
CustomProcessorEnumTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS && UNITY_6000_0_OR_NEWER
using System;
using NUnit.Framework;
using System.Collections;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Editor;
using UnityEngine.TestTools;
using UnityEngine.UIElements;
public enum SomeEnum
{
OptionA = 10,
OptionB = 20,
OptionC = 50,
OptionD = 100
}
#if UNITY_EDITOR
[InitializeOnLoad]
#endif
public class CustomProcessor : InputProcessor<float>
{
public SomeEnum SomeEnum;
#if UNITY_EDITOR
static CustomProcessor()
{
Initialize();
}
#endif
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
private static void Initialize()
{
InputSystem.RegisterProcessor<CustomProcessor>();
}
public override float Process(float value, InputControl control)
{
return value;
}
}
internal class CustomProcessorEnumTest : UIToolkitBaseTestWindow<InputActionsEditorWindow>
{
InputActionAsset m_Asset;
public override void OneTimeSetUp()
{
base.OneTimeSetUp();
m_Asset = AssetDatabaseUtils.CreateAsset<InputActionAsset>();
var actionMap = m_Asset.AddActionMap("Action Map");
actionMap.AddAction("Action", InputActionType.Value, processors: "Custom(SomeEnum=10)");
}
public override void OneTimeTearDown()
{
AssetDatabaseUtils.Restore();
base.OneTimeTearDown();
}
public override IEnumerator UnitySetup()
{
m_Window = InputActionsEditorWindow.OpenEditor(m_Asset);
yield return base.UnitySetup();
}
[UnityTest]
public IEnumerator CustomProcessorEnum_SerialiseTheValue_InAsset()
{
var json = m_Window.currentAssetInEditor.ToJson();
Assert.That(json.Contains("Custom(SomeEnum=10)"), Is.True,
"Serialized JSON does not contain the expected custom processor string for OptionA.");
var dropdownList = m_Window.rootVisualElement.Query<DropdownField>().Where(d => d.choices != null && d.choices.Contains("OptionA") && d.choices.Contains("OptionB")).ToList();
Assume.That(dropdownList.Count > 0, Is.True, "Enum parameter dropdown not found in the UI.");
var dropdown = dropdownList.First();
var newIndex = dropdown.choices.IndexOf("OptionB");
var oldValue = dropdown.value;
var newValue = dropdown.choices[newIndex];
dropdown.Focus();
dropdown.value = newValue;
var changeEvent = ChangeEvent<Enum>.GetPooled(SomeEnum.OptionA, SomeEnum.OptionC);
changeEvent.target = dropdown;
dropdown.SendEvent(changeEvent);
var saveButton = m_Window.rootVisualElement.Q<Button>("save-asset-toolbar-button");
Assume.That(saveButton, Is.Not.Null, "Save Asset button not found in the UI.");
saveButton.Focus();
SimulateClickOn(saveButton);
Assert.That(dropdown.value, Is.EqualTo(newValue));
var updatedJson = m_Window.currentAssetInEditor.ToJson();
Assert.That(updatedJson.Contains("Custom(SomeEnum=20)"), Is.True, "Serialized JSON does not contain the updated custom processor string for OptionB.");
yield return null;
}
}
#endif