-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAutoScrollTrackerTests.cs
More file actions
49 lines (38 loc) · 1.85 KB
/
Copy pathAutoScrollTrackerTests.cs
File metadata and controls
49 lines (38 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using PostCodeSerialMonitor.Utils;
using Xunit;
namespace PostCodeSerialMonitor.Tests;
public class AutoScrollTrackerTests
{
[Fact]
public void OnScrollChanged_ContentGrowsFasterThanScrollToEndCanCatchUp_StaysAutoScrolled()
{
var tracker = new AutoScrollTracker();
// Simulates a burst of fast-arriving log lines: ScrollToEnd() was called while the
// extent was still 104 (viewport 50), setting the offset to 54. Before that resulting
// ScrollChanged is processed, more lines already grew the extent further to 130. The
// offset only ever moved forward, so this is not the user scrolling away.
tracker.OnScrollChanged(offsetY: 54, extentHeight: 130, viewportHeight: 50);
Assert.True(tracker.AutoScroll);
}
[Fact]
public void OnScrollChanged_UserDragsScrollbarUp_Detaches()
{
var tracker = new AutoScrollTracker();
tracker.OnScrollChanged(offsetY: 76, extentHeight: 130, viewportHeight: 50); // starts at bottom
// The offset moves backward - only a manual scrollbar drag does that.
tracker.OnScrollChanged(offsetY: 20, extentHeight: 130, viewportHeight: 50);
Assert.False(tracker.AutoScroll);
}
[Fact]
public void OnScrollChanged_UserDragsAwayAfterSustainedAutoScrolling_StillDetaches()
{
var tracker = new AutoScrollTracker();
// Content keeps growing, offset keeps chasing it forward - auto-scroll stays engaged.
tracker.OnScrollChanged(offsetY: 50, extentHeight: 104, viewportHeight: 50);
tracker.OnScrollChanged(offsetY: 76, extentHeight: 130, viewportHeight: 50);
Assert.True(tracker.AutoScroll);
// The user then grabs the scrollbar and drags it up.
tracker.OnScrollChanged(offsetY: 20, extentHeight: 130, viewportHeight: 50);
Assert.False(tracker.AutoScroll);
}
}