| | 1 | | using System.Collections.Generic; |
| | 2 | | using System.Linq; |
| | 3 | | using DCL; |
| | 4 | | using NUnit.Framework; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace Tests |
| | 8 | | { |
| | 9 | | public class SectionLandShould |
| | 10 | | { |
| | 11 | | private SectionLandView view; |
| | 12 | |
|
| | 13 | | [SetUp] |
| | 14 | | public void SetUp() |
| | 15 | | { |
| 8 | 16 | | var prefab = Resources.Load<SectionLandView>(SectionLandController.VIEW_PREFAB_PATH); |
| 8 | 17 | | view = Object.Instantiate(prefab); |
| 8 | 18 | | WebRequestController.Create(); |
| 8 | 19 | | } |
| | 20 | |
|
| | 21 | | [TearDown] |
| | 22 | | public void TearDown() |
| | 23 | | { |
| 8 | 24 | | Object.Destroy(view.gameObject); |
| 8 | 25 | | DCL.Environment.i.platform.webRequest.Dispose(); |
| 8 | 26 | | } |
| | 27 | |
|
| | 28 | | [Test] |
| | 29 | | public void PrefabSetupCorrectly() |
| | 30 | | { |
| 1 | 31 | | Assert.AreEqual(1, view.GetLandElementsContainer().childCount); |
| 1 | 32 | | Assert.NotNull(view.landElementView); |
| 1 | 33 | | } |
| | 34 | |
|
| | 35 | | [Test] |
| | 36 | | public void SetEmptyCorrectly() |
| | 37 | | { |
| 1 | 38 | | view.SetEmpty(); |
| 1 | 39 | | Assert.IsTrue(view.emptyContainer.activeSelf); |
| 1 | 40 | | Assert.IsFalse(view.contentContainer.activeSelf); |
| 1 | 41 | | Assert.IsFalse(view.loadingAnimationContainer.activeSelf); |
| 1 | 42 | | Assert.IsFalse(view.noSearchResultContainer.activeSelf); |
| 1 | 43 | | } |
| | 44 | |
|
| | 45 | | [Test] |
| | 46 | | public void SetNotEmptyCorrectly() |
| | 47 | | { |
| 1 | 48 | | view.SetFilled(); |
| 1 | 49 | | Assert.IsTrue(view.contentContainer.activeSelf); |
| 1 | 50 | | Assert.IsFalse(view.emptyContainer.activeSelf); |
| 1 | 51 | | Assert.IsFalse(view.loadingAnimationContainer.activeSelf); |
| 1 | 52 | | Assert.IsFalse(view.noSearchResultContainer.activeSelf); |
| 1 | 53 | | } |
| | 54 | |
|
| | 55 | | [Test] |
| | 56 | | public void SetNoSearchResultCorrectly() |
| | 57 | | { |
| 1 | 58 | | view.SetNoSearchResult(); |
| 1 | 59 | | Assert.IsFalse(view.contentContainer.activeSelf); |
| 1 | 60 | | Assert.IsFalse(view.emptyContainer.activeSelf); |
| 1 | 61 | | Assert.IsFalse(view.loadingAnimationContainer.activeSelf); |
| 1 | 62 | | Assert.IsTrue(view.noSearchResultContainer.activeSelf); |
| 1 | 63 | | } |
| | 64 | |
|
| | 65 | | [Test] |
| | 66 | | public void SetLoadingCorrectly() |
| | 67 | | { |
| 1 | 68 | | view.SetLoading(); |
| 1 | 69 | | Assert.IsFalse(view.contentContainer.activeSelf); |
| 1 | 70 | | Assert.IsFalse(view.emptyContainer.activeSelf); |
| 1 | 71 | | Assert.IsTrue(view.loadingAnimationContainer.activeSelf); |
| 1 | 72 | | Assert.IsFalse(view.noSearchResultContainer.activeSelf); |
| 1 | 73 | | } |
| | 74 | |
|
| | 75 | | [Test] |
| | 76 | | public void ShowAndHideCorrectly() |
| | 77 | | { |
| 1 | 78 | | SectionLandController controller = new SectionLandController(view); |
| 1 | 79 | | controller.SetVisible(true); |
| | 80 | |
|
| 1 | 81 | | controller.SetVisible(false); |
| 1 | 82 | | Assert.IsFalse(view.gameObject.activeSelf); |
| | 83 | |
|
| 1 | 84 | | controller.SetVisible(true); |
| 1 | 85 | | Assert.IsTrue(view.gameObject.activeSelf); |
| 1 | 86 | | controller.Dispose(); |
| 1 | 87 | | } |
| | 88 | |
|
| | 89 | | [Test] |
| | 90 | | public void SetLandsCorrectly() |
| | 91 | | { |
| 1 | 92 | | SectionLandController controller = new SectionLandController(view); |
| 1 | 93 | | ILandsListener landsListener = controller; |
| | 94 | |
|
| 1 | 95 | | landsListener.OnSetLands(new[] { CreateLandData("1"), CreateLandData("2") }); |
| 1 | 96 | | Assert.AreEqual(2, GetVisibleChildrenAmount(view.GetLandElementsContainer())); |
| 1 | 97 | | Assert.IsTrue(view.contentContainer.activeSelf); |
| | 98 | |
|
| 1 | 99 | | landsListener.OnSetLands(new[] { CreateLandData("1") }); |
| 1 | 100 | | Assert.AreEqual(1, GetVisibleChildrenAmount(view.GetLandElementsContainer())); |
| 1 | 101 | | Assert.IsTrue(view.contentContainer.activeSelf); |
| | 102 | |
|
| 1 | 103 | | landsListener.OnSetLands(new LandWithAccess[] { }); |
| 1 | 104 | | Assert.AreEqual(0, GetVisibleChildrenAmount(view.GetLandElementsContainer())); |
| 1 | 105 | | Assert.IsFalse(view.contentContainer.activeSelf); |
| 1 | 106 | | Assert.IsTrue(view.emptyContainer.activeSelf); |
| | 107 | |
|
| 1 | 108 | | controller.Dispose(); |
| 1 | 109 | | } |
| | 110 | |
|
| | 111 | | [Test] |
| | 112 | | public void UpdateLandCorrectly() |
| | 113 | | { |
| | 114 | | const string startingName = "Temptation"; |
| | 115 | | const string updatedName = "New Temptation"; |
| | 116 | |
|
| 1 | 117 | | SectionLandController controller = new SectionLandController(view); |
| 1 | 118 | | ILandsListener landsListener = controller; |
| 1 | 119 | | LandElementView landElementView = view.GetLandElementeBaseView(); |
| | 120 | |
|
| 1 | 121 | | landsListener.OnSetLands(new[] { CreateLandData("1", startingName) }); |
| 1 | 122 | | Assert.AreEqual(1, GetVisibleChildrenAmount(view.GetLandElementsContainer())); |
| 1 | 123 | | Assert.AreEqual(startingName, landElementView.landName.text); |
| | 124 | |
|
| 1 | 125 | | landsListener.OnSetLands(new[] { CreateLandData("1", updatedName) }); |
| 1 | 126 | | Assert.AreEqual(1, GetVisibleChildrenAmount(view.GetLandElementsContainer())); |
| 1 | 127 | | Assert.AreEqual(updatedName, landElementView.landName.text); |
| | 128 | |
|
| | 129 | |
|
| 1 | 130 | | controller.Dispose(); |
| 1 | 131 | | } |
| | 132 | |
|
| 13 | 133 | | private int GetVisibleChildrenAmount(Transform parent) { return parent.Cast<Transform>().Count(child => child.ga |
| | 134 | |
|
| | 135 | | private LandWithAccess CreateLandData(string id) |
| | 136 | | { |
| 3 | 137 | | return new LandWithAccess( |
| | 138 | | new Land() |
| | 139 | | { |
| | 140 | | id = id, |
| | 141 | | parcels = new List<Parcel>() |
| | 142 | | } |
| | 143 | | ); |
| | 144 | | } |
| | 145 | |
|
| | 146 | | private LandWithAccess CreateLandData(string id, string name) |
| | 147 | | { |
| 2 | 148 | | return new LandWithAccess( |
| | 149 | | new Land() |
| | 150 | | { |
| | 151 | | id = id, |
| | 152 | | name = name, |
| | 153 | | parcels = new List<Parcel>() |
| | 154 | | } |
| | 155 | | ); |
| | 156 | | } |
| | 157 | | } |
| | 158 | | } |