97 lines
4.0 KiB
C#
97 lines
4.0 KiB
C#
using NUnit.Framework;
|
|
using System.Collections;
|
|
using System.IO;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.TestTools;
|
|
|
|
|
|
public class StartGamesTests
|
|
{
|
|
[UnityTest]
|
|
public IEnumerator BootWithUsersTest()
|
|
{
|
|
string path = $"{Application.persistentDataPath}/unit_test_users.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}}";
|
|
|
|
File.WriteAllText(path, oneUser);
|
|
PersistentDataController.PATH = path;
|
|
PersistentDataController.GetInstance().Load();
|
|
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
|
|
SceneManager.LoadScene("Common/Scenes/Boot");
|
|
|
|
yield return new WaitForSeconds(1);
|
|
|
|
var userCreationScreen = (UserCreationScreen)GameObject.FindObjectOfType(typeof(UserCreationScreen));
|
|
var bootScreen = (BootScreen)GameObject.FindObjectOfType(typeof(BootScreen));
|
|
var mainMenuScreen = (MainMenuScreen)GameObject.FindObjectOfType(typeof(MainMenuScreen));
|
|
|
|
// yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
|
|
// if (Application.HasUserAuthorization(UserAuthorization.WebCam))
|
|
// {
|
|
// Debug.Log("no access");
|
|
// Assert.IsNull(userCreationScreen);
|
|
// Assert.IsNull(mainMenuScreen);
|
|
// Assert.IsNotNull(bootScreen);
|
|
// Assert.AreEqual(bootScreen.errorText.text, "Zorg ervoor dat deze applicatie toegang heeft tot je webcam!");
|
|
// }
|
|
// else
|
|
if (0 >= WebCamTexture.devices.Length)
|
|
{
|
|
Assert.IsNull(mainMenuScreen);
|
|
Assert.IsNotNull(bootScreen);
|
|
Assert.AreEqual(bootScreen.errorText.text, "Zorg ervoor dat je webcam correct is aangesloten!");
|
|
}
|
|
else
|
|
{
|
|
Assert.IsNull(bootScreen);
|
|
Assert.IsNotNull(mainMenuScreen);
|
|
}
|
|
Assert.IsNull(userCreationScreen);
|
|
}
|
|
|
|
[UnityTest]
|
|
public IEnumerator BootWithoutUsersTest()
|
|
{
|
|
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
|
string noUsers = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
|
|
|
|
File.WriteAllText(path, noUsers);
|
|
PersistentDataController.PATH = path;
|
|
PersistentDataController.GetInstance().Load();
|
|
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
|
|
SceneManager.LoadScene("Common/Scenes/Boot");
|
|
|
|
yield return new WaitForSeconds(1);
|
|
|
|
var userCreationScreen = (UserCreationScreen)GameObject.FindObjectOfType(typeof(UserCreationScreen));
|
|
var bootScreen = (BootScreen)GameObject.FindObjectOfType(typeof(BootScreen));
|
|
var mainMenuScreen = (MainMenuScreen)GameObject.FindObjectOfType(typeof(MainMenuScreen));
|
|
|
|
// yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
|
|
// if (Application.HasUserAuthorization(UserAuthorization.WebCam))
|
|
// {
|
|
// Debug.Log("no access");
|
|
// Assert.IsNull(userCreationScreen);
|
|
// Assert.IsNull(mainMenuScreen);
|
|
// Assert.IsNotNull(bootScreen);
|
|
// Assert.AreEqual(bootScreen.errorText.text, "Zorg ervoor dat deze applicatie toegang heeft tot je webcam!");
|
|
// }
|
|
// else
|
|
if (0 >= WebCamTexture.devices.Length)
|
|
{
|
|
Assert.IsNull(userCreationScreen);
|
|
Assert.IsNotNull(bootScreen);
|
|
Assert.AreEqual(bootScreen.errorText.text, "Zorg ervoor dat je webcam correct is aangesloten!");
|
|
}
|
|
else
|
|
{
|
|
Assert.IsNull(bootScreen);
|
|
Assert.IsNotNull(userCreationScreen);
|
|
}
|
|
Assert.IsNull(mainMenuScreen);
|
|
}
|
|
|
|
}
|