Skip to content

Commit

Permalink
fix: VerticalScrollValue and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vatsashah45 committed Oct 14, 2024
1 parent fc2af3b commit 073320d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
60 changes: 55 additions & 5 deletions src/Uno.Toolkit.RuntimeTests/Tests/ZoomContentControlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public async Task When_ZoomOut_ShouldDecreaseZoomLevel()

SUT.ZoomLevel -= 0.5;
SUT.ZoomLevel.Should().Be(2.5);

// should be coerce back to MinZoomLevel of 1
SUT.ZoomLevel = 0.5;
SUT.ZoomLevel.Should().Be(1.0);
Expand Down Expand Up @@ -139,8 +139,59 @@ public async Task When_ContentBounds_ShouldHideScrollBars()
SUT.IsVerticalScrollBarVisible.Should().BeTrue();
}

// FindFirstDescendent is not available in UWP
#if !IS_UWP
[TestMethod]
public async Task When_VerticalOffset_ShouldUpdateCorrectly()
{
var SUT = new ZoomContentControl()
{
Width = 400,
Height = 300,
VerticalOffset = 50,
IsPanAllowed = true,
};

await UnitTestUIContentHelperEx.SetContentAndWait(SUT);

// Set vertical offset
SUT.VerticalOffset = 100;
SUT.VerticalOffset.Should().Be(100);

// Verify the content is scrolled correctly
var presenter = SUT.FindFirstDescendant<ContentPresenter>("PART_Presenter");
var translation = (presenter?.RenderTransform as TransformGroup)?.Children[1] as TranslateTransform
?? throw new Exception("Failed to find PART_Presenter's TranslateTransform");

translation.Y.Should().Be(100); // Verify that the content's Y translation is in sync with the vertical offset
}

[TestMethod]
public async Task When_VerticalOffset_ExceedsLimits_ShouldShowScrollBars()
{
var SUT = new ZoomContentControl()
{
Width = 400,
Height = 300,
VerticalOffset = 0,
IsPanAllowed = true,
IsVerticalScrollBarVisible = true,
Content = new Border
{
Width = 400 - 20, // Smaller content width
Height = 500, // Larger content height
Background = new SolidColorBrush(Colors.Blue),
}
};

await UnitTestUIContentHelperEx.SetContentAndWait(SUT);

// Simulate setting a large VerticalOffset
SUT.VerticalOffset = 200;
SUT.VerticalOffset.Should().Be(200);

// Ensure scrollbar is shown when the content exceeds the bounds
SUT.IsVerticalScrollBarVisible.Should().BeTrue();
}

[TestMethod]
public async Task When_Pan_ShouldUpdateOffsets()
{
Expand All @@ -156,7 +207,7 @@ public async Task When_Pan_ShouldUpdateOffsets()

await UnitTestUIContentHelperEx.SetContentAndWait(SUT);

var presenter = SUT.FindFirstDescendant<ContentPresenter>("PART_Presenter");
var presenter = SUT.GetFirstDescendant<ContentPresenter>(x => x.Name == "PART_Presenter");
var translation = (presenter?.RenderTransform as TransformGroup)?.Children[1] as TranslateTransform
?? throw new Exception("Failed to find PART_Presenter's TranslateTransform");

Expand All @@ -168,6 +219,5 @@ public async Task When_Pan_ShouldUpdateOffsets()
translation.X.Should().Be(50);
translation.Y.Should().Be(50);
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
SmallChange="1"
Visibility="{TemplateBinding IsVerticalScrollBarVisible}"
ViewportSize="{TemplateBinding ViewportHeight}"
Value="{TemplateBinding VerticalScrollValue}" />
Value="{TemplateBinding VerticalOffset}" />
<!-- Horizontal ScrollBar -->
<ScrollBar x:Name="PART_ScrollH"
Grid.Row="1"
Expand Down

0 comments on commit 073320d

Please sign in to comment.