Files
unity-application/Assets/SpellingBee/Tests/PlayMode/GameEndedPanelTests.cs
2023-05-17 17:36:27 +00:00

72 lines
2.9 KiB
C#

using NUnit.Framework;
using System.Collections;
using System.IO;
using UnityEditor;
using UnityEngine;
using UnityEngine.TestTools;
/// <summary>
/// Test the SpellingBeeGameEndedPanel class
/// </summary>
public class SpellingBeeGameEndedPanelTests
{
/// <summary>
/// Setup for testing scoreboard of Spelling Bee
/// </summary>
[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,\"useGPU\":false}}";
File.WriteAllText(path, oneUser);
PersistentDataController.PATH = path;
PersistentDataController.GetInstance().Load();
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
// Go to the minigame-selection scene to make sure that the minigameIndex is set correctly
SystemController.GetInstance().LoadNextScene("Common/Scenes/ListMinigamesScreen");
yield return new WaitForSeconds(0.2f);
ListMinigamesScreen minigameScreen = (ListMinigamesScreen)GameObject.FindObjectOfType(typeof(ListMinigamesScreen));
minigameScreen.minigameList.SetCurrentMinigame(MinigameIndex.SPELLING_BEE);
SystemController.GetInstance().LoadNextScene("SpellingBee/Scenes/SpellingBeeGame");
yield return new WaitForSeconds(0.2f);
}
/// <summary>
/// Tests the scoreboard for Spelling Bee
/// </summary>
[UnityTest]
public IEnumerator ScoreTest()
{
var spellingBeeController = GameObject.FindObjectOfType<SpellingBeeController>();
spellingBeeController.NextWord();
spellingBeeController.NextLetter(false);
spellingBeeController.NextLetter(true);
spellingBeeController.NextLetter(false);
yield return new WaitForSeconds(1f);
spellingBeeController.ActivateEnd(true);
// Fetch the panel with the info for the fields and check if the controller has implemented them
var SpellingBeeGameEndedPanel = GameObject.FindObjectOfType<SpellingBeeGameEndedPanel>();
Assert.NotNull(SpellingBeeGameEndedPanel);
Assert.AreEqual("Score: 0", SpellingBeeGameEndedPanel.scoreText.text);
Assert.AreEqual("1", SpellingBeeGameEndedPanel.lettersRightText.text);
Assert.AreEqual("2", SpellingBeeGameEndedPanel.lettersWrongText.text);
Assert.AreEqual("3", SpellingBeeGameEndedPanel.lettersTotalText.text);
Assert.AreEqual("00:01", SpellingBeeGameEndedPanel.timeText.text);
}
/// <summary>
/// Cleanup after testing
/// </summary>
[TearDown]
public void TearDown_SpellingBeeScoreTests()
{
PersistentDataController.PATH = null;
}
}