Files
unity-application/Assets/Common/PlayModeTests/StartGameTests.cs
2023-03-23 11:35:14 +00:00

107 lines
3.7 KiB
C#

using System.Collections;
using System.Linq;
using System.IO;
using NUnit.Framework;
using TMPro;
using UnityEngine;
using UnityEngine.TestTools;
using UnityEngine.SceneManagement;
public class StartGamesTests
{
[UnityTest]
public IEnumerator BootWithUsersTest()
{
string path = Path.Combine("Assets", "users.json");
var oneUser = "{\"currentUserIndex\": 0,\"storedUsers\": [{\"username\": \"TEST\",\"avatar\": {\"instanceID\": 40848},\"playtime\": 0.0,\"courses\": [],\"minigames\": []}]}";
using (StreamWriter writer = new StreamWriter(path))
{
writer.Write(oneUser);
}
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){
Debug.Log("no webcam");
Assert.IsNull(userCreationScreen);
Assert.IsNull(mainMenuScreen);
Assert.IsNotNull(bootScreen);
Assert.AreEqual(bootScreen.errorText.text, "Zorg ervoor dat je webcam correct is aangesloten!");
}
else
{
Debug.Log("everything is there");
Assert.IsNull(bootScreen);
Assert.IsNull(userCreationScreen);
Assert.IsNotNull(mainMenuScreen);
}
}
[UnityTest]
public IEnumerator BootWithoutUsersTest()
{
// Arrange
string path = Path.Combine("Assets", "users.json");
var oneUser = "{}";
using (StreamWriter writer = new StreamWriter(path))
{
writer.Write(oneUser);
}
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){
Debug.Log("no webcam");
Assert.IsNull(userCreationScreen);
Assert.IsNull(mainMenuScreen);
Assert.IsNotNull(bootScreen);
Assert.AreEqual(bootScreen.errorText.text, "Zorg ervoor dat je webcam correct is aangesloten!");
} else
{
Debug.Log("no users");
Assert.IsNull(bootScreen);
Assert.IsNull(mainMenuScreen);
Assert.IsNotNull(userCreationScreen);
}
}
}