| | 1 | | using NUnit.Framework; |
| | 2 | | using UnityEditor; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace Tests |
| | 6 | | { |
| | 7 | | public class SceneCardViewShould |
| | 8 | | { |
| | 9 | | private SceneCardView cardView; |
| | 10 | |
|
| | 11 | | [SetUp] |
| | 12 | | public void SetUp() |
| | 13 | | { |
| | 14 | | const string prefabAssetPath = |
| | 15 | | "Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Prefabs/SceneCardView.prefab"; |
| 4 | 16 | | var prefab = AssetDatabase.LoadAssetAtPath<SceneCardView>(prefabAssetPath); |
| 4 | 17 | | cardView = UnityEngine.Object.Instantiate(prefab); |
| 4 | 18 | | } |
| | 19 | |
|
| | 20 | | [TearDown] |
| 8 | 21 | | public void TearDown() { UnityEngine.Object.Destroy(cardView.gameObject); } |
| | 22 | |
|
| | 23 | | [Test] |
| | 24 | | public void DisplayCorrectlyWhenSceneIsDeployed() |
| | 25 | | { |
| 1 | 26 | | ((ISceneCardView)cardView).Setup(new SceneData() |
| | 27 | | { |
| | 28 | | id = "", |
| | 29 | | isDeployed = true, |
| | 30 | | name = "test", |
| | 31 | | coords = Vector2Int.zero, |
| | 32 | | size = Vector2Int.zero, |
| | 33 | | isOwner = true, |
| | 34 | | isEditable = true |
| | 35 | | }); |
| | 36 | |
|
| | 37 | | //should show both jump-in and editor buttons |
| 1 | 38 | | Assert.IsTrue(cardView.jumpInButton.gameObject.activeSelf, "JumpIn button should be active"); |
| 1 | 39 | | Assert.IsTrue(cardView.editorButton.gameObject.activeSelf, "Editor button should be active"); |
| | 40 | |
|
| | 41 | | //should show coords instead of size |
| 1 | 42 | | Assert.IsTrue(cardView.coordsContainer.activeSelf, "Coords should be displayed"); |
| 1 | 43 | | Assert.IsFalse(cardView.sizeContainer.activeSelf, "Size should not be displayed"); |
| | 44 | |
|
| | 45 | | //should show role |
| 1 | 46 | | Assert.IsTrue(cardView.roleOwnerGO.activeSelf, "Owner role tag should be displayed"); |
| 1 | 47 | | Assert.IsFalse(cardView.roleOperatorGO.activeSelf, "Operator role tag should not be displayed"); |
| 1 | 48 | | Assert.IsFalse(cardView.roleContributorGO.activeSelf, "Contributor role tag should not be displayed"); |
| 1 | 49 | | } |
| | 50 | |
|
| | 51 | | [Test] |
| | 52 | | public void DisplayCorrectlyWhenSceneIsNotDeployed() |
| | 53 | | { |
| 1 | 54 | | ((ISceneCardView)cardView).Setup(new SceneData() |
| | 55 | | { |
| | 56 | | id = "", |
| | 57 | | isDeployed = false, |
| | 58 | | name = "test", |
| | 59 | | coords = Vector2Int.zero, |
| | 60 | | size = Vector2Int.zero, |
| | 61 | | isContributor = true, |
| | 62 | | isEditable = true |
| | 63 | | }); |
| | 64 | |
|
| | 65 | | //should show only editor button, no jump-in |
| 1 | 66 | | Assert.IsFalse(cardView.jumpInButton.gameObject.activeSelf, "JumpIn button should not be active"); |
| 1 | 67 | | Assert.IsTrue(cardView.editorButton.gameObject.activeSelf, "Editor button should be active"); |
| | 68 | |
|
| | 69 | | //should show size instead of coords |
| 1 | 70 | | Assert.IsFalse(cardView.coordsContainer.activeSelf, "Coords should not be displayed"); |
| 1 | 71 | | Assert.IsTrue(cardView.sizeContainer.activeSelf, "Size should be displayed"); |
| | 72 | |
|
| | 73 | | //should show role |
| 1 | 74 | | Assert.IsTrue(cardView.roleContributorGO.activeSelf, "Contributor role tag should be displayed"); |
| 1 | 75 | | Assert.IsFalse(cardView.roleOperatorGO.activeSelf, "Operator role tag should not be displayed"); |
| 1 | 76 | | Assert.IsFalse(cardView.roleOwnerGO.activeSelf, "Owner role tag should not be displayed"); |
| 1 | 77 | | } |
| | 78 | |
|
| | 79 | | [Test] |
| | 80 | | public void DisplayCorrectlyWhenSceneIsNotEditable() |
| | 81 | | { |
| 1 | 82 | | ((ISceneCardView)cardView).Setup(new SceneData() |
| | 83 | | { |
| | 84 | | id = "", |
| | 85 | | isDeployed = false, |
| | 86 | | name = "test", |
| | 87 | | coords = Vector2Int.zero, |
| | 88 | | size = Vector2Int.zero, |
| | 89 | | isContributor = true, |
| | 90 | | isEditable = false |
| | 91 | | }); |
| | 92 | |
|
| 1 | 93 | | Assert.IsFalse(cardView.editorButton.gameObject.activeSelf, "Editor button should not be active"); |
| 1 | 94 | | Assert.IsTrue(cardView.editorLockedGO.activeSelf, "Editor locked indicator should be active"); |
| 1 | 95 | | } |
| | 96 | |
|
| | 97 | | [Test] |
| | 98 | | public void DisplayCorrectlyWhenSceneIsEditable() |
| | 99 | | { |
| 1 | 100 | | ((ISceneCardView)cardView).Setup(new SceneData() |
| | 101 | | { |
| | 102 | | id = "", |
| | 103 | | isDeployed = false, |
| | 104 | | name = "test", |
| | 105 | | coords = Vector2Int.zero, |
| | 106 | | size = Vector2Int.zero, |
| | 107 | | isContributor = true, |
| | 108 | | isEditable = true |
| | 109 | | }); |
| | 110 | |
|
| 1 | 111 | | Assert.IsTrue(cardView.editorButton.gameObject.activeSelf, "Editor button should be active"); |
| 1 | 112 | | Assert.IsFalse(cardView.editorLockedGO.activeSelf, "Editor locked indicator should not be active"); |
| 1 | 113 | | } |
| | 114 | | } |
| | 115 | | } |