| | 1 | | using DCL.Configuration; |
| | 2 | | using NSubstitute; |
| | 3 | | using NUnit.Framework; |
| | 4 | | using UnityEngine.EventSystems; |
| | 5 | |
|
| | 6 | | namespace Tests.BuildModeHUDControllers |
| | 7 | | { |
| | 8 | | public class TopActionsButtonsControllerShould |
| | 9 | | { |
| | 10 | | private TopActionsButtonsController topActionsButtonsController; |
| | 11 | |
|
| | 12 | | [SetUp] |
| | 13 | | public void SetUp() |
| | 14 | | { |
| 18 | 15 | | topActionsButtonsController = new TopActionsButtonsController(); |
| 18 | 16 | | topActionsButtonsController.Initialize( |
| | 17 | | Substitute.For<ITopActionsButtonsView>(), |
| | 18 | | Substitute.For<ITooltipController>()); |
| 18 | 19 | | } |
| | 20 | |
|
| | 21 | | [TearDown] |
| 36 | 22 | | public void TearDown() { topActionsButtonsController.Dispose(); } |
| | 23 | |
|
| | 24 | | [Test] |
| | 25 | | public void ClickOnChangeModeCorrectly() |
| | 26 | | { |
| | 27 | | // Arrange |
| 1 | 28 | | bool clicked = false; |
| 3 | 29 | | topActionsButtonsController.OnChangeModeClick += () => { clicked = true; }; |
| | 30 | |
|
| | 31 | | // Act |
| 1 | 32 | | topActionsButtonsController.ChangeModeClicked(); |
| | 33 | |
|
| | 34 | | // Assert |
| 1 | 35 | | Assert.IsTrue(clicked, "The clicked is false!"); |
| 1 | 36 | | } |
| | 37 | |
|
| | 38 | | [Test] |
| | 39 | | public void ClickOnExtraCorrectly() |
| | 40 | | { |
| | 41 | | // Arrange |
| 1 | 42 | | bool clicked = false; |
| 3 | 43 | | topActionsButtonsController.OnExtraClick += () => { clicked = true; }; |
| | 44 | |
|
| | 45 | | // Act |
| 1 | 46 | | topActionsButtonsController.ExtraClicked(); |
| | 47 | |
|
| | 48 | | // Assert |
| 1 | 49 | | Assert.IsTrue(clicked, "The clicked is false!"); |
| 1 | 50 | | } |
| | 51 | |
|
| | 52 | | [Test] |
| | 53 | | public void ClickOnTranslateCorrectly() |
| | 54 | | { |
| | 55 | | // Arrange |
| 1 | 56 | | bool clicked = false; |
| 3 | 57 | | topActionsButtonsController.OnTranslateClick += () => { clicked = true; }; |
| | 58 | |
|
| | 59 | | // Act |
| 1 | 60 | | topActionsButtonsController.TranslateClicked(); |
| | 61 | |
|
| | 62 | | // Assert |
| 1 | 63 | | Assert.IsTrue(clicked, "The clicked is false!"); |
| 1 | 64 | | } |
| | 65 | |
|
| | 66 | | [Test] |
| | 67 | | public void ClickOnRotateCorrectly() |
| | 68 | | { |
| | 69 | | // Arrange |
| 1 | 70 | | bool clicked = false; |
| 3 | 71 | | topActionsButtonsController.OnRotateClick += () => { clicked = true; }; |
| | 72 | |
|
| | 73 | | // Act |
| 1 | 74 | | topActionsButtonsController.RotateClicked(); |
| | 75 | |
|
| | 76 | | // Assert |
| 1 | 77 | | Assert.IsTrue(clicked, "The clicked is false!"); |
| 1 | 78 | | } |
| | 79 | |
|
| | 80 | | [Test] |
| | 81 | | public void ClickOnScaleCorrectly() |
| | 82 | | { |
| | 83 | | // Arrange |
| 1 | 84 | | bool clicked = false; |
| 3 | 85 | | topActionsButtonsController.OnScaleClick += () => { clicked = true; }; |
| | 86 | |
|
| | 87 | | // Act |
| 1 | 88 | | topActionsButtonsController.ScaleClicked(); |
| | 89 | |
|
| | 90 | | // Assert |
| 1 | 91 | | Assert.IsTrue(clicked, "The clicked is false!"); |
| 1 | 92 | | } |
| | 93 | |
|
| | 94 | | [Test] |
| | 95 | | public void ClickOnUndoCorrectly() |
| | 96 | | { |
| | 97 | | // Arrange |
| 1 | 98 | | bool clicked = false; |
| 3 | 99 | | topActionsButtonsController.OnUndoClick += () => { clicked = true; }; |
| | 100 | |
|
| | 101 | | // Act |
| 1 | 102 | | topActionsButtonsController.UndoClicked(); |
| | 103 | |
|
| | 104 | | // Assert |
| 1 | 105 | | Assert.IsTrue(clicked, "The clicked is false!"); |
| 1 | 106 | | } |
| | 107 | |
|
| | 108 | | [Test] |
| | 109 | | public void ClickOnRedoCorrectly() |
| | 110 | | { |
| | 111 | | // Arrange |
| 1 | 112 | | bool clicked = false; |
| 3 | 113 | | topActionsButtonsController.OnRedoClick += () => { clicked = true; }; |
| | 114 | |
|
| | 115 | | // Act |
| 1 | 116 | | topActionsButtonsController.RedoClicked(); |
| | 117 | |
|
| | 118 | | // Assert |
| 1 | 119 | | Assert.IsTrue(clicked, "The clicked is false!"); |
| 1 | 120 | | } |
| | 121 | |
|
| | 122 | | [Test] |
| | 123 | | public void ClickOnDuplicateCorrectly() |
| | 124 | | { |
| | 125 | | // Arrange |
| 1 | 126 | | bool clicked = false; |
| 3 | 127 | | topActionsButtonsController.OnDuplicateClick += () => { clicked = true; }; |
| | 128 | |
|
| | 129 | | // Act |
| 1 | 130 | | topActionsButtonsController.DuplicateClicked(); |
| | 131 | |
|
| | 132 | | // Assert |
| 1 | 133 | | Assert.IsTrue(clicked, "The clicked is false!"); |
| 1 | 134 | | } |
| | 135 | |
|
| | 136 | | [Test] |
| | 137 | | public void ClickOnDeleteCorrectly() |
| | 138 | | { |
| | 139 | | // Arrange |
| 1 | 140 | | bool clicked = false; |
| 3 | 141 | | topActionsButtonsController.OnDeleteClick += () => { clicked = true; }; |
| | 142 | |
|
| | 143 | | // Act |
| 1 | 144 | | topActionsButtonsController.DeleteClicked(); |
| | 145 | |
|
| | 146 | | // Assert |
| 1 | 147 | | Assert.IsTrue(clicked, "The clicked is false!"); |
| 1 | 148 | | } |
| | 149 | |
|
| | 150 | | [Test] |
| | 151 | | public void ShowLogoutConfirmationCorrectly() |
| | 152 | | { |
| | 153 | | // Arrange |
| 1 | 154 | | bool clicked = false; |
| 3 | 155 | | topActionsButtonsController.OnLogOutClick += () => { clicked = true; }; |
| | 156 | |
|
| | 157 | | // Act |
| 1 | 158 | | topActionsButtonsController.LogoutClicked(); |
| | 159 | |
|
| | 160 | | // Assert |
| 1 | 161 | | Assert.IsTrue(clicked, "The clicked is false!"); |
| 1 | 162 | | } |
| | 163 | |
|
| | 164 | | [Test] |
| | 165 | | public void ConfirmLogoutCorrectly() |
| | 166 | | { |
| | 167 | | // Arrange |
| 1 | 168 | | bool clicked = false; |
| 3 | 169 | | topActionsButtonsController.OnLogOutClick += () => { clicked = true; }; |
| | 170 | |
|
| | 171 | | // Act |
| 1 | 172 | | topActionsButtonsController.ConfirmLogout(BuildModeModalType.EXIT); |
| | 173 | |
|
| | 174 | | // Assert |
| 1 | 175 | | Assert.IsTrue(clicked, "The clicked is false!"); |
| 1 | 176 | | } |
| | 177 | |
|
| | 178 | | [Test] |
| | 179 | | public void TooltipPointerEnteredCorrectly() |
| | 180 | | { |
| | 181 | | // Arrange |
| 1 | 182 | | BaseEventData testEventData = new BaseEventData(null); |
| 1 | 183 | | string testText = "Test text"; |
| | 184 | |
|
| | 185 | | // Act |
| 1 | 186 | | topActionsButtonsController.TooltipPointerEntered(testEventData, testText); |
| | 187 | |
|
| | 188 | | // Assert |
| 1 | 189 | | topActionsButtonsController.tooltipController.Received(1).ShowTooltip(testEventData); |
| 1 | 190 | | topActionsButtonsController.tooltipController.Received(1).SetTooltipText(testText); |
| 1 | 191 | | } |
| | 192 | |
|
| | 193 | | [Test] |
| | 194 | | public void TooltipPointerExitedCorrectly() |
| | 195 | | { |
| | 196 | | // Act |
| 1 | 197 | | topActionsButtonsController.TooltipPointerExited(); |
| | 198 | |
|
| | 199 | | // Assert |
| 1 | 200 | | topActionsButtonsController.tooltipController.Received(1).HideTooltip(); |
| 1 | 201 | | } |
| | 202 | |
|
| | 203 | | [Test] |
| | 204 | | public void TestSetGizmosActivetedCorrectly() |
| | 205 | | { |
| | 206 | | //Arrange |
| 1 | 207 | | string gizmosActive = BuilderInWorldSettings.TRANSLATE_GIZMO_NAME; |
| | 208 | |
|
| | 209 | | // Act |
| 1 | 210 | | topActionsButtonsController.SetGizmosActive(gizmosActive); |
| | 211 | |
|
| | 212 | | // Assert |
| 1 | 213 | | topActionsButtonsController.topActionsButtonsView.Received(1).SetGizmosActive(gizmosActive); |
| 1 | 214 | | } |
| | 215 | |
|
| | 216 | | [Test] |
| | 217 | | [TestCase(true)] |
| | 218 | | [TestCase(false)] |
| | 219 | | public void TestSeActionsInteractable(bool isInteractable) |
| | 220 | | { |
| | 221 | | //Act |
| 2 | 222 | | topActionsButtonsController.SetActionsInteractable(isInteractable); |
| | 223 | |
|
| | 224 | | //Assert |
| 2 | 225 | | topActionsButtonsController.topActionsButtonsView.Received(1).SetActionsInteractable(isInteractable); |
| 2 | 226 | | } |
| | 227 | |
|
| | 228 | | [Test] |
| | 229 | | [TestCase(true)] |
| | 230 | | [TestCase(false)] |
| | 231 | | public void TestSnapModeChange(bool isActive) |
| | 232 | | { |
| | 233 | | //Act |
| 2 | 234 | | topActionsButtonsController.SetSnapActive(isActive); |
| | 235 | |
|
| | 236 | | //Assert |
| 2 | 237 | | topActionsButtonsController.topActionsButtonsView.Received(1).SetSnapActive(isActive); |
| 2 | 238 | | } |
| | 239 | | } |
| | 240 | | } |