| | 1 | | using NUnit.Framework; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.EventSystems; |
| | 4 | |
|
| | 5 | | namespace Tests.BuildModeHUDViews |
| | 6 | | { |
| | 7 | | public class InspectorBtnViewShould |
| | 8 | | { |
| | 9 | | private InspectorBtnView inspectorBtnView; |
| | 10 | |
|
| | 11 | | [SetUp] |
| 6 | 12 | | public void SetUp() { inspectorBtnView = InspectorBtnView.Create(); } |
| | 13 | |
|
| | 14 | | [TearDown] |
| 6 | 15 | | public void TearDown() { Object.Destroy(inspectorBtnView.gameObject); } |
| | 16 | |
|
| | 17 | | [Test] |
| | 18 | | public void OnPointerClickCorrectly() |
| | 19 | | { |
| | 20 | | // Arrange |
| 1 | 21 | | bool isClicked = false; |
| 2 | 22 | | inspectorBtnView.OnInspectorButtonClick += () => isClicked = true; |
| | 23 | |
|
| | 24 | | // Act |
| 1 | 25 | | inspectorBtnView.OnPointerClick(new DCLAction_Trigger()); |
| | 26 | |
|
| | 27 | | // Assert |
| 1 | 28 | | Assert.IsTrue(isClicked, "isClicked is false!"); |
| 1 | 29 | | } |
| | 30 | |
|
| | 31 | | [Test] |
| | 32 | | public void OnPointerEnterCorrectly() |
| | 33 | | { |
| | 34 | | // Arrange |
| 1 | 35 | | PointerEventData sentEventData = new PointerEventData(null); |
| 1 | 36 | | inspectorBtnView.tooltipText = "Test text"; |
| 1 | 37 | | PointerEventData returnedEventData = null; |
| 1 | 38 | | string returnedTooltipText = ""; |
| 1 | 39 | | inspectorBtnView.OnShowTooltip += (data, text) => |
| | 40 | | { |
| 1 | 41 | | returnedEventData = (PointerEventData)data; |
| 1 | 42 | | returnedTooltipText = text; |
| 1 | 43 | | }; |
| | 44 | |
|
| | 45 | | // Act |
| 1 | 46 | | inspectorBtnView.OnPointerEnter(sentEventData); |
| | 47 | |
|
| | 48 | | // Assert |
| 1 | 49 | | Assert.AreEqual(sentEventData, returnedEventData, "The tooltip text does not match!"); |
| 1 | 50 | | Assert.AreEqual(inspectorBtnView.tooltipText, returnedTooltipText, "The tooltip text does not match!"); |
| 1 | 51 | | } |
| | 52 | |
|
| | 53 | | [Test] |
| | 54 | | public void OnPointerExitCorrectly() |
| | 55 | | { |
| | 56 | | // Arrange |
| 1 | 57 | | bool isHidden = false; |
| 2 | 58 | | inspectorBtnView.OnHideTooltip += () => isHidden = true; |
| | 59 | |
|
| | 60 | | // Act |
| 1 | 61 | | inspectorBtnView.OnPointerExit(); |
| | 62 | |
|
| | 63 | | // Assert |
| 1 | 64 | | Assert.IsTrue(isHidden, "isHidden is false!"); |
| 1 | 65 | | } |
| | 66 | | } |
| | 67 | | } |