| | 1 | | using NUnit.Framework; |
| | 2 | | using System; |
| | 3 | | using System.Collections; |
| | 4 | | using UnityEngine.TestTools; |
| | 5 | |
|
| | 6 | | public class ProfileHUDTests : IntegrationTestSuite_Legacy |
| | 7 | | { |
| 12 | 8 | | protected override bool justSceneSetUp => true; |
| | 9 | | ProfileHUDController controller; |
| | 10 | |
|
| | 11 | | [UnitySetUp] |
| | 12 | | protected override IEnumerator SetUp() |
| | 13 | | { |
| 12 | 14 | | yield return base.SetUp(); |
| 12 | 15 | | controller = new ProfileHUDController(); |
| 12 | 16 | | } |
| | 17 | |
|
| | 18 | | [UnityTearDown] |
| | 19 | | protected override IEnumerator TearDown() |
| | 20 | | { |
| 12 | 21 | | controller.Dispose(); |
| 12 | 22 | | yield return base.TearDown(); |
| 12 | 23 | | } |
| | 24 | |
|
| | 25 | | [Test] |
| | 26 | | public void Creation() |
| | 27 | | { |
| 1 | 28 | | Assert.NotNull(controller.view); |
| 1 | 29 | | Assert.NotNull(controller.view.manaCounterView); |
| 1 | 30 | | } |
| | 31 | |
|
| | 32 | | [Test] |
| | 33 | | public void VisibilityDefaulted() |
| | 34 | | { |
| 1 | 35 | | Assert.IsTrue(controller.view.gameObject.activeInHierarchy); |
| 1 | 36 | | Assert.IsFalse(controller.view.menuShowHideAnimator.isVisible); |
| 1 | 37 | | Assert.IsFalse(controller.view.manaCounterView.gameObject.activeInHierarchy); |
| 1 | 38 | | } |
| | 39 | |
|
| | 40 | | [Test] |
| | 41 | | public void VisibilityOverridenTrue() |
| | 42 | | { |
| 1 | 43 | | controller.SetVisibility(true); |
| 1 | 44 | | Assert.IsTrue(controller.view.gameObject.activeInHierarchy); |
| 1 | 45 | | Assert.IsFalse(controller.view.menuShowHideAnimator.isVisible); |
| 1 | 46 | | } |
| | 47 | |
|
| | 48 | | [Test] |
| | 49 | | public void VisibilityOverridenFalse() |
| | 50 | | { |
| 1 | 51 | | controller.SetVisibility(false); |
| 1 | 52 | | Assert.IsFalse(controller.view.menuShowHideAnimator.isVisible); |
| 1 | 53 | | } |
| | 54 | |
|
| | 55 | | [Test] |
| | 56 | | public void ContentVisibilityOnToggle() |
| | 57 | | { |
| 1 | 58 | | Assert.AreEqual(false, controller.view.menuShowHideAnimator.isVisible); |
| 1 | 59 | | controller.view.ToggleMenu(); |
| 1 | 60 | | Assert.AreEqual(true, controller.view.menuShowHideAnimator.isVisible); |
| 1 | 61 | | controller.view.ToggleMenu(); |
| 1 | 62 | | Assert.AreEqual(false, controller.view.menuShowHideAnimator.isVisible); |
| 1 | 63 | | } |
| | 64 | |
|
| | 65 | | [Test] |
| | 66 | | public void UpdateProfileCorrectly() |
| | 67 | | { |
| | 68 | | const string address = "0x12345678901234567890"; |
| | 69 | | const string addressEnd = "7890"; |
| | 70 | | const string addressFormatted = "0x1234...567890"; |
| | 71 | | const string testUserName = "PraBian"; |
| | 72 | |
|
| 1 | 73 | | UserProfileModel profileModel = new UserProfileModel() |
| | 74 | | { |
| | 75 | | name = testUserName, |
| | 76 | | userId = address, |
| | 77 | | hasClaimedName = true |
| | 78 | | }; |
| 1 | 79 | | UserProfile profile = UserProfile.GetOwnUserProfile(); |
| 1 | 80 | | profile.UpdateData(profileModel, false); |
| | 81 | |
|
| 8 | 82 | | for (int i = 0; i < controller.view.hideOnNameClaimed.Length; i++) |
| | 83 | | { |
| 3 | 84 | | Assert.AreEqual(false, controller.view.hideOnNameClaimed[i].gameObject.activeSelf); |
| | 85 | | } |
| 1 | 86 | | Assert.AreEqual(profileModel.name, controller.view.textName.text); |
| | 87 | |
|
| 1 | 88 | | profileModel.name += "#1234"; |
| 1 | 89 | | profileModel.hasClaimedName = false; |
| 1 | 90 | | profile.UpdateData(profileModel, true); |
| | 91 | |
|
| 8 | 92 | | for (int i = 0; i < controller.view.hideOnNameClaimed.Length; i++) |
| | 93 | | { |
| 3 | 94 | | Assert.AreEqual(true, controller.view.hideOnNameClaimed[i].gameObject.activeSelf); |
| | 95 | | } |
| 1 | 96 | | Assert.AreEqual(testUserName, controller.view.textName.text); |
| 1 | 97 | | Assert.AreEqual($"#{addressEnd}", controller.view.textPostfix.text); |
| 1 | 98 | | Assert.AreEqual(addressFormatted, controller.view.textAddress.text); |
| | 99 | |
|
| 1 | 100 | | } |
| | 101 | |
|
| | 102 | | [Test] |
| | 103 | | public void SetManaBalanceCorrectly() |
| | 104 | | { |
| 1 | 105 | | string balance = "5"; |
| | 106 | |
|
| 1 | 107 | | controller.SetManaBalance(balance); |
| 1 | 108 | | Assert.AreEqual(Convert.ToDouble(balance), Convert.ToDouble(controller.view.manaCounterView.balanceText.text)); |
| 1 | 109 | | } |
| | 110 | |
|
| | 111 | | [Test] |
| | 112 | | public void AddBackpackWindowCorrectly() |
| | 113 | | { |
| 1 | 114 | | Assert.IsNull(controller.avatarEditorHud); |
| 1 | 115 | | Assert.IsFalse(controller.view.buttonBackpack.gameObject.activeSelf); |
| | 116 | |
|
| 1 | 117 | | AvatarEditorHUDController testAvatarEditor = new AvatarEditorHUDController(); |
| 1 | 118 | | controller.AddBackpackWindow(testAvatarEditor); |
| | 119 | |
|
| 1 | 120 | | Assert.IsNotNull(controller.avatarEditorHud); |
| 1 | 121 | | Assert.IsTrue(controller.view.buttonBackpack.gameObject.activeSelf); |
| 1 | 122 | | } |
| | 123 | |
|
| | 124 | | [Test] |
| | 125 | | public void ShowAndHideBackpackButtonCorrectly() |
| | 126 | | { |
| 1 | 127 | | AvatarEditorHUDController testAvatarEditor = new AvatarEditorHUDController(); |
| 1 | 128 | | controller.AddBackpackWindow(testAvatarEditor); |
| | 129 | |
|
| 1 | 130 | | controller.SetBackpackButtonVisibility(true); |
| 1 | 131 | | Assert.IsTrue(controller.view.buttonBackpack.gameObject.activeSelf); |
| | 132 | |
|
| 1 | 133 | | controller.SetBackpackButtonVisibility(false); |
| 1 | 134 | | Assert.IsFalse(controller.view.buttonBackpack.gameObject.activeSelf); |
| 1 | 135 | | } |
| | 136 | |
|
| | 137 | | [Test] |
| | 138 | | public void ActivateAndDeactivateProfileNameEditionCorrectly() |
| | 139 | | { |
| 1 | 140 | | controller.view.textName.text = "test name"; |
| | 141 | |
|
| 1 | 142 | | controller.view.ActivateProfileNameEditionMode(true); |
| 1 | 143 | | Assert.IsFalse(controller.view.editNameTooltipGO.activeSelf); |
| 1 | 144 | | Assert.IsFalse(controller.view.textName.gameObject.activeSelf); |
| 1 | 145 | | Assert.IsTrue(controller.view.inputName.gameObject.activeSelf); |
| 1 | 146 | | Assert.IsTrue(controller.view.inputName.text == controller.view.textName.text); |
| | 147 | |
|
| 1 | 148 | | controller.view.ActivateProfileNameEditionMode(false); |
| 1 | 149 | | Assert.IsTrue(controller.view.editNameTooltipGO.activeSelf); |
| 1 | 150 | | Assert.IsTrue(controller.view.textName.gameObject.activeSelf); |
| 1 | 151 | | Assert.IsFalse(controller.view.inputName.gameObject.activeSelf); |
| 1 | 152 | | } |
| | 153 | |
|
| | 154 | | [Test] |
| | 155 | | public void UpdateCharactersLimitLabelCorrectly() |
| | 156 | | { |
| 1 | 157 | | controller.view.inputName.characterLimit = 100; |
| 1 | 158 | | controller.view.inputName.text = ""; |
| 1 | 159 | | Assert.IsTrue(controller.view.textCharLimit.text == $"{controller.view.inputName.text.Length}/{controller.view.i |
| | 160 | |
|
| 1 | 161 | | controller.view.inputName.characterLimit = 50; |
| 1 | 162 | | controller.view.inputName.text = "test name"; |
| 1 | 163 | | Assert.IsTrue(controller.view.textCharLimit.text == $"{controller.view.inputName.text.Length}/{controller.view.i |
| 1 | 164 | | } |
| | 165 | |
|
| | 166 | | [Test] |
| | 167 | | public void SetProfileNameCorrectly() |
| | 168 | | { |
| 1 | 169 | | string newName = "new test name"; |
| | 170 | |
|
| 1 | 171 | | controller.view.textName.text = "test name"; |
| 1 | 172 | | controller.view.SetProfileName(newName); |
| 1 | 173 | | Assert.IsTrue(controller.view.textName.text == newName); |
| 1 | 174 | | } |
| | 175 | | } |