| | 1 | | using AvatarShape_Tests; |
| | 2 | | using DCL; |
| | 3 | | using NUnit.Framework; |
| | 4 | | using System.Collections; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.Linq; |
| | 7 | | using UnityEngine; |
| | 8 | | using UnityEngine.TestTools; |
| | 9 | |
|
| | 10 | | namespace AvatarEditorHUD_Tests |
| | 11 | | { |
| | 12 | | public class AvatarEditorHUDControllerShould : IntegrationTestSuite_Legacy |
| | 13 | | { |
| | 14 | | private const string EYEBROWS_ID = "urn:decentraland:off-chain:base-avatars:f_eyebrows_01"; |
| | 15 | | private const string FEMALE_CATGLASSES_ID = "urn:decentraland:off-chain:base-avatars:f_glasses_cat_style"; |
| | 16 | |
|
| | 17 | | private UserProfile userProfile; |
| | 18 | | private AvatarEditorHUDController_Mock controller; |
| | 19 | | private BaseDictionary<string, WearableItem> catalog; |
| | 20 | | private ColorList skinColorList; |
| | 21 | | private ColorList hairColorList; |
| | 22 | | private ColorList eyeColorList; |
| | 23 | |
|
| 14 | 24 | | protected override bool justSceneSetUp => true; |
| | 25 | |
|
| | 26 | | [UnitySetUp] |
| | 27 | | protected override IEnumerator SetUp() |
| | 28 | | { |
| 14 | 29 | | yield return base.SetUp(); |
| | 30 | |
|
| 14 | 31 | | if (controller == null) |
| | 32 | | { |
| 1 | 33 | | skinColorList = Resources.Load<ColorList>("SkinTone"); |
| 1 | 34 | | hairColorList = Resources.Load<ColorList>("HairColor"); |
| 1 | 35 | | eyeColorList = Resources.Load<ColorList>("EyeColor"); |
| | 36 | |
|
| 1 | 37 | | userProfile = ScriptableObject.CreateInstance<UserProfile>(); |
| | 38 | | } |
| | 39 | |
|
| 14 | 40 | | catalog = AvatarAssetsTestHelpers.CreateTestCatalogLocal(); |
| 14 | 41 | | controller = new AvatarEditorHUDController_Mock(); |
| 14 | 42 | | controller.Initialize(userProfile, catalog); |
| 14 | 43 | | controller.SetVisibility(true); |
| 14 | 44 | | DataStore.i.isPlayerRendererLoaded.Set(true); |
| | 45 | |
|
| 14 | 46 | | userProfile.UpdateData(new UserProfileModel() |
| | 47 | | { |
| | 48 | | name = "name", |
| | 49 | | email = "mail", |
| | 50 | | avatar = new AvatarModel() |
| | 51 | | { |
| | 52 | | bodyShape = WearableLiterals.BodyShapes.FEMALE, |
| | 53 | | wearables = new List<string>() { }, |
| | 54 | | } |
| | 55 | | }, false); |
| 14 | 56 | | } |
| | 57 | |
|
| | 58 | | [UnityTearDown] |
| | 59 | | protected override IEnumerator TearDown() |
| | 60 | | { |
| 14 | 61 | | controller.Dispose(); |
| 14 | 62 | | yield return base.TearDown(); |
| 14 | 63 | | } |
| | 64 | |
|
| | 65 | | [Test] |
| | 66 | | public void AutofillMandatoryCategoriesIfNotProvided() |
| | 67 | | { |
| 1 | 68 | | userProfile.UpdateData(new UserProfileModel() |
| | 69 | | { |
| | 70 | | name = "name", |
| | 71 | | email = "mail", |
| | 72 | | avatar = new AvatarModel() |
| | 73 | | { |
| | 74 | | bodyShape = WearableLiterals.BodyShapes.FEMALE, |
| | 75 | | wearables = new List<string>() { }, |
| | 76 | | } |
| | 77 | | }, false); |
| | 78 | |
|
| 7 | 79 | | var categoriesEquiped = controller.myModel.wearables.Select(x => x.data.category).ToArray(); |
| 16 | 80 | | foreach (string category in controller.myCategoriesThatMustHaveSelection) |
| | 81 | | { |
| 7 | 82 | | if (category != "body_shape") |
| | 83 | | { |
| 6 | 84 | | Assert.Contains(category, categoriesEquiped); |
| | 85 | | } |
| | 86 | | } |
| 1 | 87 | | } |
| | 88 | |
|
| | 89 | | [Test] |
| | 90 | | public void ReplaceNotSupportedWearablesWhenChangingBodyShape() |
| | 91 | | { |
| 1 | 92 | | userProfile.UpdateData(new UserProfileModel() |
| | 93 | | { |
| | 94 | | name = "name", |
| | 95 | | email = "mail", |
| | 96 | | avatar = new AvatarModel() |
| | 97 | | { |
| | 98 | | bodyShape = WearableLiterals.BodyShapes.FEMALE, |
| | 99 | | wearables = new List<string>() |
| | 100 | | { |
| | 101 | | FEMALE_CATGLASSES_ID |
| | 102 | | }, |
| | 103 | | } |
| | 104 | | }, false); |
| | 105 | |
|
| 1 | 106 | | controller.WearableClicked(WearableLiterals.BodyShapes.MALE); |
| | 107 | |
|
| 9 | 108 | | Assert.False(controller.myModel.wearables.Any(x => x.id == FEMALE_CATGLASSES_ID)); |
| 1 | 109 | | } |
| | 110 | |
|
| | 111 | | [Test] |
| | 112 | | public void LoadUserProfileByConstructor() |
| | 113 | | { |
| 1 | 114 | | userProfile.UpdateData(new UserProfileModel() |
| | 115 | | { |
| | 116 | | name = "name", |
| | 117 | | email = "mail", |
| | 118 | | avatar = new AvatarModel() |
| | 119 | | { |
| | 120 | | bodyShape = WearableLiterals.BodyShapes.FEMALE, |
| | 121 | | wearables = new List<string>() |
| | 122 | | { |
| | 123 | | EYEBROWS_ID, |
| | 124 | | "urn:decentraland:off-chain:base-avatars:f_eyes_00", |
| | 125 | | "urn:decentraland:off-chain:base-avatars:bear_slippers", |
| | 126 | | "urn:decentraland:off-chain:base-avatars:f_african_leggins", |
| | 127 | | "urn:decentraland:off-chain:base-avatars:f_mouth_00", |
| | 128 | | "urn:decentraland:off-chain:base-avatars:blue_bandana", |
| | 129 | | "urn:decentraland:off-chain:base-avatars:bee_t_shirt" |
| | 130 | | }, |
| | 131 | | skinColor = skinColorList.colors[0], |
| | 132 | | hairColor = hairColorList.colors[0], |
| | 133 | | eyeColor = eyeColorList.colors[0], |
| | 134 | | } |
| | 135 | | }, false); |
| | 136 | |
|
| 1 | 137 | | AssertAvatarModelAgainstAvatarEditorHUDModel(userProfile.avatar, controller.myModel); |
| 1 | 138 | | } |
| | 139 | |
|
| | 140 | | [Test] |
| | 141 | | public void ReactToUserProfileUpdate() |
| | 142 | | { |
| 1 | 143 | | userProfile.UpdateData(new UserProfileModel() |
| | 144 | | { |
| | 145 | | name = "name", |
| | 146 | | email = "mail", |
| | 147 | | avatar = new AvatarModel() |
| | 148 | | { |
| | 149 | | bodyShape = WearableLiterals.BodyShapes.FEMALE, |
| | 150 | | wearables = new List<string>() |
| | 151 | | { |
| | 152 | | EYEBROWS_ID, |
| | 153 | | "urn:decentraland:off-chain:base-avatars:f_eyes_00", |
| | 154 | | "urn:decentraland:off-chain:base-avatars:bear_slippers", |
| | 155 | | "urn:decentraland:off-chain:base-avatars:f_african_leggins", |
| | 156 | | "urn:decentraland:off-chain:base-avatars:f_mouth_00", |
| | 157 | | "urn:decentraland:off-chain:base-avatars:blue_bandana", |
| | 158 | | "urn:decentraland:off-chain:base-avatars:bee_t_shirt" |
| | 159 | | }, |
| | 160 | | skinColor = skinColorList.colors[0], |
| | 161 | | hairColor = hairColorList.colors[0], |
| | 162 | | eyeColor = eyeColorList.colors[0], |
| | 163 | | } |
| | 164 | | }, false); |
| | 165 | |
|
| 1 | 166 | | AssertAvatarModelAgainstAvatarEditorHUDModel(userProfile.avatar, controller.myModel); |
| 1 | 167 | | } |
| | 168 | |
|
| | 169 | | [Test] |
| | 170 | | public void ProcessClickedBodyShape() |
| | 171 | | { |
| 1 | 172 | | controller.WearableClicked(WearableLiterals.BodyShapes.MALE); |
| | 173 | |
|
| 1 | 174 | | Assert.AreEqual(WearableLiterals.BodyShapes.MALE, controller.myModel.bodyShape.id); |
| 1 | 175 | | } |
| | 176 | |
|
| | 177 | | [Test] |
| | 178 | | public void ProcessClickedWearables() |
| | 179 | | { |
| 1 | 180 | | controller.WearableClicked(EYEBROWS_ID); |
| | 181 | |
|
| 1 | 182 | | Assert.AreEqual(EYEBROWS_ID, controller.myModel.wearables.Last().id); |
| 1 | 183 | | } |
| | 184 | |
|
| | 185 | | [Test] |
| | 186 | | public void ProcessSupportedClickedHairColor() |
| | 187 | | { |
| 1 | 188 | | controller.HairColorClicked(hairColorList.colors[3]); |
| | 189 | |
|
| 1 | 190 | | Assert.AreEqual(hairColorList.colors[3], controller.myModel.hairColor); |
| 1 | 191 | | } |
| | 192 | |
|
| | 193 | | [Test] |
| | 194 | | public void ProcessNotSupportedClickedHairColor() |
| | 195 | | { |
| 1 | 196 | | var current = controller.myModel.hairColor; |
| 1 | 197 | | controller.HairColorClicked(hairColorList.colors[0] * new Color(0.2f, 0.4f, 0.2f)); //Getting an arbitrary/i |
| | 198 | |
|
| 1 | 199 | | Assert.AreEqual(current, controller.myModel.hairColor); |
| 1 | 200 | | } |
| | 201 | |
|
| | 202 | | [Test] |
| | 203 | | public void ProcessSupportedClickedSkinColor() |
| | 204 | | { |
| 1 | 205 | | controller.SkinColorClicked(skinColorList.colors[3]); |
| | 206 | |
|
| 1 | 207 | | Assert.AreEqual(skinColorList.colors[3], controller.myModel.skinColor); |
| 1 | 208 | | } |
| | 209 | |
|
| | 210 | | [Test] |
| | 211 | | public void ProcessNotSupportedClickedSkinColor() |
| | 212 | | { |
| 1 | 213 | | var current = controller.myModel.skinColor; |
| 1 | 214 | | controller.SkinColorClicked(skinColorList.colors[0] * new Color(0.2f, 0.4f, 0.2f)); //Getting an arbitrary/i |
| | 215 | |
|
| 1 | 216 | | Assert.AreEqual(current, controller.myModel.skinColor); |
| 1 | 217 | | } |
| | 218 | |
|
| | 219 | | [Test] |
| | 220 | | public void ProcessSupportedClickedEyeColor() |
| | 221 | | { |
| 1 | 222 | | controller.EyesColorClicked(eyeColorList.colors[3]); |
| | 223 | |
|
| 1 | 224 | | Assert.AreEqual(eyeColorList.colors[3], controller.myModel.eyesColor); |
| 1 | 225 | | } |
| | 226 | |
|
| | 227 | | [Test] |
| | 228 | | public void ProcessNotSupportedClickedEyesColor() |
| | 229 | | { |
| 1 | 230 | | var current = controller.myModel.eyesColor; |
| 1 | 231 | | controller.EyesColorClicked(eyeColorList.colors[0] * new Color(0.2f, 0.4f, 0.2f)); //Getting an arbitrary/in |
| | 232 | |
|
| 1 | 233 | | Assert.AreEqual(current, controller.myModel.eyesColor); |
| 1 | 234 | | } |
| | 235 | |
|
| | 236 | | [Test] |
| | 237 | | public void RandomizeOnlyTheSelectedSetOfWearables() |
| | 238 | | { |
| 1 | 239 | | controller.RandomizeWearables(); |
| | 240 | |
|
| 1 | 241 | | Assert.AreEqual(WearableLiterals.BodyShapes.FEMALE, controller.myModel.bodyShape.id); |
| 8 | 242 | | var categoriesEquiped = controller.myModel.wearables.Select(x => x.data.category).ToArray(); |
| 16 | 243 | | foreach (string category in categoriesEquiped) |
| | 244 | | { |
| 7 | 245 | | Assert.Contains(category, controller.myCategoriesToRandomize); |
| | 246 | | } |
| 1 | 247 | | } |
| | 248 | |
|
| | 249 | | [Test] |
| | 250 | | public void SaveAvatarProperly() |
| | 251 | | { |
| 1 | 252 | | userProfile.UpdateData(new UserProfileModel() |
| | 253 | | { |
| | 254 | | name = "name", |
| | 255 | | email = "mail", |
| | 256 | | avatar = new AvatarModel() |
| | 257 | | { |
| | 258 | | bodyShape = WearableLiterals.BodyShapes.FEMALE, |
| | 259 | | wearables = new List<string>() |
| | 260 | | { |
| | 261 | | EYEBROWS_ID, |
| | 262 | | "urn:decentraland:off-chain:base-avatars:f_eyes_00", |
| | 263 | | "urn:decentraland:off-chain:base-avatars:bear_slippers", |
| | 264 | | "urn:decentraland:off-chain:base-avatars:f_african_leggins", |
| | 265 | | "urn:decentraland:off-chain:base-avatars:f_mouth_00", |
| | 266 | | "urn:decentraland:off-chain:base-avatars:blue_bandana", |
| | 267 | | "urn:decentraland:off-chain:base-avatars:bee_t_shirt" |
| | 268 | | }, |
| | 269 | | skinColor = skinColorList.colors[0], |
| | 270 | | hairColor = hairColorList.colors[0], |
| | 271 | | eyeColor = eyeColorList.colors[0], |
| | 272 | | } |
| | 273 | | }, false); |
| | 274 | |
|
| 1 | 275 | | controller.WearableClicked(WearableLiterals.BodyShapes.MALE); |
| 1 | 276 | | controller.WearableClicked("urn:decentraland:off-chain:base-avatars:eyebrows_01"); |
| 1 | 277 | | controller.WearableClicked("urn:decentraland:off-chain:base-avatars:eyes_00"); |
| 1 | 278 | | controller.WearableClicked("urn:decentraland:off-chain:base-avatars:bear_slippers"); |
| 1 | 279 | | controller.WearableClicked("urn:decentraland:off-chain:base-avatars:basketball_shorts"); |
| 1 | 280 | | controller.WearableClicked("urn:decentraland:off-chain:base-avatars:mouth_00"); |
| 1 | 281 | | controller.WearableClicked("urn:decentraland:off-chain:base-avatars:blue_bandana"); |
| 1 | 282 | | controller.WearableClicked("urn:decentraland:off-chain:base-avatars:black_jacket"); |
| | 283 | |
|
| 1 | 284 | | controller.SaveAvatar(Texture2D.whiteTexture, Texture2D.whiteTexture, Texture2D.whiteTexture, Texture2D.whit |
| | 285 | |
|
| 1 | 286 | | AssertAvatarModelAgainstAvatarEditorHUDModel(userProfile.avatar, controller.myModel); |
| 1 | 287 | | } |
| | 288 | |
|
| | 289 | | private void AssertAvatarModelAgainstAvatarEditorHUDModel(AvatarModel avatarModel, AvatarEditorHUDModel avatarEd |
| | 290 | | { |
| 3 | 291 | | Assert.AreEqual(avatarModel.bodyShape, avatarEditorHUDModel.bodyShape.id); |
| | 292 | |
|
| 3 | 293 | | Assert.AreEqual(avatarModel.wearables.Count, avatarEditorHUDModel.wearables.Count); |
| 52 | 294 | | for (var i = 0; i < avatarModel.wearables.Count; i++) |
| | 295 | | { |
| 23 | 296 | | Assert.AreEqual(avatarModel.wearables[i], avatarEditorHUDModel.wearables[i].id); |
| | 297 | | } |
| | 298 | |
|
| 3 | 299 | | Assert.AreEqual(avatarModel.skinColor, avatarEditorHUDModel.skinColor); |
| 3 | 300 | | Assert.AreEqual(avatarModel.hairColor, avatarEditorHUDModel.hairColor); |
| 3 | 301 | | Assert.AreEqual(avatarModel.eyeColor, avatarEditorHUDModel.eyesColor); |
| 3 | 302 | | } |
| | 303 | | } |
| | 304 | | } |