using NUnit.Framework; using System.Collections; using System.IO; using UnityEditor; using UnityEngine; using UnityEngine.TestTools; /// /// Test the CourseMenuScreen class /// public class CourseMenuScreenTests { /// /// Setup the environment before each test /// [UnitySetUp] public IEnumerator SetupFunction() { string path = $"{Application.persistentDataPath}/wesign_unit_test.json"; string oneUser = $"{{\"version\":1027,\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"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().LoadNextScene("Common/Scenes/CoursesMenuScreen"); yield return new WaitForSeconds(0.2f); } /// /// Cleanup after testing /// [TearDown] public void TearDown_CourseMenuScreenTests() { PersistentDataController.PATH = null; } /// /// Test to verify the navigation to the list of courses screen. /// [UnityTest] public IEnumerator GotoListOfCoursesTest() { var courseMenuScreen = GameObject.FindObjectOfType(); courseMenuScreen.GotoListOfCourses(); yield return new WaitForSeconds(0.2f); var listCoursesScreen = GameObject.FindObjectOfType(); Assert.IsNotNull(listCoursesScreen); } /// /// Test to verify the navigation to the recent courses screen. /// [UnityTest] public IEnumerator RecentCoursesTest() { 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); GameObject backbutton = GameObject.Find("ButtonBack"); Assert.IsNotNull(backbutton); backbutton.GetComponent().onClick.Invoke(); yield return null; } }