// Copyright (c) 2025 EFramework Innovation. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
using NUnit.Framework;
using EFramework.Unity.UIPlugin;
using UnityEditor;
using UnityEngine;
///
/// TestUIWrapContentEditor 是 UIWrapContentEditor 的单元测试。
///
public class TestUIWrapContentEditor
{
[Test]
public void Create()
{
// 执行菜单操作创建Wrap Content
EditorApplication.ExecuteMenuItem("GameObject/UI/Wrap Content");
// 验证结果
var createdObject = Selection.activeGameObject;
Assert.That(createdObject, Is.Not.Null, "应当创建新的游戏对象");
Assert.That(createdObject.name, Is.EqualTo("Wrap Content"), "游戏对象名称应为'Wrap Content'");
// 验证组件
var wrapContent = createdObject.GetComponent();
Assert.That(wrapContent, Is.Not.Null, "应当添加UIWrapContent组件");
// 验证层级结构(从ScrollRect生成,应该包含Viewport和Content)
var viewport = createdObject.transform.Find("Viewport");
Assert.That(viewport, Is.Not.Null, "应当包含Viewport子对象");
var content = viewport?.Find("Content");
Assert.That(content, Is.Not.Null, "应当包含Content子对象");
// 验证ScrollRect的属性被转移到WrapContent
Assert.That(wrapContent.viewport, Is.Not.Null, "viewport引用应正确设置");
Assert.That(wrapContent.content, Is.Not.Null, "content引用应正确设置");
// 清理
if (createdObject != null) GameObject.DestroyImmediate(createdObject);
}
}