// 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 UnityEngine;
///
/// TestUIAtlas 是 UIAtlas 的单元测试。
///
public class TestUIAtlas
{
[Test]
public void GetSprite()
{
// 创建测试对象
var gameObject = new GameObject("TestAtlas");
var atlas = gameObject.AddComponent();
// 准备测试精灵
Sprite[] testSprites = new Sprite[2];
testSprites[0] = Sprite.Create(Texture2D.whiteTexture, new Rect(), Vector2.zero);
testSprites[0].name = "Sprite1";
testSprites[1] = Sprite.Create(Texture2D.whiteTexture, new Rect(), Vector2.zero);
testSprites[1].name = "Sprite2";
// 设置精灵数组
atlas.Sprites = testSprites;
// 正常获取精灵图
var sprite1 = atlas.GetSprite("Sprite1");
Assert.That(sprite1, Is.Not.Null, "应当能找到存在的精灵");
Assert.That(sprite1.name, Is.EqualTo("Sprite1"), "应当返回正确名称的精灵");
// 获取不存在的精灵
var nonExistSprite = atlas.GetSprite("NonExistentSprite");
Assert.That(nonExistSprite, Is.Null, "不存在的精灵应返回null");
// 空名称
var emptyNameSprite = atlas.GetSprite("");
Assert.That(emptyNameSprite, Is.Null, "空名称应返回null");
// 清理
Object.DestroyImmediate(gameObject);
}
}