Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/ManagementApi/Services/Trees/ScriptTreeServiceTests.cs
Nicklas Kramer 8213da1b77 Trees: Expanding sibling endpoints to include all entities with trees (#20150)
* Adding member types sibling endpoints

* Introducing sibling endpoint for Partial Views and logic.

* Introducing sibling endpoint for stylesheets

* Introducing sibling endpoint for scripts

* Introducing FileSystemTreeServiceBase.cs

* Introducing interfaces for implementation specific services

* Introducing services for specific trees

* Modifying controller bases to fit new interface and logic.

* Obsoleting old constructors related to PartialView

* Obsoleting ctors related to Stylesheets

* Obsoleting ctors related to scripts

* Adding tests for scriptsTreeService

* Adding tests for siblings

* Removing unused dependencies

* Removing signs and replacing it with flags

* Fixing breaking changes by obsoletion

* Fixing more breaking changes

* Registering missing service

* Fixing breaking changes again

* Changing name of method GetSiblingsViewModels

* Rewritten tests for less bloat and less duplicate code

* Expanding tests to include other methods from service

* Test refactoring: avoided populating file systems that weren't under test, updated encapsulation, renaming, further re-use.

* Management API: Expanding the existing sibling endpoints to support trashed entities (#20154)

* Refactoring existing logic to include trashed items

* Including tests for trashed entities

* Groundwork for trashed siblings

* Documents trashed siblings endpoint

* Controller for Media trashed items

* Expanding tests to include a test for trashed siblings

* Code review corrections

* Resolving code review

---------

Co-authored-by: Andy Butland <abutland73@gmail.com>
2025-09-23 11:17:25 +02:00

54 lines
1.9 KiB
C#

using NUnit.Framework;
using Umbraco.Cms.Api.Management.Services.FileSystem;
using Umbraco.Cms.Api.Management.ViewModels.Tree;
using Umbraco.Cms.Core.IO;
namespace Umbraco.Cms.Tests.Integration.ManagementApi.Services.Trees;
public class ScriptTreeServiceTests : FileSystemTreeServiceTestsBase
{
protected override string FileSystemPath => GlobalSettings.UmbracoScriptsPath;
protected override IFileSystem? GetScriptsFileSystem() => TestFileSystem;
[Test]
public void Can_Get_Siblings_From_Script_Tree_Service()
{
var service = new ScriptTreeService(FileSystems);
FileSystemTreeItemPresentationModel[] treeModel = service.GetSiblingsViewModels("file5", 1, 1, out long before, out var after);
int index = Array.FindIndex(treeModel, item => item.Name == "file5");
Assert.AreEqual(treeModel[index].Name, "file5");
Assert.AreEqual(treeModel[index - 1].Name, "file4");
Assert.AreEqual(treeModel[index + 1].Name, "file6");
Assert.That(treeModel.Length == 3);
Assert.AreEqual(after, 3);
Assert.AreEqual(before, 4);
}
[Test]
public void Can_Get_Ancestors_From_StyleSheet_Tree_Service()
{
var service = new ScriptTreeService(FileSystems);
var path = Path.Join("tests", "file5");
FileSystemTreeItemPresentationModel[] treeModel = service.GetAncestorModels(path, true);
Assert.IsNotEmpty(treeModel);
Assert.AreEqual(treeModel.Length, 2);
Assert.AreEqual(treeModel[0].Name, "tests");
}
[Test]
public void Can_Get_PathViewModels_From_StyleSheet_Tree_Service()
{
var service = new ScriptTreeService(FileSystems);
FileSystemTreeItemPresentationModel[] treeModels = service.GetPathViewModels(string.Empty, 0, Int32.MaxValue, out var totalItems);
Assert.IsNotEmpty(treeModels);
Assert.AreEqual(treeModels.Length, totalItems);
}
}