98 lines
3.2 KiB
C#
98 lines
3.2 KiB
C#
using NUnit.Framework;
|
|
using System.Collections;
|
|
using System.IO;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.TestTools;
|
|
|
|
/// <summary>
|
|
/// Test the UserButton class
|
|
/// </summary>
|
|
public class UserButtonTests
|
|
{
|
|
/// <summary>
|
|
/// Setup the environment before each test
|
|
/// </summary>
|
|
[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<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
|
|
SystemController.GetInstance().LoadNextScene("Common/Scenes/CoursesMenuScreen");
|
|
yield return new WaitForSeconds(0.2f);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Cleanup after testing
|
|
/// </summary>
|
|
[TearDown]
|
|
public void TearDown_UserButtonTests()
|
|
{
|
|
PersistentDataController.PATH = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test the ChangeUserCallback on the UserButton
|
|
/// </summary>
|
|
[UnityTest]
|
|
public IEnumerator ChangeUserCallbackTest()
|
|
{
|
|
var userButton = GameObject.FindObjectOfType<UserButton>();
|
|
userButton.ChangeUserCallback();
|
|
yield return new WaitForSeconds(0.2f);
|
|
|
|
var changeUserScreen = GameObject.FindObjectOfType<ChangeUserScreen>();
|
|
Assert.IsNotNull(changeUserScreen);
|
|
yield return null;
|
|
}
|
|
/// <summary>
|
|
/// Test if the username and avatar are correctly loaded
|
|
/// </summary>
|
|
[UnityTest]
|
|
public IEnumerator CorrectUsernameAndAvatarTest()
|
|
{
|
|
var userButton = GameObject.FindObjectOfType<UserButton>();
|
|
|
|
Assert.AreEqual("TEST", userButton.username.text, "Username is not correctly displayed.");
|
|
Assert.IsNotNull(userButton.avatar.sprite, "Avatar sprite is null.");
|
|
|
|
yield return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test the transition to UserProgressScreen
|
|
/// </summary>
|
|
[UnityTest]
|
|
public IEnumerator ChangeSceneToUserProgressScreenTest()
|
|
{
|
|
var userButton = GameObject.FindObjectOfType<UserButton>();
|
|
|
|
userButton.OpenProgressCallback();
|
|
yield return new WaitForSeconds(0.2f);
|
|
|
|
var userProgressScreen = GameObject.FindObjectOfType<UserProgressScreen>();
|
|
Assert.IsNotNull(userProgressScreen, "Scene was not correctly changed to UserProgressScreen.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test is the user dropdown menu works correctly
|
|
/// </summary>
|
|
[UnityTest]
|
|
public IEnumerator ToggleDropdownTest()
|
|
{
|
|
var userButton = GameObject.FindObjectOfType<UserButton>();
|
|
|
|
bool initialActiveState = userButton.dropdownBox.activeSelf;
|
|
userButton.ToggleDropdown();
|
|
|
|
Assert.AreNotEqual(initialActiveState, userButton.dropdownBox.activeSelf, "Dropdown box active state was not toggled.");
|
|
|
|
yield return null;
|
|
}
|
|
}
|