| | 1 | | using System.Collections.Generic; |
| | 2 | | using NUnit.Framework; |
| | 3 | | using UnityEditor; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace Tests |
| | 7 | | { |
| | 8 | | public class SectionProjectScenesViewShould |
| | 9 | | { |
| | 10 | | private SectionProjectScenesView view; |
| | 11 | |
|
| | 12 | | [SetUp] |
| | 13 | | public void SetUp() |
| | 14 | | { |
| 2 | 15 | | var prefab = Resources.Load<SectionProjectScenesView>(SectionProjectScenesController.VIEW_PREFAB_PATH); |
| 2 | 16 | | view = Object.Instantiate(prefab); |
| 2 | 17 | | } |
| | 18 | |
|
| | 19 | | [TearDown] |
| 4 | 20 | | public void TearDown() { Object.Destroy(view.gameObject); } |
| | 21 | |
|
| | 22 | | [Test] |
| 2 | 23 | | public void HaveScenesContainerEmptyAtInstantiation() { Assert.AreEqual(0, view.scenesCardContainer.childCount); |
| | 24 | |
|
| | 25 | | [Test] |
| | 26 | | public void ShowCardsInCorrectSortOrder() |
| | 27 | | { |
| | 28 | | const string prefabAssetPath = |
| | 29 | | "Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Prefabs/SceneCardView.prefab"; |
| 1 | 30 | | var prefab = AssetDatabase.LoadAssetAtPath<SceneCardView>(prefabAssetPath); |
| | 31 | |
|
| 1 | 32 | | Dictionary<string, ISceneCardView> cardViews = new Dictionary<string, ISceneCardView>(); |
| | 33 | | const int cardsCount = 10; |
| 22 | 34 | | for (int i = 0; i < cardsCount; i++) |
| | 35 | | { |
| 10 | 36 | | var card = (ISceneCardView)Object.Instantiate(prefab); |
| 10 | 37 | | card.Setup(new SceneData() { size = new Vector2Int(i, i), id = i.ToString() }); |
| 10 | 38 | | cardViews.Add(i.ToString(), card); |
| | 39 | | } |
| | 40 | |
|
| | 41 | |
|
| 1 | 42 | | SectionProjectScenesController controller = new SectionProjectScenesController(view); |
| 1 | 43 | | controller.searchHandler.SetSortType(SectionSearchHandler.SIZE_SORT_TYPE_DESC); |
| | 44 | |
|
| 1 | 45 | | ((IProjectSceneListener)controller).OnSetScenes(cardViews); |
| | 46 | |
|
| 1 | 47 | | Assert.AreEqual(cardsCount, view.scenesCardContainer.childCount); |
| | 48 | |
|
| 1 | 49 | | var prev = (ISceneCardView)view.scenesCardContainer.GetChild(0).GetComponent<SceneCardView>(); |
| 20 | 50 | | for (int i = 1; i < cardsCount; i++) |
| | 51 | | { |
| 9 | 52 | | var current = (ISceneCardView)view.scenesCardContainer.GetChild(i).GetComponent<SceneCardView>(); |
| 9 | 53 | | Assert.LessOrEqual(current.sceneData.size.x * current.sceneData.size.y, prev.sceneData.size.x * prev.sce |
| 9 | 54 | | prev = current; |
| | 55 | | } |
| | 56 | |
|
| 22 | 57 | | foreach (var card in cardViews.Values) |
| | 58 | | { |
| 10 | 59 | | card.Dispose(); |
| | 60 | | } |
| 1 | 61 | | controller.Dispose(); |
| 1 | 62 | | } |
| | 63 | | } |
| | 64 | | } |