Files
h-school/tests/HSchool.Content.Tests/MapViewTests.cs
T

97 lines
4.1 KiB
C#

namespace HSchool.Content.Tests;
public class MapViewTests
{
[Fact]
public void VanillaMap_LabelsTheTreeInTheRequestedLocale()
{
var root = Path.Combine(AppContext.BaseDirectory, "vanilla");
var documents = PackDocuments.FromDirectory(CatalogLoader.CorePackId, root);
var catalog = new CatalogLoader().Load([CatalogLoader.CorePackId], documents);
var map = CatalogLoader.LastDefaultMap([CatalogLoader.CorePackId], documents);
Assert.NotNull(map);
var ru = MapView.Build(catalog, map, "ru");
var en = MapView.Build(catalog, map, "en");
Assert.Equal("yard", ru[0].Id);
Assert.Equal(string.Empty, ru[0].ParentId);
Assert.Equal("yard", ru.Single(node => node.Id == "main").ParentId);
Assert.Equal("yard", ru.Single(node => node.Id == "gym").ParentId);
Assert.Equal("floor-1", ru.Single(node => node.Id == "principals-office").ParentId);
Assert.Equal("gym-floor", ru.Single(node => node.Id == "gym-hall").ParentId);
var officeRu = ru.Single(node => node.Id == "principals-office");
Assert.Equal("Кабинет директора", officeRu.Name);
Assert.Equal(
[new MapViewItem("Кресло директора", 1), new MapViewItem("Стол", 1), new MapViewItem("Стул", 2)],
officeRu.Items);
Assert.Equal(0, officeRu.PupilSlots);
Assert.Equal(["Директор"], officeRu.Positions);
var officeEn = en.Single(node => node.Id == "principals-office");
Assert.Equal("Principal's office", officeEn.Name);
Assert.Equal(
[new MapViewItem("Principal's chair", 1), new MapViewItem("Desk", 1), new MapViewItem("Chair", 2)],
officeEn.Items);
Assert.Equal(["Principal"], officeEn.Positions);
var corridor = ru.Single(node => node.Id == "corridor-1");
Assert.Empty(corridor.Items);
Assert.Empty(corridor.Positions);
Assert.Equal("Коридор 1", corridor.Name);
var classroom = ru.Single(node => node.Id == "classroom-1a");
Assert.Equal("Класс 1A", classroom.Name);
Assert.Equal(
[
new MapViewItem("Доска", 1),
new MapViewItem("Стол", 1),
new MapViewItem("Стул", 1),
new MapViewItem("Парта", 16),
],
classroom.Items);
Assert.Equal(16, classroom.PupilSlots);
Assert.Equal(["Учитель"], classroom.Positions);
Assert.Equal("Classroom 1A", en.Single(node => node.Id == "classroom-1a").Name);
}
[Fact]
public void FloorLabel_FollowsTheDefLabelInsteadOfReplacingIt()
{
var catalog = new CatalogLoader().Load(
[CatalogLoader.CorePackId],
[
new ContentDocument(
CatalogLoader.CorePackId,
"defs/floors/standard.jsonc",
"""{ "defName": "StandardFloor" }"""),
new ContentDocument(
CatalogLoader.CorePackId,
"defs/territories/yard.jsonc",
"""{ "defName": "Yard" }"""),
new ContentDocument(
CatalogLoader.CorePackId,
"localizations/ru.jsonc",
"""{ "StandardFloor": "Этаж", "Yard": "Двор" }"""),
]);
var map = new MapLayout
{
Territory = new TerritoryNode { Id = "yard", Def = "Yard" },
Buildings = [new BuildingNode { Id = "main", Def = "Main" }],
Floors =
[
new FloorNode { Id = "floor-1", Def = "StandardFloor", Building = "main", Label = "1" },
new FloorNode { Id = "floor-2", Def = "StandardFloor", Building = "main" },
],
};
var nodes = MapView.Build(catalog, map, "ru");
// A bare "1" in the tree is the label on its own; the def label carries the noun.
Assert.Equal("Этаж 1", nodes.Single(node => node.Id == "floor-1").Name);
Assert.Equal("Этаж", nodes.Single(node => node.Id == "floor-2").Name);
}
}