| | 1 | | using System.Collections.Generic; |
| | 2 | | using System.Linq; |
| | 3 | | using NSubstitute; |
| | 4 | | using NUnit.Framework; |
| | 5 | | using UnityEditor; |
| | 6 | | using UnityEngine; |
| | 7 | |
|
| | 8 | | namespace Tests |
| | 9 | | { |
| | 10 | | public class SectionDeployedScenesViewShould |
| | 11 | | { |
| | 12 | | private SectionDeployedScenesView view; |
| | 13 | |
|
| | 14 | | [SetUp] |
| | 15 | | public void SetUp() |
| | 16 | | { |
| 7 | 17 | | var prefab = Resources.Load<SectionDeployedScenesView>(SectionDeployedScenesController.VIEW_PREFAB_PATH); |
| 7 | 18 | | view = Object.Instantiate(prefab); |
| 7 | 19 | | } |
| | 20 | |
|
| | 21 | | [TearDown] |
| 14 | 22 | | public void TearDown() { Object.Destroy(view.gameObject); } |
| | 23 | |
|
| | 24 | | [Test] |
| 2 | 25 | | public void HaveScenesContainerEmptyAtInstantiation() { Assert.AreEqual(0, view.scenesCardContainer.childCount); |
| | 26 | |
|
| | 27 | | [Test] |
| | 28 | | public void ShowCardsInCorrectSortOrder() |
| | 29 | | { |
| | 30 | | const string prefabAssetPath = |
| | 31 | | "Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Prefabs/SceneCardView.prefab"; |
| 1 | 32 | | var prefab = AssetDatabase.LoadAssetAtPath<SceneCardView>(prefabAssetPath); |
| | 33 | |
|
| 1 | 34 | | Dictionary<string, ISceneCardView> cardViews = new Dictionary<string, ISceneCardView>(); |
| | 35 | | const int cardsCount = 10; |
| 22 | 36 | | for (int i = 0; i < cardsCount; i++) |
| | 37 | | { |
| 10 | 38 | | var card = (ISceneCardView)Object.Instantiate(prefab); |
| 10 | 39 | | card.Setup(new SceneData() { size = new Vector2Int(i, i), id = i.ToString() }); |
| 10 | 40 | | cardViews.Add(i.ToString(), card); |
| | 41 | | } |
| | 42 | |
|
| | 43 | |
|
| 1 | 44 | | SectionDeployedScenesController controller = new SectionDeployedScenesController(view); |
| 1 | 45 | | controller.searchHandler.SetSortType(SectionSearchHandler.SIZE_SORT_TYPE_ASC); |
| | 46 | |
|
| 1 | 47 | | ((IDeployedSceneListener)controller).OnSetScenes(cardViews); |
| | 48 | |
|
| 1 | 49 | | Assert.AreEqual(cardsCount, view.scenesCardContainer.childCount); |
| | 50 | |
|
| 1 | 51 | | var prev = (ISceneCardView)view.scenesCardContainer.GetChild(0).GetComponent<SceneCardView>(); |
| 20 | 52 | | for (int i = 1; i < cardsCount; i++) |
| | 53 | | { |
| 9 | 54 | | var current = (ISceneCardView)view.scenesCardContainer.GetChild(i).GetComponent<SceneCardView>(); |
| 9 | 55 | | Assert.GreaterOrEqual(current.sceneData.size.x * current.sceneData.size.y, prev.sceneData.size.x * prev. |
| 9 | 56 | | prev = current; |
| | 57 | | } |
| | 58 | |
|
| 22 | 59 | | foreach (var card in cardViews.Values) |
| | 60 | | { |
| 10 | 61 | | card.Dispose(); |
| | 62 | | } |
| 1 | 63 | | controller.Dispose(); |
| 1 | 64 | | } |
| | 65 | |
|
| | 66 | | [Test] |
| | 67 | | public void ShowEmptyCorrectly() |
| | 68 | | { |
| 1 | 69 | | view.SetEmpty(); |
| 1 | 70 | | Assert.IsFalse(view.contentContainer.activeSelf); |
| 1 | 71 | | Assert.IsFalse(view.loadingAnimationContainer.activeSelf); |
| 1 | 72 | | Assert.IsFalse(view.noSearchResultContainer.activeSelf); |
| 1 | 73 | | Assert.IsTrue(view.emptyContainer.activeSelf); |
| 1 | 74 | | } |
| | 75 | |
|
| | 76 | | [Test] |
| | 77 | | public void ShowFilledCorrectly() |
| | 78 | | { |
| 1 | 79 | | view.SetFilled(); |
| 1 | 80 | | Assert.IsTrue(view.contentContainer.activeSelf); |
| 1 | 81 | | Assert.IsFalse(view.loadingAnimationContainer.activeSelf); |
| 1 | 82 | | Assert.IsFalse(view.noSearchResultContainer.activeSelf); |
| 1 | 83 | | Assert.IsFalse(view.emptyContainer.activeSelf); |
| 1 | 84 | | } |
| | 85 | |
|
| | 86 | | [Test] |
| | 87 | | public void ShowNoResultCorrectly() |
| | 88 | | { |
| 1 | 89 | | view.SetNoSearchResult(); |
| 1 | 90 | | Assert.IsFalse(view.contentContainer.activeSelf); |
| 1 | 91 | | Assert.IsFalse(view.loadingAnimationContainer.activeSelf); |
| 1 | 92 | | Assert.IsTrue(view.noSearchResultContainer.activeSelf); |
| 1 | 93 | | Assert.IsFalse(view.emptyContainer.activeSelf); |
| 1 | 94 | | } |
| | 95 | |
|
| | 96 | | [Test] |
| | 97 | | public void ShowLoadingCorrectly() |
| | 98 | | { |
| 1 | 99 | | view.SetLoading(); |
| 1 | 100 | | Assert.IsFalse(view.contentContainer.activeSelf); |
| 1 | 101 | | Assert.IsTrue(view.loadingAnimationContainer.activeSelf); |
| 1 | 102 | | Assert.IsFalse(view.noSearchResultContainer.activeSelf); |
| 1 | 103 | | Assert.IsFalse(view.emptyContainer.activeSelf); |
| 1 | 104 | | } |
| | 105 | |
|
| | 106 | | [Test] |
| | 107 | | public void SetSectionStateCorrectly() |
| | 108 | | { |
| 1 | 109 | | SectionDeployedScenesController controller = new SectionDeployedScenesController(view); |
| 1 | 110 | | IDeployedSceneListener listener = controller; |
| | 111 | |
|
| 1 | 112 | | controller.SetFetchingDataState(true); |
| 1 | 113 | | listener.OnSetScenes(new Dictionary<string, ISceneCardView>()); |
| 1 | 114 | | Assert.IsTrue(view.loadingAnimationContainer.activeSelf); |
| | 115 | |
|
| 1 | 116 | | controller.SetFetchingDataState(false); |
| 1 | 117 | | listener.OnSetScenes(new Dictionary<string, ISceneCardView>()); |
| 1 | 118 | | Assert.IsTrue(view.emptyContainer.activeSelf); |
| | 119 | |
|
| 1 | 120 | | listener.OnSetScenes(new Dictionary<string, ISceneCardView>() { { "1", Substitute.For<ISceneCardView>() }, { |
| 1 | 121 | | Assert.IsTrue(view.contentContainer.activeSelf); |
| | 122 | |
|
| 1 | 123 | | listener.OnSetScenes(new Dictionary<string, ISceneCardView>() { { "1", Substitute.For<ISceneCardView>() } }) |
| 1 | 124 | | Assert.IsTrue(view.contentContainer.activeSelf); |
| | 125 | |
|
| 1 | 126 | | controller.Dispose(); |
| 1 | 127 | | } |
| | 128 | | } |
| | 129 | | } |