using NUnit.Framework; using System.Collections; using System.IO; using System.Linq; using TMPro; using UnityEditor; using UnityEngine; using UnityEngine.TestTools; using UnityEngine.UI; /// /// Test the UserCreationScreen class /// [TestFixture] public class UserCreationScreenTests { /// /// Wait time between scene transitions /// private const float WAIT_TIME = 0.2f; /// /// Setup the UserCreationScreen tests /// private IEnumerator Setup_UserCreationScreen(string startScreen = "Accounts/Scenes/UserCreationScreen") { string path = $"{Application.persistentDataPath}/wesign_unit_test.json"; string oneUser = "{\"version\":1027,\"users\":[{\"entries\":[],\"username\":\"Tester0\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}"; File.WriteAllText(path, oneUser); PersistentDataController.PATH = path; PersistentDataController.GetInstance().Load(); AssetDatabase.LoadAssetAtPath("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake(); SystemController.GetInstance().SwapScene(startScreen); yield return new WaitForSeconds(WAIT_TIME); } /// /// Cleanup after testing /// [TearDown] public void TearDown_UserCreationScreen() { PersistentDataController.PATH = null; } /// /// Test whether every item that needs to be assign in the editor, is assigned /// [UnityTest] public IEnumerator Test_EditorAssignments() { yield return Setup_UserCreationScreen(); var userCreationController = GameObject.FindObjectOfType(); Assert.IsNotNull(userCreationController); Assert.IsNotNull(userCreationController.errorMessage); Assert.IsNotNull(userCreationController.inputName); Assert.IsNotNull(userCreationController.avatarsContainer); Assert.IsNotNull(userCreationController.avatarPrefab); Assert.IsNotNull(userCreationController.backButton); Assert.IsTrue(UserCreationScreen.canGoBack); } /// /// Test whether the screen is correctly initialized /// [UnityTest] public IEnumerator Test_Start() { yield return Setup_UserCreationScreen(); var userCreationController = GameObject.FindObjectOfType(); Assert.IsFalse(userCreationController.errorMessage.activeSelf); Assert.IsTrue(userCreationController.backButton.activeSelf); var avatars = userCreationController.avatarsContainer.GetComponentsInChildren