From 68ce9a7fa61f5ec41bb4efb1c6f763483d292f87 Mon Sep 17 00:00:00 2001 From: alexiscatnip Date: Thu, 14 Jul 2022 03:08:31 +0800 Subject: [PATCH] test: fix GridDropdown_HasManyGrids regression from past refactoring --- .../GridSelectorTests/GridSelectorTests.cs | 48 ++++++++----------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/Assets/Tests/Raindrop/RaindropIntegrationTests/GridSelectorTests/GridSelectorTests.cs b/Assets/Tests/Raindrop/RaindropIntegrationTests/GridSelectorTests/GridSelectorTests.cs index 2bee811..df7dea9 100644 --- a/Assets/Tests/Raindrop/RaindropIntegrationTests/GridSelectorTests/GridSelectorTests.cs +++ b/Assets/Tests/Raindrop/RaindropIntegrationTests/GridSelectorTests/GridSelectorTests.cs @@ -3,6 +3,7 @@ using System.Collections; using NUnit.Framework; using Plugins.CommonDependencies; using Raindrop.Tests.RaindropIntegrationTests.Helpers; +using UnityEditor; using UnityEngine; using UnityEngine.TestTools; @@ -12,33 +13,19 @@ namespace Raindrop.Tests.RaindropIntegrationTests.GridSelectorTests public class GridSelectorTests { //https://forum.unity.com/threads/add-coroutine-version-of-onetimesetup.890092/ - private bool initialized = false; [UnitySetUp] public IEnumerator UnitySetup() { - if (!initialized) - { - initialized = true; - - //+++++++++++++load test scene+++++++ - // load the base scene - yield return SceneLoader.LoadHeadlessScene(); - - //at this point, raindropInstance is ready. - var instance = ServiceLocator.Instance.Get(); - Assert.True(instance!=null, "instance is null"); - - //open up the dropdown small ui. - string pathOfPrefabDirectory = "LoginUI/"; - string prefabName = "GridSelection"; - var dropdownUI = GameObject.Instantiate( - Resources.Load(pathOfPrefabDirectory+prefabName) - ) as GameObject; - Assert.True(dropdownUI!=null, "dropdown prefab not found in resources"); - //+++++++++++++finish load test scene+++++++ - yield return null; - - } + //+++++++++++++load test scene+++++++ + // load the base scene + yield return SceneLoader.LoadHeadlessScene(); + + //at this point, raindropInstance is ready. + var instance = ServiceLocator.Instance.Get(); + Assert.True(instance!=null, "instance is null"); + + //+++++++++++++finish load test scene+++++++ + yield return null; } [OneTimeTearDown] @@ -51,11 +38,16 @@ namespace Raindrop.Tests.RaindropIntegrationTests.GridSelectorTests [UnityTest] public IEnumerator GridDropdown_HasManyGrids() { + //load and open up the dropdown small ui. + string pathOfPrefabDirectory = "Assets/Raindrop/UI/Login/"; + string prefabName = "GridSelection.prefab"; + var prefab = AssetDatabase.LoadAssetAtPath(pathOfPrefabDirectory+prefabName, typeof(GameObject)); + GameObject dropdownUI = (GameObject) GameObject.Instantiate(prefab); + Assert.True(dropdownUI!=null, "dropdown prefab not found in resources"); + //click dropdown UI to reveal its full content - var dropdown_GO = GameObject.Find("Dropdown"); - Assert.True(dropdown_GO,"the GO with name Dropdown is not found"); - GridSelectionView gridGridSelection = dropdown_GO.GetComponent(); - Assert.True(gridGridSelection,"the dropdown doesnt have DropdownViewPresenter"); + GridSelectionView gridGridSelection = dropdownUI.GetComponent(); + Assert.True(gridGridSelection,"the dropdown doesnt have GridSelectionView"); yield return new WaitForSeconds(2); // seems if you don't wait, the options count are not updated yet.