Skip to content

Commit aff78a0

Browse files
committed
feat(button): loglevel before testing changes
1 parent c776593 commit aff78a0

File tree

15 files changed

+210
-29
lines changed

15 files changed

+210
-29
lines changed

.github/workflows/reuseable-ci-checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ jobs:
443443
E2ETracingEnabled: ${{ env.E2E_TRACING_ENABLED }}
444444
HeadlessTesting: ${{ env.HEADLESS_TESTING }}
445445
run: |
446-
dotnet test --collect:"XPlat Code Coverage" --settings coverlet.runsettings
446+
dotnet test --collect "XPlat Code Coverage" --settings "coverlet.runsettings"
447447
continue-on-error: true
448448

449449
- name: Generate Coverage Report

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
88

99
<!-- coverlet.msbuild, specifically msbuild props -->
10-
<CollectCoverage>true</CollectCoverage>
10+
<CollectCoverage>false</CollectCoverage>
1111
<CoverletOutputFormat>cobertura</CoverletOutputFormat>
1212
<Threshold>8</Threshold>
1313
<ThresholdType>line</ThresholdType>

TELBlazor.Components.ShowCase.E2ETests/Pages/BaseComponentPages/TELButtonPageTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ await browserContext.Tracing.StartAsync(new()
5858

5959
IPage page = await browserContext.NewPageAsync();
6060

61-
await page.GotoOnceNetworkIsIdleAsync("TELButtonPage");
61+
await page.GotoOnceNetworkIsIdleAsync("TELButton");
6262
ILocator button = page.GetByRole(AriaRole.Button, new() { Name = "Click Counter" });
6363

6464
AxeResult axeResults = await button.RunAxe();
@@ -134,7 +134,7 @@ await browserContext.Tracing.StartAsync(new()
134134
//Debug option
135135
//await page.PauseAsync();
136136

137-
await page.GotoOnceNetworkIsIdleAsync("TELButtonPage");
137+
await page.GotoOnceNetworkIsIdleAsync("TELButton");
138138
ILocator button = page.GetByRole(AriaRole.Button, new() { Name = "Click Counter" });
139139

140140
await Expect(button).ToContainTextAsync("Button pressed 0 times");

TELBlazor.Components.ShowCase.Shared/Layouts/ComponentLayouts/ComponentNavMenu.razor

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
<li class="app-side-nav__item"><NavLink class="app-side-nav__link" href="CssSourceCheckerPage">CssSourceCheckerPage</NavLink></li>
66
<li class="app-side-nav__item"><NavLink class="app-side-nav__link" href="TELButtonPage">TELButtonPage</NavLink></li> *@
77
<li class="app-side-nav__item"><a class="app-side-nav__link" href="/">Home</a></li>
8-
<li class="app-side-nav__item"><a class="app-side-nav__link" href="CssSourceChecker">CssSourceChecker</a></li>
98
<li class="app-side-nav__item"><a class="app-side-nav__link" href="TELButton">TELButton</a></li>
109
</ul>
10+
<h2 class="app-side-nav__heading">Test Components</h2>
11+
<ul class="nhsuk-list app-side-nav__list">
12+
<li class="app-side-nav__item"><a class="app-side-nav__link" href="LogLevelSwitcher">LogLevelSwitcher</a></li>
13+
<li class="app-side-nav__item"><a class="app-side-nav__link" href="CssSourceChecker">CssSourceChecker</a></li>
14+
</ul>
1115
</nav>
1216

TELBlazor.Components.ShowCase.Shared/Layouts/ComponentLayouts/ShowCase.razor

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,41 @@
11
@layout ComponentPageLayout
22
<div class="component-showcase">
3+
@if(IsTestComponent){
4+
<h1 class="test-component-warning-header">This is a Test Component</h1>
5+
<p>Test components are components not for production but to aid testing. Or to demo a feature not planned for prodution.</p>
6+
<p>Test components do not have test coverage and are not for production.</p>
7+
}
8+
39
<h2>@Title</h2>
410
<TELBlazorPackageVersionInformation />
511
<div class="component-presentor">
612
@ChildContent
713
</div>
8-
<div class="component-description">
14+
<div class="component-information">
15+
<h2>Instructions</h2>
16+
<p>@Instructions</p>
17+
</div>
18+
<div class="component-information">
919
<h2>Description</h2>
1020
<p>@Description</p>
1121
</div>
22+
1223
</div>
1324
@code
1425
{
26+
27+
[Parameter, EditorRequired]
28+
public required bool IsTestComponent { get; set; } = false;
29+
1530
[Parameter, EditorRequired]
1631
public required string Title { get; set; } = string.Empty;
1732

1833
[Parameter,EditorRequired]
1934
public required string Description { get; set; } = string.Empty;
2035

36+
[Parameter, EditorRequired]
37+
public required string Instructions { get; set; } = string.Empty;
38+
2139
[Parameter, EditorRequired]
2240
public required RenderFragment ChildContent { get; set; }
2341
}

TELBlazor.Components.ShowCase.Shared/Layouts/ComponentLayouts/ShowCase.razor.css

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
.component-showcase {
1+
.test-component-warning-header {
2+
color:red;
3+
}
4+
.component-showcase {
25
padding: 1.5rem;
36
margin-bottom: 2rem;
4-
border: 1px solid #e5e7eb;
7+
border: 1px solid #e5e7eb;
58
border-radius: 0.75rem;
69
background-color: #ffffff;
710
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
@@ -22,7 +25,7 @@
2225
margin-bottom: 1rem;
2326
}
2427

25-
.component-description {
28+
.component-information {
2629
font-size: 0.95rem;
2730
color: #4b5563;
2831
line-height: 1.6;

TELBlazor.Components.ShowCase.Shared/Pages/ComponentPages/BaseComponentPages/TELButtonPage.razor

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
@page "/TELButton/"
22
<PageTitle>@Title</PageTitle>
3-
<ShowCase Title="@Title" Description="@Description">
3+
<ShowCase Title="@Title" Instructions="@Instructions" Description="@Description" IsTestComponent="@IsTestComponent">
44

55
<TELButton IsSubmitButtonForEditForm=false
6-
NoJSActionUrl="nojsfallback/mvcendpoint/telbuttonshowcase"
7-
FormData="@(new Dictionary<string, string>{{"increment","1"}})"
8-
OnClick="IncrementCount"
9-
ButtonStyle="TELButtonStyle.Warning"
10-
PreventDoubleClick=false
11-
ButtonText="@ButtonText"
12-
AdditionalCssClasses=""
13-
AriaLabel="Click Counter"
14-
AssistiveText="Click to increase the number"
15-
TabIndex="0"
16-
ToolTipTitle="Click to increment" />
6+
NoJSActionUrl="nojsfallback/mvcendpoint/telbuttonshowcase"
7+
FormData="@(new Dictionary<string, string>{{"increment","1"}})"
8+
OnClick="IncrementCount"
9+
ButtonStyle="TELButtonStyle.Warning"
10+
PreventDoubleClick=false
11+
ButtonText="@ButtonText"
12+
AdditionalCssClasses=""
13+
AriaLabel="Click Counter"
14+
AssistiveText="Click to increase the number"
15+
TabIndex="0"
16+
ToolTipTitle="Click to increment" />
1717

1818
</ShowCase>
1919

2020
@code {
21+
private bool IsTestComponent => false;
22+
private string Instructions => "The button has been given a simple event to increment its text. Click the button.";
2123
private int currentCount = 0;
2224
public string ButtonText => $"Button pressed {currentCount} times";
2325
private void IncrementCount()
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
@page "/CssSourceChecker/"
22
<PageTitle>@Title</PageTitle>
3-
<ShowCase Title="@Title" Description="@Description">
3+
<ShowCase Title="@Title" Instructions="@Instructions" Description="@Description" IsTestComponent=@IsTestComponent>
44
<CssSourceChecker/>
55
</ShowCase>
66

77
@code {
8-
8+
private bool IsTestComponent => true;
99
private string Title => "CssSourceChecker";
10+
private string Instructions => "This element just shows css";
1011
private string Description => "Just a test elements";
1112
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@page "/LogLevelSwitcher/"
2+
<PageTitle>@Title</PageTitle>
3+
<ShowCase Title="@Title" Instructions="@Instructions" Description="@Description" IsTestComponent="@IsTestComponent">
4+
<LogLevelSwitcher />
5+
</ShowCase>
6+
7+
@code {
8+
private bool IsTestComponent => true;
9+
private string Title => "LogLevelSwitch";
10+
private string Instructions => "Open the console and change the log levels, view other components and see their logging change";
11+
private string Description => "This is a test component: Changing the log level does not trigger events because everything would need one so it will affect new components. Also we have complete tare down between mvc components so local storage for 24 hours or db user logging state would be needed the singleton will not be enough. For implementation into MVC see MVCBlazor project. In production the value of this would be being able to programmatically change the loglevel in a browser based on an event for example a recurring problem. Another potential use is giving an admin or console option so a user being supported with an error could increase logging, or staff reporting a bug could ensure they are creating logs whilst reporting a bug such that they could turn up logging, trigger an error, and share when they successfully repeated the error. Sometimes logging is used for analytics but specific analytics tools are better for this.or to change the loglevel for a user who is supported via a tool. So this component would be the starting point for easily changing loglevel live.";
12+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@inject ILogLevelSwitcherService LogLevelSwitcherService
2+
3+
<h3>Log Level Slider</h3>
4+
5+
6+
<select value="@CurrentLogLevel" @onchange="HandleLogLevelChange" class="form-select">
7+
@foreach (var item in AvailableLogLevels)
8+
{
9+
<option value="@item">@item</option>
10+
}
11+
</select>
12+
<p>Current Log Level: @CurrentLogLevel</p>
13+
14+
15+
16+
@code {
17+
private string CurrentLogLevel = string.Empty;
18+
19+
private List<string> AvailableLogLevels = new();
20+
21+
protected override async Task OnInitializedAsync()
22+
{
23+
await LogLevelSwitcherService.InitializeLogLevelFromAsyncSourceIfAvailable();
24+
AvailableLogLevels = LogLevelSwitcherService.GetAvailableLogLevels();
25+
CurrentLogLevel = LogLevelSwitcherService.GetCurrentLogLevel();
26+
}
27+
28+
private void SetLogLevel(string level)
29+
{
30+
CurrentLogLevel = LogLevelSwitcherService.SetLogLevel(level);
31+
// No StateHasChanged needed here. The component will re-render
32+
// when CurrentLogLevel is updated due to how Blazor change detection works.
33+
}
34+
35+
private void HandleLogLevelChange(ChangeEventArgs e)
36+
{
37+
if (e.Value is string selectedLevel) // Safe casting
38+
{
39+
CurrentLogLevel = e.Value.ToString();
40+
LogLevelSwitcherService.SetLogLevel(CurrentLogLevel); // Crucial: Update the service!
41+
StateHasChanged();
42+
}
43+
}
44+
45+
}
46+

0 commit comments

Comments
 (0)