| | 1 | | using DCL.Helpers; |
| | 2 | | using NUnit.Framework; |
| | 3 | | using System.Collections; |
| | 4 | | using NSubstitute; |
| | 5 | | using NSubstitute.Extensions; |
| | 6 | | using TMPro; |
| | 7 | | using UnityEngine; |
| | 8 | | using UnityEngine.Events; |
| | 9 | | using UnityEngine.UI; |
| | 10 | |
|
| | 11 | | namespace Tests |
| | 12 | | { |
| | 13 | | public class WelcomeHUDControllerShould : IntegrationTestSuite_Legacy |
| | 14 | | { |
| | 15 | | [Test] |
| | 16 | | public void CreateTheView() |
| | 17 | | { |
| | 18 | | // Arrange |
| 1 | 19 | | WelcomeHUDController controller = Substitute.ForPartsOf<WelcomeHUDController>(); |
| | 20 | |
|
| | 21 | | // Assert |
| 1 | 22 | | Assert.IsNotNull(controller.view); |
| | 23 | |
|
| 1 | 24 | | controller.Dispose(); |
| 1 | 25 | | } |
| | 26 | |
|
| | 27 | | // TODO(Santi): Check with Brian how to adapt this test to the new async flow of the WelcomeHUD |
| | 28 | | [Test] |
| | 29 | | [TestCase(0)] |
| | 30 | | [TestCase(1)] |
| | 31 | | [Explicit] |
| | 32 | | [Category("Explicit")] |
| | 33 | | public void ReactToViewOnButtonConfirm(int buttonIndexToPress) |
| | 34 | | { |
| | 35 | | // Arrange |
| 0 | 36 | | IWelcomeHUDView mockView = Substitute.For<IWelcomeHUDView>(); |
| 0 | 37 | | mockView.When(x => x.Initialize(Arg.Any<UnityAction<int>>(), Arg.Any<UnityAction>(), Arg.Any<MessageOfTheDay |
| 0 | 38 | | .Do(x => x.ArgAt<UnityAction<int>>(0).Invoke(buttonIndexToPress)); |
| 0 | 39 | | WelcomeHUDController controller = Substitute.ForPartsOf<WelcomeHUDController>(); |
| | 40 | |
|
| | 41 | | // Act |
| 0 | 42 | | controller.Initialize(null); |
| | 43 | |
|
| | 44 | | // Assert |
| 0 | 45 | | controller.Received().OnConfirmPressed(buttonIndexToPress); |
| 0 | 46 | | mockView.Received().SetVisible(false); |
| | 47 | |
|
| 0 | 48 | | controller.Dispose(); |
| 0 | 49 | | } |
| | 50 | |
|
| | 51 | | [Test] |
| | 52 | | public void CallButtonAction() |
| | 53 | | { |
| | 54 | | // Arrange |
| 1 | 55 | | WelcomeHUDController controller = Substitute.ForPartsOf<WelcomeHUDController>(); |
| 1 | 56 | | controller.Initialize(new MessageOfTheDayConfig |
| | 57 | | { |
| | 58 | | buttons = new[] |
| | 59 | | { |
| | 60 | | new MessageOfTheDayConfig.Button { action = "action0" }, |
| | 61 | | new MessageOfTheDayConfig.Button { action = "action1" } |
| | 62 | | } |
| | 63 | | }); |
| | 64 | |
|
| | 65 | | // Act |
| 1 | 66 | | controller.OnConfirmPressed(1); |
| | 67 | |
|
| | 68 | | // Assert |
| 1 | 69 | | controller.Received().SendAction("action1"); |
| | 70 | |
|
| 1 | 71 | | controller.Dispose(); |
| 1 | 72 | | } |
| | 73 | |
|
| | 74 | | [Test] |
| | 75 | | public void ProcessOutOfBoundsButtonsProperly() |
| | 76 | | { |
| | 77 | | // Arrange |
| 1 | 78 | | WelcomeHUDController controller = Substitute.ForPartsOf<WelcomeHUDController>(); |
| 1 | 79 | | controller.Initialize(new MessageOfTheDayConfig { buttons = new MessageOfTheDayConfig.Button[0] }); |
| | 80 | |
|
| | 81 | | // Act |
| 1 | 82 | | controller.OnConfirmPressed(-1); |
| 1 | 83 | | controller.OnConfirmPressed(1); |
| | 84 | |
|
| | 85 | | // Assert |
| 1 | 86 | | controller.DidNotReceiveWithAnyArgs().SendAction(default); |
| | 87 | |
|
| 1 | 88 | | controller.Dispose(); |
| 1 | 89 | | } |
| | 90 | | } |
| | 91 | |
|
| | 92 | | public class WelcomeHUDViewShould : IntegrationTestSuite_Legacy |
| | 93 | | { |
| | 94 | | private WelcomeHUDView view; |
| | 95 | |
|
| | 96 | | protected override IEnumerator SetUp() |
| | 97 | | { |
| | 98 | | yield return base.SetUp(); |
| | 99 | | view = WelcomeHUDView.CreateView(); |
| | 100 | | } |
| | 101 | |
|
| | 102 | | [Test] |
| | 103 | | public void CreateViewProperly() |
| | 104 | | { |
| | 105 | | Assert.IsNotNull(view); |
| | 106 | | Assert.IsNotNull(view.gameObject); |
| | 107 | | } |
| | 108 | |
|
| | 109 | | [Test] |
| | 110 | | public void SetUICorrectly() |
| | 111 | | { |
| | 112 | | view.Initialize(null, null, |
| | 113 | | new MessageOfTheDayConfig |
| | 114 | | { |
| | 115 | | title = "title", |
| | 116 | | body = "body", |
| | 117 | | }); |
| | 118 | |
|
| | 119 | | Assert.AreEqual("title", view.titleText.text); |
| | 120 | | Assert.AreEqual("body", view.bodyText.text); |
| | 121 | | } |
| | 122 | |
|
| | 123 | | [Test] |
| | 124 | | public void SetButtonsCorrectly() |
| | 125 | | { |
| | 126 | | view.Initialize(null, null, |
| | 127 | | new MessageOfTheDayConfig |
| | 128 | | { |
| | 129 | | buttons = new[] |
| | 130 | | { |
| | 131 | | new MessageOfTheDayConfig.Button { caption = "button0", tint = Color.green }, |
| | 132 | | new MessageOfTheDayConfig.Button { caption = "button1", tint = Color.blue }, |
| | 133 | | } |
| | 134 | | }); |
| | 135 | |
|
| | 136 | | Assert.AreEqual("button0", view.buttonsParent.GetChild(0).GetComponentInChildren<TextMeshProUGUI>().text); |
| | 137 | | Assert.AreEqual(Color.green, view.buttonsParent.GetChild(0).GetComponentInChildren<Image>().color); |
| | 138 | | Assert.AreEqual("button1", view.buttonsParent.GetChild(1).GetComponentInChildren<TextMeshProUGUI>().text); |
| | 139 | | Assert.AreEqual(Color.blue, view.buttonsParent.GetChild(1).GetComponentInChildren<Image>().color); |
| | 140 | | } |
| | 141 | |
|
| | 142 | | protected override IEnumerator TearDown() |
| | 143 | | { |
| | 144 | | if (view != null && view.gameObject != null) |
| | 145 | | Object.Destroy(view.gameObject); |
| | 146 | | yield return base.TearDown(); |
| | 147 | | } |
| | 148 | | } |
| | 149 | | } |