< Summary

Class:Tests.BuildModeHUDViews.QuickBarViewShould
Assembly:BuildModeHUDTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuildModeHUD/Tests/QuickBarViewShould.cs
Covered lines:78
Uncovered lines:0
Coverable lines:78
Total lines:191
Line coverage:100% (78 of 78)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%110100%
TearDown()0%110100%
SelectQuickBarObjectCorrectly()0%110100%
SetIndexToBeginDragCorrectly()0%110100%
SetIndexToDropCorrectly()0%110100%
DropSceneObjectFromQuickBarCorrectly()0%110100%
DropSceneObjectFromCatalogCorrectly()0%110100%
TriggerQuickBarInputCorrectly()0%110100%
BeginDragSlotCorrectly()0%110100%
DragSlotCorrectly()0%110100%
EndDragSlotCorrectly()0%110100%
CancelCurrentDraggingCorrectly()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuildModeHUD/Tests/QuickBarViewShould.cs

#LineLine coverage
 1using NUnit.Framework;
 2using UnityEngine;
 3using UnityEngine.EventSystems;
 4
 5namespace Tests.BuildModeHUDViews
 6{
 7    public class QuickBarViewShould
 8    {
 9        private QuickBarView quickBarView;
 10
 11        [SetUp]
 12        public void SetUp()
 13        {
 1014            quickBarView = QuickBarView.Create();
 1015            quickBarView.generalCanvas = new GameObject().AddComponent<Canvas>();
 1016        }
 17
 18        [TearDown]
 2019        public void TearDown() { Object.Destroy(quickBarView.gameObject); }
 20
 21        [Test]
 22        public void SelectQuickBarObjectCorrectly()
 23        {
 24            // Arrange
 125            int selectedObjectIndex = -1;
 126            int indexToSelect = 3;
 227            quickBarView.OnQuickBarObjectSelected += (index) => selectedObjectIndex = index;
 28
 29            // Act
 130            quickBarView.QuickBarObjectSelected(indexToSelect);
 31
 32            // Assert
 133            Assert.AreEqual(indexToSelect, selectedObjectIndex, "The selected object index does not match!");
 134        }
 35
 36        [Test]
 37        public void SetIndexToBeginDragCorrectly()
 38        {
 39            // Arrange
 140            int draggedObjectIndex = -1;
 141            int indexToBeginDrag = 3;
 242            quickBarView.OnSetIndexToBeginDrag += (index) => draggedObjectIndex = index;
 43
 44            // Act
 145            quickBarView.SetIndexToBeginDrag(indexToBeginDrag);
 46
 47            // Assert
 148            Assert.AreEqual(indexToBeginDrag, draggedObjectIndex, "The dragged object index does not match!");
 149        }
 50
 51        [Test]
 52        public void SetIndexToDropCorrectly()
 53        {
 54            // Arrange
 155            int dropObjectIndex = -1;
 156            int indexToDrop = 3;
 257            quickBarView.OnSetIndexToDrop += (index) => dropObjectIndex = index;
 58
 59            // Act
 160            quickBarView.SetIndexToDrop(indexToDrop);
 61
 62            // Assert
 163            Assert.AreEqual(indexToDrop, dropObjectIndex, "The drop object index does not match!");
 164        }
 65
 66        [Test]
 67        public void DropSceneObjectFromQuickBarCorrectly()
 68        {
 69            // Arrange
 170            Texture testTexture = null;
 171            int testFromIndex = 0;
 172            int testToIndex = 1;
 73            Texture returnedTexture;
 174            int returnedFromIndex = 0;
 175            int returnedToIndex = 1;
 76
 177            quickBarView.OnSceneObjectDroppedFromQuickBar += (fromIndex, toIndex, texture) =>
 78            {
 179                returnedFromIndex = fromIndex;
 180                returnedToIndex = toIndex;
 181                returnedTexture = texture;
 182            };
 83
 84            // Act
 185            quickBarView.SceneObjectDroppedFromQuickBar(testFromIndex, testToIndex, testTexture);
 86
 87            // Assert
 188            Assert.AreEqual(returnedFromIndex, testFromIndex, "The returnedFromIndex does not match!");
 189            Assert.AreEqual(returnedToIndex, testToIndex, "The returnedToIndex does not match!");
 190        }
 91
 92        [Test]
 93        public void DropSceneObjectFromCatalogCorrectly()
 94        {
 95            // Arrange
 196            BaseEventData droppedObject = null;
 197            BaseEventData objectToDrop = new BaseEventData(null);
 298            quickBarView.OnSceneObjectDroppedFromCatalog += (data) => droppedObject = data;
 99
 100            // Act
 1101            quickBarView.SceneObjectDroppedFromCatalog(objectToDrop);
 102
 103            // Assert
 1104            Assert.IsNotNull(droppedObject, "The dropped object is null!");
 1105            Assert.AreEqual(objectToDrop, droppedObject, "The dropped object does not match!");
 1106        }
 107
 108        [Test]
 109        public void TriggerQuickBarInputCorrectly()
 110        {
 111            // Arrange
 1112            int triggeredIndex = -1;
 1113            int indexToDrop = 3;
 2114            quickBarView.OnQuickBarInputTriggered += (index) => triggeredIndex = index;
 115
 116            // Act
 1117            quickBarView.OnQuickBarInputTriggedered(indexToDrop);
 118
 119            // Assert
 1120            Assert.AreEqual(indexToDrop, triggeredIndex, "The triggered index does not match!");
 1121        }
 122
 123        [Test]
 124        public void BeginDragSlotCorrectly()
 125        {
 126            // Arrange
 1127            int testIndex = 0;
 1128            quickBarView.lastIndexToBeginDrag = -1;
 1129            quickBarView.shortcutsImgs[0].SetTexture(new Texture2D(10, 10));
 130
 131
 132            // Act
 1133            quickBarView.BeginDragSlot(testIndex);
 134
 135            // Assert
 1136            Assert.AreEqual(testIndex, quickBarView.lastIndexToBeginDrag, "The lastIndexToBeginDrag does not match!");
 1137            Assert.IsTrue(quickBarView.draggedSlot.isActiveAndEnabled, "The draggedSlot is not active!");
 1138            Assert.IsTrue(quickBarView.draggedSlot.image.isActiveAndEnabled, "The draggedSlot image is not active!");
 1139        }
 140
 141        [Test]
 142        public void DragSlotCorrectly()
 143        {
 144            // Arrange
 1145            PointerEventData testEventData = new PointerEventData(null);
 1146            testEventData.position = new Vector2(5, 3);
 1147            int testIndex = 0;
 1148            quickBarView.draggedSlot.slotTransform.position = Vector3.zero;
 1149            quickBarView.shortcutsImgs[0].SetTexture(new Texture2D(10, 10));
 150
 151
 152            // Act
 1153            quickBarView.DragSlot(testEventData, testIndex);
 154
 155            // Assert
 1156            Assert.AreEqual(testEventData.position, (Vector2)quickBarView.draggedSlot.slotTransform.position, "The dragg
 1157        }
 158
 159        [Test]
 160        public void EndDragSlotCorrectly()
 161        {
 162            // Arrange
 1163            int testIndex = 0;
 1164            int returnedIndex = -1;
 1165            quickBarView.shortcutsImgs[0].SetTexture(new Texture2D(10, 10));
 3166            quickBarView.OnQuickBarObjectSelected += (index) => { returnedIndex = index; };
 167
 168
 169            // Act
 1170            quickBarView.EndDragSlot(testIndex);
 171
 172            // Assert
 1173            Assert.IsFalse(quickBarView.draggedSlot.image.isActiveAndEnabled, "The draggedSlot image is active!");
 1174            Assert.IsFalse(quickBarView.draggedSlot.isActiveAndEnabled, "The draggedSlot is active!");
 1175            Assert.AreEqual(testIndex, returnedIndex, "The selected index does not match!");
 1176        }
 177
 178        [Test]
 179        public void CancelCurrentDraggingCorrectly()
 180        {
 181            // Arrange
 1182            quickBarView.lastIndexToBeginDrag = 5;
 183
 184            // Act
 1185            quickBarView.CancelCurrentDragging();
 186
 187            // Assert
 1188            Assert.AreEqual(-1, quickBarView.lastIndexToBeginDrag, "The lastIndexToBeginDrag does not match!");
 1189        }
 190    }
 191}