Resolve WES-187 "Unit tests common and course"
This commit is contained in:
committed by
Jerome Coudron
parent
672ff367e2
commit
48b915acba
63
Assets/Common/Tests/PlayMode/ThemeItemTests.cs
Normal file
63
Assets/Common/Tests/PlayMode/ThemeItemTests.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
public class ThemeItemTests
|
||||
{
|
||||
/// <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\":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;
|
||||
PersistentDataController.GetInstance().Load();
|
||||
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
|
||||
SystemController.GetInstance().LoadNextScene("Common/Scenes/ListMinigamesScreen");
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
}
|
||||
/// <summary>
|
||||
/// Cleanup after testing
|
||||
/// </summary>
|
||||
[TearDown]
|
||||
public void TearDown_ThemeItemTests()
|
||||
{
|
||||
PersistentDataController.PATH = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Test the callback function of a ThemeItem
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[UnityTest]
|
||||
public IEnumerator CallBackTest()
|
||||
{
|
||||
var listMinigamesScreen = GameObject.FindObjectOfType<ListMinigamesScreen>();
|
||||
listMinigamesScreen.minigameList.SetCurrentMinigame(MinigameIndex.SPELLING_BEE);
|
||||
listMinigamesScreen.LoadScene("Common/Scenes/MinigameActivityScreen");
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
SystemController.GetInstance().LoadNextScene("Common/Scenes/ThemeSelectionScreen");
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
GameObject buttonObject = GameObject.Find("Theme Item(Clone)");
|
||||
Assert.IsNotNull(buttonObject, "Could not find button object");
|
||||
|
||||
Button button = buttonObject.GetComponent<Button>();
|
||||
Assert.IsNotNull(button, "Button component not found on button object");
|
||||
|
||||
button.onClick.Invoke();
|
||||
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
Assert.AreEqual("SpellingBeeGame", SceneManager.GetActiveScene().name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user