using NUnit.Framework; using System.Collections; using System.IO; using UnityEditor; using UnityEngine; using UnityEngine.TestTools; /// /// Test the SpellingBeeGameEndedPanel class /// public class SpellingBeeGameEndedPanelTests { /// /// Setup for testing scoreboard of Spelling Bee /// [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("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); } /// /// Tests the scoreboard for Spelling Bee /// [UnityTest] public IEnumerator ScoreTest() { var spellingBeeController = GameObject.FindObjectOfType(); 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(); 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); } /// /// Cleanup after testing /// [TearDown] public void TearDown_SpellingBeeScoreTests() { PersistentDataController.PATH = null; } }