| | 1 | | using NUnit.Framework; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.EventSystems; |
| | 4 | |
|
| | 5 | | namespace Tests.BuildModeHUDViews |
| | 6 | | { |
| | 7 | | public class PublishBtnViewShould |
| | 8 | | { |
| | 9 | | private PublishBtnView publishBtnView; |
| | 10 | |
|
| | 11 | | [SetUp] |
| 10 | 12 | | public void SetUp() { publishBtnView = PublishBtnView.Create(); } |
| | 13 | |
|
| | 14 | | [TearDown] |
| 10 | 15 | | public void TearDown() { Object.Destroy(publishBtnView.gameObject); } |
| | 16 | |
|
| | 17 | | [Test] |
| | 18 | | public void OnPointerClickCorrectly() |
| | 19 | | { |
| | 20 | | // Arrange |
| 1 | 21 | | bool isClicked = false; |
| 2 | 22 | | publishBtnView.OnPublishButtonClick += () => isClicked = true; |
| | 23 | |
|
| | 24 | | // Act |
| 1 | 25 | | publishBtnView.OnPointerClick(); |
| | 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 | | publishBtnView.tooltipText = "Test text"; |
| 1 | 37 | | PointerEventData returnedEventData = null; |
| 1 | 38 | | string returnedTooltipText = ""; |
| 1 | 39 | | publishBtnView.OnShowTooltip += (data, text) => |
| | 40 | | { |
| 1 | 41 | | returnedEventData = (PointerEventData)data; |
| 1 | 42 | | returnedTooltipText = text; |
| 1 | 43 | | }; |
| | 44 | |
|
| | 45 | | // Act |
| 1 | 46 | | publishBtnView.OnPointerEnter(sentEventData); |
| | 47 | |
|
| | 48 | | // Assert |
| 1 | 49 | | Assert.AreEqual(sentEventData, returnedEventData, "The event data does not match!"); |
| 1 | 50 | | Assert.AreEqual(publishBtnView.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 | | publishBtnView.OnHideTooltip += () => isHidden = true; |
| | 59 | |
|
| | 60 | | // Act |
| 1 | 61 | | publishBtnView.OnPointerExit(); |
| | 62 | |
|
| | 63 | | // Assert |
| 1 | 64 | | Assert.IsTrue(isHidden, "isHidden is false!"); |
| 1 | 65 | | } |
| | 66 | |
|
| | 67 | | [Test] |
| | 68 | | [TestCase(true)] |
| | 69 | | [TestCase(false)] |
| | 70 | | public void SetInteractableCorrectly(bool isInteractable) |
| | 71 | | { |
| | 72 | | // Arrange |
| 2 | 73 | | publishBtnView.mainButton.interactable = !isInteractable; |
| | 74 | |
|
| | 75 | | // Act |
| 2 | 76 | | publishBtnView.SetInteractable(isInteractable); |
| | 77 | |
|
| | 78 | | // Assert |
| 2 | 79 | | Assert.AreEqual(isInteractable, publishBtnView.mainButton.interactable, "The interactable property does not |
| 2 | 80 | | } |
| | 81 | | } |
| | 82 | | } |