| | 1 | | using DCL.Configuration; |
| | 2 | | using NSubstitute; |
| | 3 | | using NUnit.Framework; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace Tests.BuildModeHUDViews |
| | 7 | | { |
| | 8 | | public class TopActionsButtonsViewShould |
| | 9 | | { |
| | 10 | | private TopActionsButtonsView topActionsButtonsView; |
| | 11 | |
|
| | 12 | | [SetUp] |
| 38 | 13 | | public void SetUp() { topActionsButtonsView = TopActionsButtonsView.Create(); } |
| | 14 | |
|
| | 15 | | [TearDown] |
| 38 | 16 | | public void TearDown() { Object.Destroy(topActionsButtonsView.gameObject); } |
| | 17 | |
|
| | 18 | | [Test] |
| | 19 | | public void ConfigureExtraActionsCorrectly() |
| | 20 | | { |
| | 21 | | // Arrange |
| 1 | 22 | | IExtraActionsController mockedExtraActionsController = Substitute.For<IExtraActionsController>(); |
| 1 | 23 | | topActionsButtonsView.extraActionsController = null; |
| | 24 | |
|
| | 25 | |
|
| | 26 | | // Act |
| 1 | 27 | | topActionsButtonsView.ConfigureExtraActions(mockedExtraActionsController); |
| | 28 | |
|
| | 29 | | // Assert |
| 1 | 30 | | Assert.AreEqual(mockedExtraActionsController, topActionsButtonsView.extraActionsController, "The extra actio |
| 1 | 31 | | mockedExtraActionsController.Received(1).Initialize(topActionsButtonsView.extraActionsView); |
| 1 | 32 | | } |
| | 33 | |
|
| | 34 | | [Test] |
| | 35 | | public void ClickOnChangeModeCorrectly() |
| | 36 | | { |
| | 37 | | // Arrange |
| 1 | 38 | | bool modeIsChanged = false; |
| 2 | 39 | | topActionsButtonsView.OnChangeModeClicked += () => modeIsChanged = true; |
| | 40 | |
|
| | 41 | | // Act |
| 1 | 42 | | topActionsButtonsView.OnChangeModeClick(new DCLAction_Trigger()); |
| | 43 | |
|
| | 44 | | // Assert |
| 1 | 45 | | Assert.IsTrue(modeIsChanged, "modeIsChanged is false!"); |
| 1 | 46 | | } |
| | 47 | |
|
| | 48 | | [Test] |
| | 49 | | public void ClickOnExtraCorrectly() |
| | 50 | | { |
| | 51 | | // Arrange |
| 1 | 52 | | bool extraClicked = false; |
| 2 | 53 | | topActionsButtonsView.OnExtraClicked += () => extraClicked = true; |
| | 54 | |
|
| | 55 | | // Act |
| 1 | 56 | | topActionsButtonsView.OnExtraClick(new DCLAction_Trigger()); |
| | 57 | |
|
| | 58 | | // Assert |
| 1 | 59 | | Assert.IsTrue(extraClicked, "extraClicked is false!"); |
| 1 | 60 | | } |
| | 61 | |
|
| | 62 | | [Test] |
| | 63 | | public void ClickOnTranslateCorrectly() |
| | 64 | | { |
| | 65 | | // Arrange |
| 1 | 66 | | bool translateClicked = false; |
| 2 | 67 | | topActionsButtonsView.OnTranslateClicked += () => translateClicked = true; |
| | 68 | |
|
| | 69 | | // Act |
| 1 | 70 | | topActionsButtonsView.OnTranslateClick(new DCLAction_Trigger()); |
| | 71 | |
|
| | 72 | | // Assert |
| 1 | 73 | | Assert.IsTrue(translateClicked, "translateClicked is false!"); |
| 1 | 74 | | } |
| | 75 | |
|
| | 76 | | [Test] |
| | 77 | | public void ClickOnRotateCorrectly() |
| | 78 | | { |
| | 79 | | // Arrange |
| 1 | 80 | | bool rotateClicked = false; |
| 2 | 81 | | topActionsButtonsView.OnRotateClicked += () => rotateClicked = true; |
| | 82 | |
|
| | 83 | | // Act |
| 1 | 84 | | topActionsButtonsView.OnRotateClick(new DCLAction_Trigger()); |
| | 85 | |
|
| | 86 | | // Assert |
| 1 | 87 | | Assert.IsTrue(rotateClicked, "rotateClicked is false!"); |
| 1 | 88 | | } |
| | 89 | |
|
| | 90 | | [Test] |
| | 91 | | public void ClickOnScaleCorrectly() |
| | 92 | | { |
| | 93 | | // Arrange |
| 1 | 94 | | bool scaleClicked = false; |
| 2 | 95 | | topActionsButtonsView.OnScaleClicked += () => scaleClicked = true; |
| | 96 | |
|
| | 97 | | // Act |
| 1 | 98 | | topActionsButtonsView.OnScaleClick(new DCLAction_Trigger()); |
| | 99 | |
|
| | 100 | | // Assert |
| 1 | 101 | | Assert.IsTrue(scaleClicked, "scaleClicked is false!"); |
| 1 | 102 | | } |
| | 103 | |
|
| | 104 | | [Test] |
| | 105 | | public void ClickOnUndoCorrectly() |
| | 106 | | { |
| | 107 | | // Arrange |
| 1 | 108 | | bool undoClicked = false; |
| 2 | 109 | | topActionsButtonsView.OnUndoClicked += () => undoClicked = true; |
| | 110 | |
|
| | 111 | | // Act |
| 1 | 112 | | topActionsButtonsView.OnUndoClick(); |
| | 113 | |
|
| | 114 | | // Assert |
| 1 | 115 | | Assert.IsTrue(undoClicked, "undoClicked is false!"); |
| 1 | 116 | | } |
| | 117 | |
|
| | 118 | | [Test] |
| | 119 | | public void ClickOnRedoCorrectly() |
| | 120 | | { |
| | 121 | | // Arrange |
| 1 | 122 | | bool redoClicked = false; |
| 2 | 123 | | topActionsButtonsView.OnRedoClicked += () => redoClicked = true; |
| | 124 | |
|
| | 125 | | // Act |
| 1 | 126 | | topActionsButtonsView.OnRedoClick(); |
| | 127 | |
|
| | 128 | | // Assert |
| 1 | 129 | | Assert.IsTrue(redoClicked, "undoClicked is false!"); |
| 1 | 130 | | } |
| | 131 | |
|
| | 132 | | [Test] |
| | 133 | | public void ClickOnDuplicateCorrectly() |
| | 134 | | { |
| | 135 | | // Arrange |
| 1 | 136 | | bool duplicateClicked = false; |
| 2 | 137 | | topActionsButtonsView.OnDuplicateClicked += () => duplicateClicked = true; |
| | 138 | |
|
| | 139 | | // Act |
| 1 | 140 | | topActionsButtonsView.OnDuplicateClick(new DCLAction_Trigger()); |
| | 141 | |
|
| | 142 | | // Assert |
| 1 | 143 | | Assert.IsTrue(duplicateClicked, "duplicateClicked is false!"); |
| 1 | 144 | | } |
| | 145 | |
|
| | 146 | | [Test] |
| | 147 | | public void ClickOnDeleteCorrectly() |
| | 148 | | { |
| | 149 | | // Arrange |
| 1 | 150 | | bool deleteClicked = false; |
| 2 | 151 | | topActionsButtonsView.OnDeleteClicked += () => deleteClicked = true; |
| | 152 | |
|
| | 153 | | // Act |
| 1 | 154 | | topActionsButtonsView.OnDeleteClick(new DCLAction_Trigger()); |
| | 155 | |
|
| | 156 | | // Assert |
| 1 | 157 | | Assert.IsTrue(deleteClicked, "deleteClicked is false!"); |
| 1 | 158 | | } |
| | 159 | |
|
| | 160 | | [Test] |
| | 161 | | public void ClickOnLogoutCorrectly() |
| | 162 | | { |
| | 163 | | // Arrange |
| 1 | 164 | | bool logoutClicked = false; |
| 2 | 165 | | topActionsButtonsView.OnLogOutClicked += () => logoutClicked = true; |
| | 166 | |
|
| | 167 | | // Act |
| 1 | 168 | | topActionsButtonsView.OnLogOutClick(new DCLAction_Trigger()); |
| | 169 | |
|
| | 170 | | // Assert |
| 1 | 171 | | Assert.IsTrue(logoutClicked, "logoutClicked is false!"); |
| 1 | 172 | | } |
| | 173 | |
|
| | 174 | | [Test] |
| | 175 | | public void SetTranslateActiveGizmosCorrectly() |
| | 176 | | { |
| | 177 | | //Arrange |
| 1 | 178 | | string gizmosActive = BuilderInWorldSettings.TRANSLATE_GIZMO_NAME; |
| | 179 | |
|
| | 180 | | // Act |
| 1 | 181 | | topActionsButtonsView.SetGizmosActive(gizmosActive); |
| | 182 | |
|
| | 183 | | // Assert |
| 1 | 184 | | Assert.AreEqual(topActionsButtonsView.translateGizmosBtnImg.color , topActionsButtonsView.selectedBtnImgColo |
| 1 | 185 | | Assert.AreEqual(topActionsButtonsView.rotateGizmosBtnImg.color , topActionsButtonsView.normalBtnImgColor); |
| 1 | 186 | | Assert.AreEqual(topActionsButtonsView.scaleGizmosBtnImg.color , topActionsButtonsView.normalBtnImgColor); |
| 1 | 187 | | } |
| | 188 | |
|
| | 189 | | [Test] |
| | 190 | | public void SetRotateActiveGizmosCorrectly() |
| | 191 | | { |
| | 192 | | //Arrange |
| 1 | 193 | | string gizmosActive = BuilderInWorldSettings.ROTATE_GIZMO_NAME; |
| | 194 | |
|
| | 195 | | // Act |
| 1 | 196 | | topActionsButtonsView.SetGizmosActive(gizmosActive); |
| | 197 | |
|
| | 198 | | // Assert |
| 1 | 199 | | Assert.AreEqual(topActionsButtonsView.translateGizmosBtnImg.color , topActionsButtonsView.normalBtnImgColor) |
| 1 | 200 | | Assert.AreEqual(topActionsButtonsView.rotateGizmosBtnImg.color , topActionsButtonsView.selectedBtnImgColor); |
| 1 | 201 | | Assert.AreEqual(topActionsButtonsView.scaleGizmosBtnImg.color , topActionsButtonsView.normalBtnImgColor); |
| 1 | 202 | | } |
| | 203 | |
|
| | 204 | | [Test] |
| | 205 | | public void SetScaleActiveGizmosCorrectly() |
| | 206 | | { |
| | 207 | | //Arrange |
| 1 | 208 | | string gizmosActive = BuilderInWorldSettings.SCALE_GIZMO_NAME; |
| | 209 | |
|
| | 210 | | // Act |
| 1 | 211 | | topActionsButtonsView.SetGizmosActive(gizmosActive); |
| | 212 | |
|
| | 213 | | // Assert |
| 1 | 214 | | Assert.AreEqual(topActionsButtonsView.translateGizmosBtnImg.color , topActionsButtonsView.normalBtnImgColor) |
| 1 | 215 | | Assert.AreEqual(topActionsButtonsView.rotateGizmosBtnImg.color , topActionsButtonsView.normalBtnImgColor); |
| 1 | 216 | | Assert.AreEqual(topActionsButtonsView.scaleGizmosBtnImg.color , topActionsButtonsView.selectedBtnImgColor); |
| 1 | 217 | | } |
| | 218 | |
|
| | 219 | | [Test] |
| | 220 | | public void SetEmptyGizmosCorrectly() |
| | 221 | | { |
| | 222 | | //Arrange |
| 1 | 223 | | string gizmosActive = BuilderInWorldSettings.EMPTY_GIZMO_NAME; |
| | 224 | |
|
| | 225 | | // Act |
| 1 | 226 | | topActionsButtonsView.SetGizmosActive(gizmosActive); |
| | 227 | |
|
| | 228 | | // Assert |
| 1 | 229 | | Assert.AreEqual(topActionsButtonsView.translateGizmosBtnImg.color , topActionsButtonsView.normalBtnImgColor) |
| 1 | 230 | | Assert.AreEqual(topActionsButtonsView.rotateGizmosBtnImg.color , topActionsButtonsView.normalBtnImgColor); |
| 1 | 231 | | Assert.AreEqual(topActionsButtonsView.scaleGizmosBtnImg.color , topActionsButtonsView.normalBtnImgColor); |
| 1 | 232 | | } |
| | 233 | |
|
| | 234 | | [Test] |
| | 235 | | [TestCase(true)] |
| | 236 | | [TestCase(false)] |
| | 237 | | public void SetActionsInteractable(bool isActive) |
| | 238 | | { |
| | 239 | | //Act |
| 2 | 240 | | topActionsButtonsView.SetActionsInteractable(isActive); |
| | 241 | |
|
| 2 | 242 | | Assert.AreEqual(isActive, topActionsButtonsView.duplicateBtn.IsInteractable()); |
| 2 | 243 | | Assert.AreEqual(isActive, topActionsButtonsView.deleteBtn.IsInteractable()); |
| 2 | 244 | | } |
| | 245 | |
|
| | 246 | | [Test] |
| | 247 | | [TestCase(true)] |
| | 248 | | [TestCase(false)] |
| | 249 | | public void SetSnapMode(bool isActive) |
| | 250 | | { |
| | 251 | | //Arrange |
| 2 | 252 | | Color correctColor = isActive ? topActionsButtonsView.selectedBtnImgColor : topActionsButtonsView.normalBtnI |
| | 253 | |
|
| | 254 | | //Act |
| 2 | 255 | | topActionsButtonsView.SetSnapActive(isActive); |
| | 256 | |
|
| | 257 | | //Assert |
| 2 | 258 | | Assert.AreEqual(topActionsButtonsView.snapModeBtnImg.color , correctColor); |
| 2 | 259 | | } |
| | 260 | | } |
| | 261 | | } |