| | 1 | | using DCL; |
| | 2 | | using NSubstitute; |
| | 3 | | using NUnit.Framework; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | namespace Tests.BuildModeHUDControllers |
| | 8 | | { |
| | 9 | | public class QuickBarControllerShould |
| | 10 | | { |
| | 11 | | private QuickBarController quickBarController; |
| | 12 | |
|
| | 13 | | [SetUp] |
| | 14 | | public void SetUp() |
| | 15 | | { |
| 13 | 16 | | quickBarController = new QuickBarController(); |
| 13 | 17 | | quickBarController.Initialize( |
| | 18 | | Substitute.For<IQuickBarView>(), |
| | 19 | | Substitute.For<ISceneCatalogController>()); |
| 13 | 20 | | } |
| | 21 | |
|
| | 22 | | [TearDown] |
| 26 | 23 | | public void TearDown() { quickBarController.Dispose(); } |
| | 24 | |
|
| | 25 | | [Test] |
| | 26 | | [TestCase(0)] |
| | 27 | | [TestCase(1)] |
| | 28 | | [TestCase(2)] |
| | 29 | | public void QuickBarObjectSelectedCorrectly(int objectIndex) |
| | 30 | | { |
| | 31 | | // Arrange |
| 3 | 32 | | CatalogItem catalogItemSelected = null; |
| 9 | 33 | | quickBarController.OnCatalogItemSelected += (item) => { catalogItemSelected = item; }; |
| | 34 | |
|
| 3 | 35 | | quickBarController.quickBarShortcutsCatalogItems = new CatalogItem[3]; |
| 3 | 36 | | quickBarController.quickBarShortcutsCatalogItems[0] = new CatalogItem { id = "testId1" }; |
| 3 | 37 | | quickBarController.quickBarShortcutsCatalogItems[1] = new CatalogItem { id = "testId2" }; |
| 3 | 38 | | quickBarController.quickBarShortcutsCatalogItems[2] = new CatalogItem { id = "testId3" }; |
| | 39 | |
|
| | 40 | | // Act |
| 3 | 41 | | CatalogItem result = quickBarController.QuickBarObjectSelected(objectIndex); |
| | 42 | |
|
| | 43 | | // Assert |
| 3 | 44 | | Assert.AreEqual(catalogItemSelected, result, "The catalog item does not match!"); |
| 3 | 45 | | Assert.AreEqual(catalogItemSelected.id, result.id, "The catalog item id does not match!"); |
| 3 | 46 | | } |
| | 47 | |
|
| | 48 | | [Test] |
| | 49 | | public void SetIndexToDropCorrectly() |
| | 50 | | { |
| | 51 | | // Arrange |
| 1 | 52 | | int testLastIndexDropped = 5; |
| 1 | 53 | | quickBarController.lastIndexDroped = -1; |
| | 54 | |
|
| | 55 | | // Act |
| 1 | 56 | | quickBarController.SetIndexToDrop(testLastIndexDropped); |
| | 57 | |
|
| | 58 | | // Assert |
| 1 | 59 | | Assert.AreEqual(testLastIndexDropped, quickBarController.lastIndexDroped, "The last index dropped does not m |
| 1 | 60 | | } |
| | 61 | |
|
| | 62 | | [Test] |
| | 63 | | public void SceneObjectDroppedFromQuickBarCorrectly() |
| | 64 | | { |
| | 65 | | // Arrange |
| 1 | 66 | | Asset_Texture testTexture = new Asset_Texture(); |
| 1 | 67 | | CatalogItem testCatalogItem = new CatalogItem { }; |
| 1 | 68 | | int testFromIndex = 0; |
| 1 | 69 | | int testToIndex = 1; |
| 1 | 70 | | quickBarController.quickBarShortcutsCatalogItems = new CatalogItem[2]; |
| 1 | 71 | | quickBarController.quickBarShortcutsCatalogItems[0] = testCatalogItem; |
| 1 | 72 | | quickBarController.quickBarShortcutsCatalogItems[1] = null; |
| | 73 | |
|
| | 74 | | // Act |
| 1 | 75 | | quickBarController.SceneObjectDroppedFromQuickBar(testFromIndex, testToIndex, testTexture.texture); |
| | 76 | |
|
| | 77 | | // Assert |
| 1 | 78 | | Assert.AreEqual(testCatalogItem, quickBarController.quickBarShortcutsCatalogItems[1], "The CatalogItem 1 doe |
| 1 | 79 | | quickBarController.quickBarView.Received(1).SetTextureToShortcut(testToIndex, testTexture.texture); |
| 1 | 80 | | Assert.IsNull(quickBarController.quickBarShortcutsCatalogItems[testFromIndex], "The CatalogItem 0 is not nul |
| 1 | 81 | | quickBarController.quickBarView.Received(1).SetShortcutAsEmpty(testFromIndex); |
| 1 | 82 | | } |
| | 83 | |
|
| | 84 | | [Test] |
| | 85 | | public void SceneObjectDroppedFromCatalogCorrectly() |
| | 86 | | { |
| | 87 | | // Act |
| 1 | 88 | | quickBarController.SceneObjectDroppedFromCatalog(null); |
| | 89 | |
|
| | 90 | | // Assert |
| 1 | 91 | | quickBarController.sceneCatalogController.Received(1).GetLastCatalogItemDragged(); |
| 1 | 92 | | } |
| | 93 | |
|
| | 94 | | [Test] |
| | 95 | | [TestCase(0)] |
| | 96 | | [TestCase(1)] |
| | 97 | | [TestCase(2)] |
| | 98 | | public void SetQuickBarShortcutCorrectly(int objectIndex) |
| | 99 | | { |
| | 100 | | // Arrange |
| 3 | 101 | | string testCatalogItemId = "testId"; |
| 3 | 102 | | quickBarController.lastIndexDroped = objectIndex; |
| 3 | 103 | | quickBarController.quickBarShortcutsCatalogItems = new CatalogItem[3]; |
| 3 | 104 | | quickBarController.quickBarShortcutsCatalogItems[0] = new CatalogItem { }; |
| 3 | 105 | | quickBarController.quickBarShortcutsCatalogItems[1] = new CatalogItem { }; |
| 3 | 106 | | quickBarController.quickBarShortcutsCatalogItems[2] = new CatalogItem { }; |
| 3 | 107 | | CatalogItem testItem = new CatalogItem { id = testCatalogItemId }; |
| 3 | 108 | | Texture testTexture = new Texture2D(10, 10); |
| | 109 | |
|
| | 110 | | // Act |
| 3 | 111 | | quickBarController.SetQuickBarShortcut(testItem, objectIndex, testTexture); |
| | 112 | |
|
| | 113 | | // Assert |
| 3 | 114 | | Assert.AreEqual(testCatalogItemId, quickBarController.quickBarShortcutsCatalogItems[objectIndex].id); |
| 3 | 115 | | quickBarController.quickBarView.Received(1).SetTextureToShortcut(objectIndex, testTexture); |
| 3 | 116 | | } |
| | 117 | |
|
| | 118 | | [Test] |
| | 119 | | [TestCase(0)] |
| | 120 | | [TestCase(1)] |
| | 121 | | [TestCase(2)] |
| | 122 | | public void QuickBarInputCorrectly(int quickBarSlotIndex) |
| | 123 | | { |
| | 124 | | // Arrange |
| 3 | 125 | | int selectedQuickBarSlot = -1; |
| 9 | 126 | | quickBarController.OnQuickBarShortcutSelected += (quickBarSlot) => { selectedQuickBarSlot = quickBarSlot; }; |
| | 127 | |
|
| | 128 | | // Act |
| 3 | 129 | | quickBarController.QuickBarInput(quickBarSlotIndex); |
| | 130 | |
|
| | 131 | | // Assert |
| 3 | 132 | | Assert.AreEqual(quickBarSlotIndex, selectedQuickBarSlot, "The QuickBar Slot index does not match!"); |
| 3 | 133 | | } |
| | 134 | |
|
| | 135 | | [Test] |
| | 136 | | public void CancelDraggingCorrectly() |
| | 137 | | { |
| | 138 | | // Act |
| 1 | 139 | | quickBarController.CancelDragging(); |
| | 140 | |
|
| | 141 | | // Assert |
| 1 | 142 | | quickBarController.quickBarView.Received(1).CancelCurrentDragging(); |
| 1 | 143 | | } |
| | 144 | | } |
| | 145 | | } |