using NUnit.Framework; using System.Collections; using System.IO; using UnityEditor; using UnityEngine; using UnityEngine.TestTools; /// /// Test the CourseActivityScreen class /// public class CourseActivityScreenTests { /// /// Setup the environment before each test /// [UnitySetUp] public IEnumerator SetupFunction() { string path = $"{Application.persistentDataPath}/wesign_unit_test.json"; string oneUser = $"{{\"version\":1537,\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0,\"useGPU\":false}}"; File.WriteAllText(path, oneUser); PersistentDataController.PATH = path; PersistentDataController.GetInstance().Load(); AssetDatabase.LoadAssetAtPath("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake(); SystemController.GetInstance().LoadNextScene("Common/Scenes/Boot"); yield return new WaitForSeconds(0.2f); } /// /// Cleanup after testing /// [TearDown] public void TearDown_CourseActivityTests() { PersistentDataController.PATH = null; } /// /// Full tests of the CoursesActivityScreen /// [UnityTest] public IEnumerator CoursesActivityTest() { var mainMenuScreen = GameObject.FindObjectOfType(); mainMenuScreen.GotoCourses(); yield return new WaitForSeconds(0.2f); var courseMenuScreen = GameObject.FindObjectOfType(); Assert.IsNotNull(courseMenuScreen, "Course was not started."); var courseList = courseMenuScreen.courseList; Assert.IsNotNull(courseList, "Course was not started."); courseList.SetCurrentCourse(0); SystemController.GetInstance().LoadNextScene("Common/Scenes/CourseActivityScreen"); yield return new WaitForSeconds(0.2f); var courseActivityScreen = GameObject.FindObjectOfType(); Assert.IsNotNull(courseActivityScreen); courseActivityScreen.StartCourse(); yield return new WaitForSeconds(0.5f); var templateCourse = GameObject.FindObjectOfType(); Assert.IsNotNull(templateCourse); templateCourse.ReturnToActivityScreen(); yield return new WaitForSeconds(0.2f); var courseActivityScreen2 = GameObject.FindObjectOfType(); Assert.IsNotNull(courseActivityScreen2); courseActivityScreen2.ResetCourseProgress(); yield return new WaitForSeconds(0.2f); var templateCourse2 = GameObject.FindObjectOfType(); Assert.IsNotNull(templateCourse2); var user = UserList.GetCurrentUser(); var progress = user.GetCourseProgress(0); progress.progress = 1.00f; progress.inUseLearnables = 0; templateCourse2.ReturnToActivityScreen(); yield return new WaitForSeconds(0.2f); } }