| | 1 | | using NUnit.Framework; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Linq; |
| | 4 | |
|
| | 5 | | public class PlayerInfoCardHUDViewShould : IntegrationTestSuite_Legacy |
| | 6 | | { |
| | 7 | | private PlayerInfoCardHUDView view; |
| | 8 | | private UserProfile userProfile; |
| 9 | 9 | | protected override bool justSceneSetUp => true; |
| | 10 | |
|
| | 11 | | protected override IEnumerator SetUp() |
| | 12 | | { |
| 9 | 13 | | yield return base.SetUp(); |
| | 14 | |
|
| 9 | 15 | | view = PlayerInfoCardHUDView.CreateView(); |
| 9 | 16 | | view.Initialize(null, null, null, null, null, null, null, null); |
| | 17 | |
|
| 9 | 18 | | CreateMockWearableByRarity(WearableLiterals.ItemRarity.EPIC); |
| 9 | 19 | | CreateMockWearableByRarity(WearableLiterals.ItemRarity.LEGENDARY); |
| 9 | 20 | | CreateMockWearableByRarity(WearableLiterals.ItemRarity.MYTHIC); |
| 9 | 21 | | CreateMockWearableByRarity(WearableLiterals.ItemRarity.RARE); |
| 9 | 22 | | CreateMockWearableByRarity(WearableLiterals.ItemRarity.UNIQUE); |
| | 23 | |
|
| 9 | 24 | | UserProfileController.i.AddUserProfileToCatalog(new UserProfileModel() |
| | 25 | | { |
| | 26 | | userId = "userId", |
| | 27 | | name = "username", |
| | 28 | | description = "description", |
| | 29 | | email = "email", |
| | 30 | | inventory = new string[] |
| | 31 | | { |
| | 32 | | WearableLiterals.ItemRarity.EPIC, |
| | 33 | | WearableLiterals.ItemRarity.LEGENDARY, |
| | 34 | | WearableLiterals.ItemRarity.MYTHIC, |
| | 35 | | WearableLiterals.ItemRarity.RARE, |
| | 36 | | WearableLiterals.ItemRarity.UNIQUE, |
| | 37 | | } |
| | 38 | | }); |
| | 39 | |
|
| 9 | 40 | | userProfile = UserProfileController.userProfilesCatalog.Get("userId"); |
| 9 | 41 | | } |
| | 42 | |
|
| | 43 | | protected override IEnumerator TearDown() |
| | 44 | | { |
| 9 | 45 | | UnityEngine.Object.Destroy(view.gameObject); |
| 9 | 46 | | yield return base.TearDown(); |
| 9 | 47 | | } |
| | 48 | |
|
| | 49 | | [Test] |
| 2 | 50 | | public void BeCreatedProperly() { Assert.IsNotNull(view); } |
| | 51 | |
|
| | 52 | | [Test] |
| | 53 | | public void InitializeProperly() |
| | 54 | | { |
| 1 | 55 | | bool hideCardButtonWasPressed = false; |
| 1 | 56 | | bool reportButtonWasPressed = false; |
| 1 | 57 | | bool blockButtonWasPressed = false; |
| 1 | 58 | | bool unblockButtonWasPressed = false; |
| 1 | 59 | | bool addFriendWasPressed = false; |
| 1 | 60 | | bool cancelWasPressed = false; |
| 1 | 61 | | bool acceptRequestWasPressed = false; |
| 1 | 62 | | bool rejectRequestWasPressed = false; |
| | 63 | |
|
| 9 | 64 | | view.Initialize(() => hideCardButtonWasPressed = true, () => reportButtonWasPressed = true, () => blockButtonWas |
| 1 | 65 | | view.hideCardButton.onClick.Invoke(); |
| 1 | 66 | | view.reportPlayerButton.onClick.Invoke(); |
| 1 | 67 | | view.blockPlayerButton.onClick.Invoke(); |
| 1 | 68 | | view.unblockPlayerButton.onClick.Invoke(); |
| 1 | 69 | | view.addFriendButton.onClick.Invoke(); |
| 1 | 70 | | view.requestSentButton.onClick.Invoke(); |
| 1 | 71 | | view.acceptRequestButton.onClick.Invoke(); |
| 1 | 72 | | view.rejectRequestButton.onClick.Invoke(); |
| | 73 | |
|
| 1 | 74 | | Assert.IsTrue(hideCardButtonWasPressed); |
| 1 | 75 | | Assert.IsTrue(reportButtonWasPressed); |
| 1 | 76 | | Assert.IsTrue(blockButtonWasPressed); |
| 1 | 77 | | Assert.IsTrue(unblockButtonWasPressed); |
| 1 | 78 | | Assert.IsTrue(addFriendWasPressed); |
| 1 | 79 | | Assert.IsTrue(cancelWasPressed); |
| 1 | 80 | | Assert.IsTrue(acceptRequestWasPressed); |
| 1 | 81 | | Assert.IsTrue(rejectRequestWasPressed); |
| 1 | 82 | | Assert.IsTrue(GetTabMapping(PlayerInfoCardHUDView.Tabs.Passport).container.activeSelf); |
| 1 | 83 | | Assert.IsFalse(GetTabMapping(PlayerInfoCardHUDView.Tabs.Trade).container.activeSelf); |
| 1 | 84 | | Assert.IsFalse(GetTabMapping(PlayerInfoCardHUDView.Tabs.Block).container.activeSelf); |
| 1 | 85 | | } |
| | 86 | |
|
| | 87 | | [Test] |
| | 88 | | [TestCase(true)] |
| | 89 | | [TestCase(false)] |
| | 90 | | public void UpdateCanvasActiveProperly(bool cardActive) |
| | 91 | | { |
| 2 | 92 | | view.SetCardActive(cardActive); |
| 2 | 93 | | Assert.AreEqual(cardActive, view.cardCanvas.enabled); |
| 2 | 94 | | } |
| | 95 | |
|
| | 96 | | [Test] |
| | 97 | | [TestCase(PlayerInfoCardHUDView.Tabs.Passport)] |
| | 98 | | [TestCase(PlayerInfoCardHUDView.Tabs.Block)] |
| | 99 | | [TestCase(PlayerInfoCardHUDView.Tabs.Trade)] |
| | 100 | | public void UpdateTabsProperly(PlayerInfoCardHUDView.Tabs tab) |
| | 101 | | { |
| 3 | 102 | | GetTabMapping(tab).toggle.isOn = true; |
| 24 | 103 | | foreach (var tabsMapping in view.tabsMapping) |
| | 104 | | { |
| 9 | 105 | | Assert.AreEqual(tabsMapping.container.activeSelf, tabsMapping.tab == tab, $"{tab} Tab was selected and Tab: |
| | 106 | | } |
| 3 | 107 | | } |
| | 108 | |
|
| | 109 | | [Test] |
| | 110 | | public void UpdateProfileDataProperly() |
| | 111 | | { |
| 1 | 112 | | view.SetUserProfile(userProfile); |
| | 113 | |
|
| 1 | 114 | | Assert.AreEqual(userProfile, view.currentUserProfile); |
| 1 | 115 | | Assert.AreEqual(userProfile.userName, view.name.text); |
| 1 | 116 | | Assert.AreEqual(userProfile.description, view.description.text); |
| 1 | 117 | | } |
| | 118 | |
|
| | 119 | | [Test] |
| | 120 | | public void CreateCollectibles() |
| | 121 | | { |
| 1 | 122 | | view.SetUserProfile(userProfile); |
| | 123 | |
|
| 1 | 124 | | Assert.AreEqual(userProfile.inventory.Count, view.playerInfoCollectibles.Count); |
| 2 | 125 | | foreach (var keyValuePair in userProfile.inventory) |
| | 126 | | { |
| 0 | 127 | | var wearable = CatalogController.wearableCatalog.Get(keyValuePair.Key); |
| 0 | 128 | | Assert.IsTrue(view.playerInfoCollectibles.Any(x => x.collectible == wearable)); |
| | 129 | | } |
| 1 | 130 | | } |
| | 131 | |
|
| 18 | 132 | | private PlayerInfoCardHUDView.TabsMapping GetTabMapping(PlayerInfoCardHUDView.Tabs tab) { return view.tabsMapping.Fi |
| | 133 | |
|
| | 134 | | private WearableItem CreateMockWearableByRarity(string rarity) |
| | 135 | | { |
| 45 | 136 | | var wearable = new WearableItem() |
| | 137 | | { |
| | 138 | | id = rarity, |
| | 139 | | rarity = rarity, |
| | 140 | | data = new WearableItem.Data() |
| | 141 | | { |
| | 142 | | tags = new string[] { }, |
| | 143 | | category = WearableLiterals.Categories.UPPER_BODY |
| | 144 | | } |
| | 145 | | }; |
| | 146 | |
|
| 45 | 147 | | CatalogController.wearableCatalog.Remove(rarity); |
| 45 | 148 | | CatalogController.wearableCatalog.Add(rarity, wearable); |
| | 149 | |
|
| 45 | 150 | | return wearable; |
| | 151 | | } |
| | 152 | | } |