Skip to content

Commit 6138be1

Browse files
Copilotdwarwick
andcommitted
Add scrolling to demo steps and improve test assertions
Co-authored-by: dwarwick <15970276+dwarwick@users.noreply.github.com>
1 parent d14e7f3 commit 6138be1

File tree

3 files changed

+61
-8
lines changed

3 files changed

+61
-8
lines changed

JwtIdentity.Client/Pages/Survey/BranchingSurveyEdit.razor

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ else
119119
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center" Class="mb-3">
120120
<MudText Typo="Typo.subtitle1" Class="font-weight-bold">Question Groups</MudText>
121121
<DemoBorder CurrentDemoStep="@DemoStep" StepsToShow="@(new List<int>() { 1, 5 })" IsButton="true">
122-
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="AddQuestionGroup" StartIcon="@Icons.Material.Filled.Add" Disabled="@IsAddGroupDisabled()">
122+
<MudButton id="AddGroupButton" Variant="Variant.Filled" Color="Color.Primary" OnClick="AddQuestionGroup" StartIcon="@Icons.Material.Filled.Add" Disabled="@IsAddGroupDisabled()">
123123
Add Group
124124
</MudButton>
125125
</DemoBorder>
@@ -136,7 +136,8 @@ else
136136
@foreach (var group in QuestionGroups.OrderBy(g => g.GroupNumber))
137137
{
138138
var colorClass = $"group-color-{group.GroupNumber % 10}";
139-
<MudExpansionPanel Class="mb-3">
139+
var panelId = $"Group{group.GroupNumber}Panel";
140+
<MudExpansionPanel id="@panelId" Class="mb-3">
140141
<TitleContent>
141142
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="2" Style="width: 100%;">
142143
<span class="@($"group-badge group-badge-{group.GroupNumber % 10}")">Group @group.GroupNumber</span>
@@ -157,7 +158,7 @@ else
157158
@if (group.GroupNumber == 1)
158159
{
159160
<DemoBorder CurrentDemoStep="@DemoStep" StepsToShow="@(new List<int>() { 2, 3 })">
160-
<MudTextField Label="Group Name" Value="@group.GroupName"
161+
<MudTextField id="Group1NameField" Label="Group Name" Value="@group.GroupName"
161162
Variant="Variant.Outlined"
162163
HelperText="Optional: Give this group a descriptive name"
163164
ReadOnly="@IsGroupNameReadOnly(group.GroupNumber)"
@@ -180,7 +181,7 @@ else
180181
else if (group.GroupNumber == 2)
181182
{
182183
<DemoBorder CurrentDemoStep="@DemoStep" StepsToShow="@(new List<int>() { 6, 7 })">
183-
<MudTextField Label="Group Name" Value="@group.GroupName"
184+
<MudTextField id="Group2NameField" Label="Group Name" Value="@group.GroupName"
184185
Variant="Variant.Outlined"
185186
HelperText="Optional: Give this group a descriptive name"
186187
ReadOnly="@IsGroupNameReadOnly(group.GroupNumber)"

JwtIdentity.Client/Pages/Survey/BranchingSurveyEdit.razor.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class BranchingSurveyEditModel : BlazorBase
1414
protected bool IsDemoUser { get; set; }
1515
protected int DemoStep { get; set; }
1616
protected string DemoType { get; set; }
17+
private int _previousDemoStep = -1;
1718
protected Origin AnchorOrigin { get; set; } = Origin.BottomRight;
1819
protected Origin TransformOrigin { get; set; } = Origin.TopLeft;
1920
protected bool ShowDemoStep(int step) => IsDemoUser && DemoType == "branching" && DemoStep == step;
@@ -62,6 +63,57 @@ protected override async Task OnInitializedAsync()
6263
BuildSyncfusionDiagram();
6364
}
6465

66+
protected override async Task OnAfterRenderAsync(bool firstRender)
67+
{
68+
if (firstRender)
69+
{
70+
var isMobile = await JSRuntime.InvokeAsync<bool>("isMobile");
71+
if (isMobile)
72+
{
73+
AnchorOrigin = Origin.BottomCenter;
74+
TransformOrigin = Origin.TopCenter;
75+
}
76+
StateHasChanged();
77+
}
78+
79+
// Scroll to the current demo step when it changes
80+
if (IsDemoUser && DemoStep != _previousDemoStep)
81+
{
82+
await ScrollToCurrentDemoStep();
83+
_previousDemoStep = DemoStep;
84+
}
85+
}
86+
87+
private async Task ScrollToCurrentDemoStep()
88+
{
89+
var id = DemoStep switch
90+
{
91+
1 => "AddGroupButton", // Step 1: Add first group
92+
2 => "Group1Panel", // Step 2: Group 1 created, ready to name
93+
3 => "Group1NameField", // Step 3: Name Group 1
94+
5 => "AddGroupButton", // Step 5: Add second group
95+
6 => "Group2Panel", // Step 6: Group 2 created, ready to name
96+
7 => "Group2NameField", // Step 7: Name Group 2
97+
9 => "QuestionGroupSelector_Q3", // Step 9: Move Q3 to Group 1
98+
11 => "QuestionGroupSelector_Q4", // Step 11: Move Q4 to Group 2
99+
13 => "BranchingSelector_Q1", // Step 13: Configure Q1 branching
100+
15 => "BranchingSelector_Q2", // Step 15: Configure Q2 branching
101+
_ => null
102+
};
103+
104+
if (!string.IsNullOrEmpty(id))
105+
{
106+
await JSRuntime.InvokeVoidAsync(
107+
"scrollToElement",
108+
id,
109+
new { behavior = "smooth", block = "center", headerOffset = 0 }
110+
);
111+
112+
// Ensure any demo popover tied to the element renders after the scroll
113+
StateHasChanged();
114+
}
115+
}
116+
65117
protected void DiagramCreated()
66118
{
67119
FitOptions options = new FitOptions() { Mode = FitMode.Both, Region = DiagramRegion.Content };

bUnitTests/BranchingPageDemoTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@ public void BranchingPage_Step1_PromptsToAddFirstGroup()
188188
// Wait for loading to complete
189189
cut.WaitForState(() => cut.Markup.Contains("Add Group"), timeout: TimeSpan.FromSeconds(5));
190190

191-
// Assert - Prompt to add first group at step 1
191+
// Assert - At step 1, Add Group button should be present and enabled (has demo-primary-border class)
192192
Assert.That(cut.Markup, Does.Contain("Add Group"));
193+
Assert.That(cut.Markup, Does.Contain("demo-primary-border")); // Demo border shows it's the active step
193194
}
194195

195196
[Test]
@@ -219,10 +220,9 @@ public void BranchingPage_AddGroup_AdvancesToStep2()
219220
// Wait for loading
220221
cut.WaitForState(() => cut.Markup.Contains("Add Group"), timeout: TimeSpan.FromSeconds(5));
221222

222-
// Assert - Should have Add Group button
223+
// Assert - At step 1, Add Group button should be present with demo border
223224
Assert.That(cut.Markup, Does.Contain("Add Group"));
224-
// Verify component loaded successfully
225-
Assert.That(cut.Markup, Does.Contain("Survey Branching"));
225+
Assert.That(cut.Markup, Does.Contain("demo-primary-border")); // Demo border shows it's active
226226
}
227227

228228
[Test]

0 commit comments

Comments
 (0)