| | 1 | | using DCL.SettingsPanelHUD.Controls; |
| | 2 | | using DCL.SettingsPanelHUD.Sections; |
| | 3 | | using DCL.SettingsPanelHUD.Widgets; |
| | 4 | | using NSubstitute; |
| | 5 | | using System.Collections; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using UnityEngine; |
| | 8 | | using UnityEngine.TestTools; |
| | 9 | |
|
| | 10 | | namespace SettingsSectionTests |
| | 11 | | { |
| | 12 | |
|
| | 13 | | public class SettingsSectionShould_PlayMode |
| | 14 | | { |
| | 15 | | private const string SECTION_VIEW_PREFAB_PATH = "Sections/DefaultSettingsSectionTemplate"; |
| | 16 | | private const string WIDGET_VIEW_PREFAB_PATH = "Widgets/DefaultSettingsWidgetTemplate"; |
| | 17 | |
|
| | 18 | | private SettingsSectionView sectionView; |
| | 19 | | private ISettingsSectionController sectionController; |
| 1 | 20 | | private List<SettingsWidgetModel> widgetsToCreate = new List<SettingsWidgetModel>(); |
| | 21 | |
|
| | 22 | | [UnitySetUp] |
| | 23 | | private IEnumerator SetUp() |
| | 24 | | { |
| 1 | 25 | | sectionView = Object.Instantiate((GameObject)Resources.Load(SECTION_VIEW_PREFAB_PATH)).GetComponent<Settings |
| 1 | 26 | | sectionController = Substitute.For<ISettingsSectionController>(); |
| | 27 | |
|
| 1 | 28 | | yield return null; |
| 1 | 29 | | } |
| | 30 | |
|
| | 31 | | [UnityTearDown] |
| | 32 | | private IEnumerator TearDown() |
| | 33 | | { |
| 1 | 34 | | Object.Destroy(sectionView.gameObject); |
| 1 | 35 | | widgetsToCreate.Clear(); |
| | 36 | |
|
| 1 | 37 | | yield return null; |
| 1 | 38 | | } |
| | 39 | |
|
| | 40 | | [UnityTest] |
| | 41 | | public IEnumerator GenerateWidgetIntoASectionViewCorrectly() |
| | 42 | | { |
| | 43 | | // Arrange |
| 1 | 44 | | SettingsWidgetView widgetViewPrefab = ((GameObject)Resources.Load(WIDGET_VIEW_PREFAB_PATH)).GetComponent<Set |
| | 45 | |
|
| 1 | 46 | | SettingsWidgetModel newWidgetConfig = ScriptableObject.CreateInstance<SettingsWidgetModel>(); |
| 1 | 47 | | newWidgetConfig.title = "TestWidget"; |
| 1 | 48 | | newWidgetConfig.widgetPrefab = widgetViewPrefab; |
| 1 | 49 | | newWidgetConfig.widgetController = ScriptableObject.CreateInstance<SettingsWidgetController>(); |
| 1 | 50 | | newWidgetConfig.controlColumns = new SettingsControlGroupList(); |
| | 51 | |
|
| 1 | 52 | | widgetsToCreate.Add(newWidgetConfig); |
| | 53 | |
|
| | 54 | | // Act |
| 1 | 55 | | sectionView.Initialize(sectionController, widgetsToCreate); |
| 1 | 56 | | yield return null; |
| | 57 | |
|
| | 58 | | // Assert |
| 1 | 59 | | sectionController.Received(1) |
| | 60 | | .AddWidget( |
| | 61 | | Arg.Any<ISettingsWidgetView>(), |
| | 62 | | Arg.Any<ISettingsWidgetController>(), |
| | 63 | | Arg.Any<SettingsWidgetModel>()); |
| 1 | 64 | | } |
| | 65 | | } |
| | 66 | | } |