| | 1 | | using NSubstitute; |
| | 2 | | using NUnit.Framework; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.EventSystems; |
| | 5 | |
|
| | 6 | | namespace Tests.BuildModeHUDControllers |
| | 7 | | { |
| | 8 | | public class TooltipControllerShould |
| | 9 | | { |
| | 10 | | private TooltipController tooltipController; |
| | 11 | |
|
| | 12 | | [SetUp] |
| | 13 | | public void SetUp() |
| | 14 | | { |
| 3 | 15 | | tooltipController = new TooltipController(); |
| 3 | 16 | | tooltipController.Initialize(Substitute.For<ITooltipView>()); |
| 3 | 17 | | } |
| | 18 | |
|
| | 19 | | [TearDown] |
| 6 | 20 | | public void TearDown() { tooltipController.Dispose(); } |
| | 21 | |
|
| | 22 | | [Test] |
| | 23 | | public void SetTooltipTextCorrectly() |
| | 24 | | { |
| | 25 | | // Arrange |
| 1 | 26 | | string testText = "Test text"; |
| | 27 | |
|
| | 28 | | // Act |
| 1 | 29 | | tooltipController.SetTooltipText(testText); |
| | 30 | |
|
| | 31 | | // Assert |
| 1 | 32 | | tooltipController.view.Received(1).SetText(testText); |
| 1 | 33 | | } |
| | 34 | |
|
| | 35 | | [Test] |
| | 36 | | public void ShowTooltipCorrectly() |
| | 37 | | { |
| | 38 | | // Arrange |
| 1 | 39 | | PointerEventData testEventData = new PointerEventData(null); |
| 1 | 40 | | testEventData.pointerEnter = new GameObject("_PointerEnterGO"); |
| 1 | 41 | | RectTransform testRT = testEventData.pointerEnter.AddComponent<RectTransform>(); |
| 1 | 42 | | tooltipController.changeAlphaCoroutine = null; |
| | 43 | |
|
| | 44 | | // Act |
| 1 | 45 | | tooltipController.ShowTooltip(testEventData); |
| | 46 | |
|
| | 47 | | // Assert |
| 1 | 48 | | tooltipController.view.Received(1).SetTooltipPosition(testRT.position); |
| 1 | 49 | | Assert.IsNotNull(tooltipController.changeAlphaCoroutine, "The changeAlphaCoroutine is null!"); |
| 1 | 50 | | } |
| | 51 | |
|
| | 52 | | [Test] |
| | 53 | | public void ShowTooltipWithOffsetCorrectly() |
| | 54 | | { |
| | 55 | | // Arrange |
| 1 | 56 | | PointerEventData testEventData = new PointerEventData(null); |
| 1 | 57 | | testEventData.pointerEnter = new GameObject("_PointerEnterGO"); |
| 1 | 58 | | RectTransform testRT = testEventData.pointerEnter.AddComponent<RectTransform>(); |
| 1 | 59 | | tooltipController.changeAlphaCoroutine = null; |
| 1 | 60 | | Vector3 offset = new Vector3(0, 50, 0); |
| | 61 | |
|
| | 62 | | // Act |
| 1 | 63 | | tooltipController.ShowTooltip(testEventData, offset); |
| | 64 | |
|
| | 65 | | // Assert |
| 1 | 66 | | tooltipController.view.Received(1).SetTooltipPosition(offset + testRT.position); |
| 1 | 67 | | Assert.IsNotNull(tooltipController.changeAlphaCoroutine, "The changeAlphaCoroutine is null!"); |
| 1 | 68 | | } |
| | 69 | | } |
| | 70 | | } |