| | 1 | | using DCL.SettingsPanelHUD; |
| | 2 | | using DCL.SettingsPanelHUD.Sections; |
| | 3 | | using DCL.SettingsPanelHUD.Widgets; |
| | 4 | | using NSubstitute; |
| | 5 | | using NUnit.Framework; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using UnityEngine; |
| | 8 | |
|
| | 9 | | namespace SettingsPanelTests |
| | 10 | | { |
| | 11 | | public class SettingsPanelShould_EditMode |
| | 12 | | { |
| | 13 | | private SettingsPanelHUDController panelController; |
| | 14 | | private ISettingsSectionView newSectionView; |
| | 15 | | private ISettingsSectionController newSectionController; |
| | 16 | | private SettingsSectionModel newSectionConfig; |
| | 17 | | private Sprite testSprite; |
| | 18 | |
|
| | 19 | | [SetUp] |
| | 20 | | public void SetUp() |
| | 21 | | { |
| 0 | 22 | | panelController = new SettingsPanelHUDController(); |
| 0 | 23 | | newSectionView = Substitute.For<ISettingsSectionView>(); |
| 0 | 24 | | newSectionController = Substitute.For<ISettingsSectionController>(); |
| 0 | 25 | | testSprite = Sprite.Create(new Texture2D(10, 10), new Rect(), new Vector2()); |
| 0 | 26 | | newSectionConfig = ScriptableObject.CreateInstance<SettingsSectionModel>(); |
| 0 | 27 | | newSectionConfig.icon = testSprite; |
| 0 | 28 | | newSectionConfig.text = "TestSection"; |
| 0 | 29 | | newSectionConfig.menuButtonPrefab = new GameObject().AddComponent<SettingsButtonEntry>(); |
| 0 | 30 | | newSectionConfig.sectionPrefab = new GameObject().AddComponent<SettingsSectionView>(); |
| 0 | 31 | | newSectionConfig.sectionController = ScriptableObject.CreateInstance<SettingsSectionController>(); |
| 0 | 32 | | newSectionConfig.widgets = new SettingsWidgetList(); |
| 0 | 33 | | } |
| | 34 | |
|
| | 35 | | [TearDown] |
| | 36 | | public void TearDown() |
| | 37 | | { |
| 0 | 38 | | Object.DestroyImmediate(testSprite); |
| 0 | 39 | | panelController.sections.Clear(); |
| 0 | 40 | | } |
| | 41 | |
|
| | 42 | | [Test] |
| | 43 | | public void AddSectionCorrectly() |
| | 44 | | { |
| | 45 | | // Act |
| 0 | 46 | | panelController.AddSection(null, newSectionView, newSectionController, newSectionConfig); |
| | 47 | |
|
| | 48 | | // Assert |
| 0 | 49 | | newSectionView.Received(1).Initialize(newSectionController, Arg.Any<List<SettingsWidgetModel>>()); |
| 0 | 50 | | newSectionView.Received(1).SetActive(false); |
| 0 | 51 | | Assert.Contains(newSectionView, panelController.sections, "The new section should be contained in the sectio |
| 0 | 52 | | } |
| | 53 | |
|
| | 54 | | [Test] |
| | 55 | | public void OpenSectionCorrectly() |
| | 56 | | { |
| | 57 | | //Arrange |
| 0 | 58 | | panelController.AddSection(null, newSectionView, newSectionController, newSectionConfig); |
| | 59 | |
|
| | 60 | | // Act |
| 0 | 61 | | panelController.OpenSection(newSectionView); |
| | 62 | |
|
| | 63 | | // Assert |
| 0 | 64 | | newSectionView.Received(1).SetActive(true); |
| 0 | 65 | | } |
| | 66 | |
|
| | 67 | | [Test] |
| | 68 | | public void OpenSectionByIndexCorrectly() |
| | 69 | | { |
| | 70 | | //Arrange |
| 0 | 71 | | panelController.AddSection(null, newSectionView, newSectionController, newSectionConfig); |
| | 72 | |
|
| | 73 | | // Act |
| 0 | 74 | | panelController.OpenSection(panelController.sections.Count - 1); |
| | 75 | |
|
| | 76 | | // Assert |
| 0 | 77 | | newSectionView.Received(1).SetActive(true); |
| 0 | 78 | | } |
| | 79 | | } |
| | 80 | | } |