| | 1 | | using DCL.SettingsPanelHUD; |
| | 2 | | using DCL.SettingsPanelHUD.Sections; |
| | 3 | | using NSubstitute; |
| | 4 | | using System.Collections; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.TestTools; |
| | 7 | |
|
| | 8 | | namespace SettingsPanelTests |
| | 9 | | { |
| | 10 | | public class SettingsPanelShould_PlayMode |
| | 11 | | { |
| | 12 | | private const string SECTION_VIEW_PREFAB_PATH = "Sections/DefaultSettingsSectionTemplate"; |
| | 13 | | private const string MENU_BUTTON_PREFAB_PATH = "Sections/DefaultSettingsMenuButtonTemplate"; |
| | 14 | |
|
| | 15 | | private SettingsPanelHUDView panelView; |
| | 16 | | private IHUD hudController; |
| | 17 | | private ISettingsPanelHUDController panelController; |
| 1 | 18 | | private SettingsSectionList sectionsToCreate = new SettingsSectionList(); |
| | 19 | |
|
| | 20 | | [UnitySetUp] |
| | 21 | | private IEnumerator SetUp() |
| | 22 | | { |
| 1 | 23 | | panelView = SettingsPanelHUDView.Create(); |
| 1 | 24 | | hudController = Substitute.For<IHUD>(); |
| 1 | 25 | | panelController = Substitute.For<ISettingsPanelHUDController>(); |
| | 26 | |
|
| 1 | 27 | | yield return null; |
| 1 | 28 | | } |
| | 29 | |
|
| | 30 | | [UnityTearDown] |
| | 31 | | private IEnumerator TearDown() |
| | 32 | | { |
| 1 | 33 | | Object.Destroy(panelView.gameObject); |
| | 34 | |
|
| 4 | 35 | | foreach (var section in sectionsToCreate) |
| | 36 | | { |
| 1 | 37 | | Object.Destroy(section.icon); |
| | 38 | | } |
| 1 | 39 | | sectionsToCreate.Clear(); |
| | 40 | |
|
| 1 | 41 | | yield return null; |
| 1 | 42 | | } |
| | 43 | |
|
| | 44 | | [UnityTest] |
| | 45 | | public IEnumerator GenerateSectionsIntoThePanelViewCorrectly() |
| | 46 | | { |
| | 47 | | // Arrange |
| 1 | 48 | | SettingsSectionView sectionViewPrefab = ((GameObject)Resources.Load(SECTION_VIEW_PREFAB_PATH)).GetComponent< |
| 1 | 49 | | SettingsButtonEntry menuButtonPrefab = ((GameObject)Resources.Load(MENU_BUTTON_PREFAB_PATH)).GetComponent<Se |
| | 50 | |
|
| 1 | 51 | | SettingsSectionModel newSectionConfig = ScriptableObject.CreateInstance<SettingsSectionModel>(); |
| 1 | 52 | | newSectionConfig.icon = Sprite.Create(new Texture2D(10, 10), new Rect(), new Vector2()); |
| 1 | 53 | | newSectionConfig.text = "TestSection"; |
| 1 | 54 | | newSectionConfig.menuButtonPrefab = menuButtonPrefab; |
| 1 | 55 | | newSectionConfig.sectionPrefab = sectionViewPrefab; |
| 1 | 56 | | newSectionConfig.sectionController = ScriptableObject.CreateInstance<SettingsSectionController>(); |
| 1 | 57 | | newSectionConfig.widgets = new SettingsWidgetList(); |
| | 58 | |
|
| 1 | 59 | | sectionsToCreate.Add(newSectionConfig); |
| | 60 | |
|
| | 61 | | // Act |
| 1 | 62 | | panelView.Initialize(hudController, panelController, sectionsToCreate); |
| 1 | 63 | | yield return null; |
| | 64 | |
|
| | 65 | | // Assert |
| 1 | 66 | | panelController.Received(1) |
| | 67 | | .AddSection( |
| | 68 | | Arg.Any<SettingsButtonEntry>(), |
| | 69 | | Arg.Any<ISettingsSectionView>(), |
| | 70 | | Arg.Any<ISettingsSectionController>(), |
| | 71 | | Arg.Any<SettingsSectionModel>()); |
| | 72 | |
|
| 1 | 73 | | panelController.Received(1).OpenSection(0); |
| 1 | 74 | | panelController.Received(1).MarkMenuButtonAsSelected(0); |
| 1 | 75 | | } |
| | 76 | | } |
| | 77 | | } |