mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-25 23:18:56 -07:00
72 lines
3.2 KiB
C#
72 lines
3.2 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using RadicadeServer.CDN.Config;
|
|
using RadicadeServer.DB;
|
|
using RadicadeServer.RecNet.Config;
|
|
using RadicadeServer.Utils;
|
|
using Xunit;
|
|
|
|
namespace RadicadeServer.Tests;
|
|
|
|
public class LoadingScreenTipTests
|
|
{
|
|
[Theory]
|
|
[InlineData("radicade", "yum", "Welcome to Radicade")]
|
|
[InlineData("Custom welcome", "Custom message", "Custom welcome")]
|
|
public void ReplacesOnlyLegacyPlaceholder(string title, string message, string expectedTitle)
|
|
{
|
|
using var db = new RecDBContext(TestDbOptions.Create()
|
|
.UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);
|
|
db.ServerConfig.Add(new ServerConfigVal("LoadingScreenTipData",
|
|
System.Text.Json.JsonSerializer.Serialize(new[] { new { Title = title, Message = message } })));
|
|
db.SaveChanges();
|
|
|
|
// The old single, image-less tip's wording is carried onto the first official image; the
|
|
// "radicade"/"yum" placeholder is not worth carrying, so that one keeps the default text.
|
|
// The default is read from the catalog rather than repeated here, so rewording a tip
|
|
// (which is a copy decision, not a behaviour one) does not fail this test.
|
|
var tips = new CDNConfigAPI(db).GetLoadingScreenTipData()!;
|
|
var tip = tips[0];
|
|
Assert.Equal(expectedTitle, tip.Title);
|
|
Assert.Equal(title == "radicade" ? LoadingScreenImages.Tips[0].Message : message, tip.Message);
|
|
}
|
|
|
|
[Fact]
|
|
public void CyclesThroughTheOfficialImagesOnly()
|
|
{
|
|
using var db = new RecDBContext(TestDbOptions.Create()
|
|
.UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);
|
|
db.ServerConfig.Add(new ServerConfigVal("LoadingScreenTipData",
|
|
System.Text.Json.JsonSerializer.Serialize(new[] { new { Title = "Custom welcome", Message = "Custom message", ImageName = "avatar-upload.png" } })));
|
|
db.SaveChanges();
|
|
|
|
var tips = new CDNConfigAPI(db).GetLoadingScreenTipData()!;
|
|
|
|
Assert.Equal(LoadingScreenImages.Names, tips.Select(t => t.ImageName));
|
|
Assert.All(tips, t => Assert.False(string.IsNullOrWhiteSpace(t.Title)));
|
|
Assert.All(tips, t => Assert.False(string.IsNullOrWhiteSpace(t.Message)));
|
|
}
|
|
|
|
[Fact]
|
|
public void ReusesAnAdministratorsTextForItsImage()
|
|
{
|
|
using var db = new RecDBContext(TestDbOptions.Create()
|
|
.UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);
|
|
db.ServerConfig.Add(new ServerConfigVal("LoadingScreenTipData",
|
|
System.Text.Json.JsonSerializer.Serialize(new[] { new { Title = "Our rules", Message = "Be nice.", ImageName = "Star.png" } })));
|
|
db.SaveChanges();
|
|
|
|
var star = new CDNConfigAPI(db).GetLoadingScreenTipData()!.First(t => t.ImageName == "Star.png");
|
|
|
|
Assert.Equal("Our rules", star.Title);
|
|
Assert.Equal("Be nice.", star.Message);
|
|
}
|
|
|
|
[Fact]
|
|
public void NewDatabaseSeedHasWelcomeText()
|
|
{
|
|
using var json = System.Text.Json.JsonDocument.Parse(FirstTimeUtils.LoadingScreen);
|
|
Assert.Equal("Welcome to Radicade", json.RootElement[0].GetProperty("Title").GetString());
|
|
Assert.DoesNotContain("yum", json.RootElement[0].GetProperty("Message").GetString()!);
|
|
}
|
|
}
|