Skip to content

Commit 71588ee

Browse files
andreakarashoclaude
andcommitted
Fix 7 failing click tests — clicks fire on mouse release, not press
The Click fixture helper and manual test frames only ran press-down without a subsequent release frame. ShouldProcessClick checks IsMouseJustReleased, so a third frame with mouseDown=false is needed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b10412f commit 71588ee

3 files changed

Lines changed: 40 additions & 23 deletions

File tree

src/Clay.Test/ClayUIFixture.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,20 @@ public ReadOnlySpan<RenderCommand> RunTwoFrames(
6262
}
6363

6464
/// <summary>
65-
/// Simulates a click: runs frame 1 (no press), frame 2 (press down), returns frame 2 commands.
65+
/// Simulates a click: runs frame 1 (establish bounds), frame 2 (press down),
66+
/// frame 3 (release — triggers click). Returns frame 3 commands.
6667
/// The buildUi action can capture return values via closures.
6768
/// </summary>
6869
public ReadOnlySpan<RenderCommand> Click(Action buildUi, Vector2 mousePos)
6970
{
70-
return RunTwoFrames(buildUi, mousePos, mouseDown: true);
71+
// Frame 1: establish bounding boxes (no interaction)
72+
RunFrame(buildUi, mousePos, mouseDown: false);
73+
74+
// Frame 2: press down
75+
RunFrame(buildUi, mousePos, mouseDown: true);
76+
77+
// Frame 3: release — ShouldProcessClick fires on mouse release
78+
return RunFrame(buildUi, mousePos, mouseDown: false);
7179
}
7280

7381
public void Dispose()

src/Clay.Test/ClayUIListBoxComboTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,21 @@ public void ListBoxItem_NotClicked_ReturnsFalse()
5959
public void ListBoxItem_Clicked_ReturnsTrue()
6060
{
6161
bool clicked = false;
62-
// First frame: establish layout
63-
_fixture.RunFrame(() =>
64-
{
65-
ClayUI.BeginListBox("ClickList2");
66-
ClayUI.ListBoxItem("Item A##cl2_a", isSelected: false);
67-
ClayUI.EndListBox();
68-
});
69-
70-
// Second frame: click on the item area (top-left region)
71-
_fixture.RunFrame(() =>
62+
Action buildUi = () =>
7263
{
7364
ClayUI.BeginListBox("ClickList2");
7465
clicked = ClayUI.ListBoxItem("Item A##cl2_a", isSelected: false);
7566
ClayUI.EndListBox();
76-
}, mousePos: new Vector2(30, 30), mouseDown: true);
67+
};
68+
69+
// Frame 1: establish layout
70+
_fixture.RunFrame(buildUi);
71+
72+
// Frame 2: press down on the item
73+
_fixture.RunFrame(buildUi, mousePos: new Vector2(30, 30), mouseDown: true);
74+
75+
// Frame 3: release — click fires on mouse release
76+
_fixture.RunFrame(buildUi, mousePos: new Vector2(30, 30), mouseDown: false);
7777

7878
Assert.True(clicked);
7979
}

src/Clay.Test/ClayUITreeNodeTests.cs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,29 +89,38 @@ public void BeginTreeNode_Expanded_GeneratesChildContent()
8989
[Fact]
9090
public void TreeNode_Click_TogglesExpanded()
9191
{
92-
bool expandedFrame2 = false;
92+
bool expandedFrame3 = false;
9393

94-
// Frame 1: node is collapsed (default)
95-
_fixture.RunFrame(() =>
94+
Action buildUi = () =>
9695
{
9796
var expanded = ClayUI.BeginTreeNode("Toggle Node");
98-
if (expanded) ClayUI.EndTreeNode();
99-
});
97+
if (expanded)
98+
{
99+
ClayUI.Label("Now visible");
100+
ClayUI.EndTreeNode();
101+
}
102+
};
103+
104+
// Frame 1: establish bounding boxes (collapsed, no interaction)
105+
_fixture.RunFrame(buildUi);
106+
107+
// Frame 2: press down on the node header
108+
_fixture.RunFrame(buildUi, mousePos: new Vector2(30, 5), mouseDown: true);
100109

101-
// Frame 2: click on the node header to expand it
110+
// Frame 3: release — click fires on mouse release
102111
_fixture.RunFrame(() =>
103112
{
104-
expandedFrame2 = ClayUI.BeginTreeNode("Toggle Node");
105-
if (expandedFrame2)
113+
expandedFrame3 = ClayUI.BeginTreeNode("Toggle Node");
114+
if (expandedFrame3)
106115
{
107116
ClayUI.Label("Now visible");
108117
ClayUI.EndTreeNode();
109118
}
110119
},
111120
mousePos: new Vector2(30, 5),
112-
mouseDown: true);
121+
mouseDown: false);
113122

114-
Assert.True(expandedFrame2, "Clicking tree node header should expand it");
123+
Assert.True(expandedFrame3, "Clicking tree node header should expand it");
115124
}
116125

117126
[Fact]

0 commit comments

Comments
 (0)