Files
PnvPanel/backend/tests/PnvPanel.Application.Tests/Admin/Instructions/InstructionTabCommandHandlerTests.cs
T
Leonid Pershin bef3880593
CI / Backend (build + test) (push) Successful in 1m17s
CI / Frontend (lint + typecheck + build) (push) Successful in 32s
Add instructions management functionality and update related components
- Introduced new endpoints for managing instruction intros and tabs, allowing admins to create, update, and delete instructional content.
- Enhanced the FactoryResetCommandHandler to include the seeding of instruction data during a factory reset.
- Updated the database schema to include InstructionIntro and InstructionTab entities, with corresponding migrations.
- Improved frontend routing and components to support the new instructions section, including a dedicated page for displaying instructions and tabs.
- Enhanced API documentation to reflect the new instruction management features and their expected request/response formats.
- Added localization support for the new instructions functionality in both Russian and English.
2026-07-14 22:20:10 +03:00

98 lines
3.3 KiB
C#

using PnvPanel.Application.Admin.Instructions;
using PnvPanel.Application.Tests.TestSupport;
using PnvPanel.Domain.Instructions;
using Xunit;
namespace PnvPanel.Application.Tests.Admin.Instructions;
public class InstructionTabCommandHandlerTests
{
[Fact]
public async Task Create_AddsTab()
{
using var dbContext = InMemoryDbContextFactory.Create();
var handler = new CreateInstructionTabCommandHandler(dbContext);
var result = await handler.Handle(
new CreateInstructionTabCommand("Настройка роутера", "текст", 10),
CancellationToken.None
);
await dbContext.SaveChangesAsync(CancellationToken.None);
Assert.True(result.IsSuccess);
Assert.Equal("Настройка роутера", result.Value.Title);
Assert.Single(dbContext.InstructionTabs);
}
[Fact]
public async Task Update_ReplacesFields()
{
using var dbContext = InMemoryDbContextFactory.Create();
var tab = InstructionTab.Create("Старое", "старый текст", 10);
dbContext.InstructionTabs.Add(tab);
await dbContext.SaveChangesAsync(CancellationToken.None);
var handler = new UpdateInstructionTabCommandHandler(dbContext);
var result = await handler.Handle(
new UpdateInstructionTabCommand(tab.Id, "Новое", "новый текст", 20),
CancellationToken.None
);
Assert.True(result.IsSuccess);
Assert.Equal("Новое", result.Value.Title);
Assert.Equal("новый текст", result.Value.Body);
Assert.Equal(20, result.Value.SortOrder);
}
[Fact]
public async Task Update_WhenTabMissing_ReturnsNotFound()
{
using var dbContext = InMemoryDbContextFactory.Create();
var handler = new UpdateInstructionTabCommandHandler(dbContext);
var result = await handler.Handle(
new UpdateInstructionTabCommand(Guid.NewGuid(), "Новое", "текст", 10),
CancellationToken.None
);
Assert.False(result.IsSuccess);
Assert.Equal(InstructionErrors.TabNotFound, result.Error);
}
[Fact]
public async Task Delete_RemovesTab()
{
using var dbContext = InMemoryDbContextFactory.Create();
var tab = InstructionTab.Create("Удалить меня", "текст", 10);
dbContext.InstructionTabs.Add(tab);
await dbContext.SaveChangesAsync(CancellationToken.None);
var handler = new DeleteInstructionTabCommandHandler(dbContext);
var result = await handler.Handle(
new DeleteInstructionTabCommand(tab.Id),
CancellationToken.None
);
await dbContext.SaveChangesAsync(CancellationToken.None);
Assert.True(result.IsSuccess);
Assert.Empty(dbContext.InstructionTabs);
}
[Fact]
public async Task Delete_WhenTabMissing_ReturnsNotFound()
{
using var dbContext = InMemoryDbContextFactory.Create();
var handler = new DeleteInstructionTabCommandHandler(dbContext);
var result = await handler.Handle(
new DeleteInstructionTabCommand(Guid.NewGuid()),
CancellationToken.None
);
Assert.False(result.IsSuccess);
Assert.Equal(InstructionErrors.TabNotFound, result.Error);
}
}