| | 1 | | using DCL.SettingsControls; |
| | 2 | | using DCL.SettingsPanelHUD.Controls; |
| | 3 | | using DCL.SettingsPanelHUD.Widgets; |
| | 4 | | using NSubstitute; |
| | 5 | | using NUnit.Framework; |
| | 6 | | using System.Collections; |
| | 7 | | using System.Collections.Generic; |
| | 8 | | using UnityEngine; |
| | 9 | | using UnityEngine.TestTools; |
| | 10 | |
|
| | 11 | | namespace SettingsWidgetTests |
| | 12 | | { |
| | 13 | | public class SettingsWidgetShould_PlayMode |
| | 14 | | { |
| | 15 | | private const int NUMBER_OF_COLUMNS = 2; |
| | 16 | | private const string WIDGET_VIEW_PREFAB_PATH = "Widgets/DefaultSettingsWidgetTemplate"; |
| | 17 | | private const string CONTROL_VIEW_PREFAB_PATH = "Controls/{controlType}SettingsControlTemplate"; |
| | 18 | |
|
| | 19 | | private SettingsWidgetView widgetView; |
| | 20 | | private ISettingsWidgetController widgetController; |
| 1 | 21 | | private List<SettingsControlGroup> controlColumnsToCreate = new List<SettingsControlGroup>(); |
| | 22 | |
|
| | 23 | | [UnitySetUp] |
| | 24 | | private IEnumerator SetUp() |
| | 25 | | { |
| 18 | 26 | | for (int i = 0; i < NUMBER_OF_COLUMNS; i++) |
| | 27 | | { |
| 6 | 28 | | controlColumnsToCreate.Add(new SettingsControlGroup() |
| | 29 | | { |
| | 30 | | controls = new SettingsControlList() |
| | 31 | | }); |
| | 32 | | } |
| | 33 | |
|
| 3 | 34 | | widgetView = Object.Instantiate((GameObject)Resources.Load(WIDGET_VIEW_PREFAB_PATH)).GetComponent<SettingsWi |
| 3 | 35 | | widgetController = Substitute.For<ISettingsWidgetController>(); |
| | 36 | |
|
| 3 | 37 | | yield return null; |
| 3 | 38 | | } |
| | 39 | |
|
| | 40 | | [UnityTearDown] |
| | 41 | | private IEnumerator TearDown() |
| | 42 | | { |
| 3 | 43 | | Object.Destroy(widgetView.gameObject); |
| 3 | 44 | | controlColumnsToCreate.Clear(); |
| | 45 | |
|
| 3 | 46 | | yield return null; |
| 3 | 47 | | } |
| | 48 | |
|
| | 49 | | [UnityTest] |
| | 50 | | [TestCase(0, "Slider", ExpectedResult = null)] |
| | 51 | | [TestCase(1, "SpinBox", ExpectedResult = null)] |
| | 52 | | [TestCase(0, "Toggle", ExpectedResult = null)] |
| | 53 | | public IEnumerator GenerateControlsIntoAWidgetViewCorrectly(int columnIndex, string controlType) |
| | 54 | | { |
| | 55 | | // Arrange |
| 3 | 56 | | SettingsControlView controlViewPrefab = ((GameObject)Resources.Load(CONTROL_VIEW_PREFAB_PATH.Replace("{contr |
| | 57 | |
|
| 3 | 58 | | SettingsControlModel newControlConfig = ScriptableObject.CreateInstance<SettingsControlModel>(); |
| 3 | 59 | | newControlConfig.title = $"TestControl_Col{columnIndex}"; |
| 3 | 60 | | newControlConfig.controlPrefab = controlViewPrefab; |
| 3 | 61 | | newControlConfig.controlController = ScriptableObject.CreateInstance<SettingsControlController>(); |
| 3 | 62 | | newControlConfig.flagsThatDeactivateMe = new List<BooleanVariable>(); |
| 3 | 63 | | newControlConfig.flagsThatDisableMe = new List<BooleanVariable>(); |
| 3 | 64 | | newControlConfig.isBeta = false; |
| | 65 | |
|
| | 66 | |
|
| 3 | 67 | | controlColumnsToCreate[columnIndex].controls.Add(newControlConfig); |
| | 68 | |
|
| | 69 | | // Act |
| 3 | 70 | | widgetView.Initialize("TestWidget", widgetController, controlColumnsToCreate); |
| 3 | 71 | | yield return null; |
| | 72 | |
|
| | 73 | | // Assert |
| 3 | 74 | | widgetController.Received(1) |
| | 75 | | .AddControl( |
| | 76 | | Arg.Any<ISettingsControlView>(), |
| | 77 | | Arg.Any<SettingsControlController>(), |
| | 78 | | Arg.Any<SettingsControlModel>()); |
| 3 | 79 | | } |
| | 80 | | } |
| | 81 | | } |