A game about forced loneliness, made by TACStudios
1using System.IO;
2using System.Linq;
3using NUnit.Framework;
4using Unity.Multiplayer.Center.Window;
5using UnityEditor;
6using UnityEngine;
7using UnityEngine.UIElements;
8
9namespace Unity.MultiplayerCenterTests
10{
11 internal static class UtilsForGettingStartedTabTests
12 {
13 public static void OpenGettingStartedTab()
14 {
15 var window = EditorWindow.GetWindow<MultiplayerCenterWindow>();
16 window.CurrentTabTest = 1;
17 }
18
19 public static VisualElement GetSection(string sectionName)
20 {
21 return EditorWindow.GetWindow<MultiplayerCenterWindow>().rootVisualElement.Q(sectionName);
22 }
23
24 public static bool CheckErrorLogged(LogType type)
25 {
26 return type == LogType.Error || type == LogType.Exception;
27 }
28
29 public static bool DeleteSetupDirectoryIfExists(string directoryPath)
30 {
31 directoryPath = directoryPath.TrimEnd('/');
32 var metaFilePath = $"{directoryPath}.meta";
33 if(File.Exists(metaFilePath)) // In case the directory is not accessible, Delete will throw an exception
34 {
35 File.Delete(metaFilePath);
36 }
37
38 if (Directory.Exists(directoryPath))
39 {
40 Directory.Delete(directoryPath, true);
41 return true;
42 }
43
44 return false;
45 }
46
47 public static void AssertGameObjectHasNoMissingScripts(GameObject gameObject)
48 {
49 var components = gameObject.GetComponents<Component>();
50 for (var index = 0; index < components.Length; index++)
51 {
52 var component = components[index];
53 Assert.IsNotNull(component, $"GameObject {gameObject.name} has missing script (component index: {index})");
54 }
55 }
56
57 /// <summary>
58 /// Returns true if a SettingsPage (right side of the SettingsWindow) has content.
59 /// This is useful to test if calling SettingsService.OpenProjectSettings("Your setting")
60 /// makes the window show content. In case your path does not open settings, the right side
61 /// will be empty and false will be returned.
62 /// Caution: This will only work for SettingsPages created with UI-Toolkit.
63 /// </summary>
64 /// <returns> True if settings are shown on the right side of the SettingsWindow, false if no settings window is
65 /// shown, or the content on the right is empty.</returns>
66 public static bool SettingsWindowRightSideHasContent()
67 {
68 var windows = Resources.FindObjectsOfTypeAll(typeof(EditorWindow)) as EditorWindow[];
69 var projectSettingsWindow = windows.FirstOrDefault(window => window.GetType().FullName == "UnityEditor.ProjectSettingsWindow");
70 if (projectSettingsWindow == null)
71 return false;
72
73 var settingsPanel = projectSettingsWindow.rootVisualElement.Q<VisualElement>(className: "settings-panel");
74 if (settingsPanel == null)
75 return false;
76 return settingsPanel.Children().First().childCount > 0;
77 }
78 }
79}