Skip to content

Commit 2a9be57

Browse files
committed
feat: add DesignTokensTests to validate tokens.css presence and content for ShellDocs.Tokens project
1 parent 0a80753 commit 2a9be57

3 files changed

Lines changed: 85 additions & 0 deletions

File tree

shelldocs.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<Project Path="src/ShellDocs.Core/ShellDocs.Core.csproj" />
99
<Project Path="src/ShellDocs.Markdown/ShellDocs.Markdown.csproj" />
1010
<Project Path="src/ShellDocs.Templates/ShellDocs.Templates.csproj" />
11+
<Project Path="src/ShellDocs.Tokens/ShellDocs.Tokens.csproj" />
1112
</Folder>
1213
<Folder Name="/tests/">
1314
<Project Path="tests/ShellDocs.Tests/ShellDocs.Tests.csproj" />
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System.Reflection;
2+
using Xunit;
3+
4+
namespace ShellDocs.Tests;
5+
6+
/* The Tokens RCL ships one static asset: tokens.css. If anyone renames the
7+
file, changes the package id, or accidentally drops the file from the
8+
build, these tests fail loud before it hits a consumer. */
9+
public class DesignTokensTests
10+
{
11+
private static string LoadTokensCss()
12+
{
13+
// MSBuild copies the RCL's static web assets into a predictable location
14+
// under the test project's output. Walk up from the test assembly to find
15+
// the package's wwwroot/tokens.css.
16+
var testAssembly = Assembly.GetExecutingAssembly().Location;
17+
var testDir = Path.GetDirectoryName(testAssembly)!;
18+
19+
// Traverse the well-known static-web-asset path emitted by the Razor SDK.
20+
var candidates = new[]
21+
{
22+
Path.Combine(testDir, "wwwroot", "_content", "ShellDocs.Tokens", "tokens.css"),
23+
Path.Combine(testDir, "..", "..", "..", "..", "..", "src", "ShellDocs.Tokens", "wwwroot", "tokens.css")
24+
};
25+
foreach (var c in candidates)
26+
{
27+
var full = Path.GetFullPath(c);
28+
if (File.Exists(full)) return File.ReadAllText(full);
29+
}
30+
throw new FileNotFoundException(
31+
$"tokens.css not found — checked: {string.Join(", ", candidates.Select(Path.GetFullPath))}");
32+
}
33+
34+
[Fact]
35+
public void TokensFile_Exists_AndIsNonEmpty()
36+
{
37+
var css = LoadTokensCss();
38+
Assert.NotEmpty(css);
39+
Assert.True(css.Length > 500, "tokens.css looks unexpectedly small");
40+
}
41+
42+
[Theory]
43+
[InlineData("--background")]
44+
[InlineData("--foreground")]
45+
[InlineData("--primary")]
46+
[InlineData("--muted")]
47+
[InlineData("--accent")]
48+
[InlineData("--border")]
49+
[InlineData("--radius")]
50+
[InlineData("--sidebar-width")]
51+
[InlineData("--header-height")]
52+
[InlineData("--font-sans")]
53+
[InlineData("--font-mono")]
54+
[InlineData("--info")]
55+
[InlineData("--warning")]
56+
[InlineData("--error")]
57+
[InlineData("--success")]
58+
public void TokensFile_DefinesStableToken(string token)
59+
{
60+
var css = LoadTokensCss();
61+
Assert.Contains(token + ":", css);
62+
}
63+
64+
[Fact]
65+
public void TokensFile_DefinesLightAndDarkRoots()
66+
{
67+
var css = LoadTokensCss();
68+
Assert.Contains(":root {", css);
69+
Assert.Contains(":root.dark {", css);
70+
}
71+
72+
[Fact]
73+
public void TokensFile_DarkRoot_OverridesBackground()
74+
{
75+
// Both blocks must redefine --background so the .dark class actually flips it.
76+
var css = LoadTokensCss();
77+
var darkStart = css.IndexOf(":root.dark {", StringComparison.Ordinal);
78+
Assert.True(darkStart > 0);
79+
var darkBlock = css.Substring(darkStart);
80+
Assert.Contains("--background:", darkBlock);
81+
Assert.Contains("--foreground:", darkBlock);
82+
}
83+
}

tests/ShellDocs.Tests/ShellDocs.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<ProjectReference Include="..\..\src\ShellDocs.Markdown\ShellDocs.Markdown.csproj" />
1111
<ProjectReference Include="..\..\src\ShellDocs.Components\ShellDocs.Components.csproj" />
1212
<ProjectReference Include="..\..\src\ShellDocs.Templates\ShellDocs.Templates.csproj" />
13+
<ProjectReference Include="..\..\src\ShellDocs.Tokens\ShellDocs.Tokens.csproj" />
1314
</ItemGroup>
1415

1516
<ItemGroup>

0 commit comments

Comments
 (0)