Resolve WES-187 "Unit tests common and course"
This commit is contained in:
committed by
Jerome Coudron
parent
672ff367e2
commit
48b915acba
@@ -1,19 +1,21 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
public class UserButtonTests
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Setup the environment before each test
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[UnitySetUp]
|
||||
public IEnumerator SetupFunction()
|
||||
{
|
||||
string path = $"{Application.persistentDataPath}/wesign_unit_test.json";
|
||||
string oneUser = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
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;
|
||||
@@ -23,26 +25,73 @@ public class UserButtonTests
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
}
|
||||
|
||||
/* [UnityTest]
|
||||
public IEnumerator OpenProgressCallbackTest()
|
||||
{
|
||||
var userButton = (UserButton)GameObject.FindObjectOfType(typeof(UserButton));
|
||||
userButton.OpenProgressCallback();
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
var listCoursesScreen = (ListCoursesScreen)GameObject.FindObjectOfType(typeof(ListCoursesScreen));
|
||||
Assert.IsNotNull(listCoursesScreen);
|
||||
}*/
|
||||
/// <summary>
|
||||
/// Cleanup after testing
|
||||
/// </summary>
|
||||
[TearDown]
|
||||
public void TearDown_UserButtonTests()
|
||||
{
|
||||
PersistentDataController.PATH = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test the ChangeUserCallback on the UserButton
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[UnityTest]
|
||||
public IEnumerator ChangeUserCallbackTest()
|
||||
{
|
||||
var userButton = (UserButton)GameObject.FindObjectOfType(typeof(UserButton));
|
||||
var userButton = GameObject.FindObjectOfType<UserButton>();
|
||||
userButton.ChangeUserCallback();
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
var changeUserScreen = (ChangeUserScreen)GameObject.FindObjectOfType(typeof(ChangeUserScreen));
|
||||
var changeUserScreen = GameObject.FindObjectOfType<ChangeUserScreen>();
|
||||
Assert.IsNotNull(changeUserScreen);
|
||||
yield return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Test if the username and avatar are correctly loaded
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[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>
|
||||
/// <returns></returns>
|
||||
[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>
|
||||
/// <returns></returns>
|
||||
[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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user