Files
unity-application/Assets/Common/Tests/PlayMode/ThemeItemTests.cs
2023-05-14 20:18:29 +00:00

67 lines
2.3 KiB
C#

using NUnit.Framework;
using System.Collections;
using System.IO;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools;
using UnityEngine.UI;
/// <summary>
/// Test the ThemeItem class
/// </summary>
public class ThemeItemTests
{
/// <summary>
/// Setup the environment before each test
/// </summary>
[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<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
SystemController.GetInstance().LoadNextScene("Common/Scenes/ListMinigamesScreen");
yield return new WaitForSeconds(0.2f);
}
/// <summary>
/// Cleanup after testing
/// </summary>
[TearDown]
public void TearDown_ThemeItemTests()
{
PersistentDataController.PATH = null;
}
/// <summary>
/// Test the callback function of a ThemeItem
/// </summary>
[UnityTest]
public IEnumerator CallBackTest()
{
var listMinigamesScreen = GameObject.FindObjectOfType<ListMinigamesScreen>();
listMinigamesScreen.minigameList.SetCurrentMinigame(MinigameIndex.SPELLING_BEE);
listMinigamesScreen.LoadScene("Common/Scenes/MinigameActivityScreen");
yield return new WaitForSeconds(0.2f);
SystemController.GetInstance().LoadNextScene("Common/Scenes/ThemeSelectionScreen");
yield return new WaitForSeconds(0.2f);
GameObject buttonObject = GameObject.Find("Theme Item(Clone)");
Assert.IsNotNull(buttonObject, "Could not find button object");
Button button = buttonObject.GetComponent<Button>();
Assert.IsNotNull(button, "Button component not found on button object");
button.onClick.Invoke();
yield return new WaitForSeconds(0.2f);
Assert.AreEqual("SpellingBeeGame", SceneManager.GetActiveScene().name);
}
}