|
| 1 | +using Microsoft.Maui.Controls.Shapes; |
1 | 2 | using Syncfusion.Maui.Toolkit.BottomSheet;
|
| 3 | +using Syncfusion.Maui.Toolkit.Helper; |
2 | 4 | using Syncfusion.Maui.Toolkit.Internals;
|
3 | 5 | using System.Reflection;
|
4 | 6 |
|
@@ -514,6 +516,342 @@ public void OnHandleTouch_ShouldNotHandleWhenSwipingDisabled()
|
514 | 516 |
|
515 | 517 | #endregion
|
516 | 518 |
|
| 519 | + #region Private Methods |
| 520 | + |
| 521 | + [Fact] |
| 522 | + public void InitializeLayout() |
| 523 | + { |
| 524 | + InvokePrivateMethod(_bottomSheet, "InitializeLayout"); |
| 525 | + var bottomSheet = GetPrivateField(_bottomSheet, "_bottomSheet"); |
| 526 | + var overlayGrid = GetPrivateField(_bottomSheet, "_overlayGrid"); |
| 527 | + Assert.True(_bottomSheet.Children?.Contains(bottomSheet)); |
| 528 | + Assert.True(_bottomSheet.Children?.Contains(overlayGrid)); |
| 529 | + } |
| 530 | + |
| 531 | + [Fact] |
| 532 | + public void AddChild() |
| 533 | + { |
| 534 | + var verticalStackLayout = new VerticalStackLayout() |
| 535 | + { |
| 536 | + HorizontalOptions = LayoutOptions.Center, |
| 537 | + }; |
| 538 | + |
| 539 | + var label = new Label() |
| 540 | + { |
| 541 | + Text = "Bottom Sheet" |
| 542 | + }; |
| 543 | + |
| 544 | + verticalStackLayout.Children.Add(label); |
| 545 | + InvokePrivateMethod(_bottomSheet, "AddChild", [verticalStackLayout]); |
| 546 | + Assert.True(_bottomSheet.Children.Contains(verticalStackLayout)); |
| 547 | + } |
| 548 | + |
| 549 | + [Fact] |
| 550 | + public void InitializeOverlayGrid() |
| 551 | + { |
| 552 | + InvokePrivateMethod(_bottomSheet, "InitializeOverlayGrid"); |
| 553 | + Grid? overlayGrid = (Grid?)GetPrivateField(_bottomSheet, "_overlayGrid"); |
| 554 | + Assert.Equal(overlayGrid?.BackgroundColor, Color.FromArgb("#80000000")); |
| 555 | + Assert.Equal(overlayGrid?.Opacity, 0.5); |
| 556 | + Assert.Equal(overlayGrid?.IsVisible, false); |
| 557 | + } |
| 558 | + |
| 559 | + [Fact] |
| 560 | + public void InitializeGrabber() |
| 561 | + { |
| 562 | + InvokePrivateMethod(_bottomSheet, "InitializeGrabber"); |
| 563 | + Border? grabber = (Border?)GetPrivateField(_bottomSheet, "_grabber"); |
| 564 | + RoundRectangle? grabberStrokeShape = (RoundRectangle?)GetPrivateField(_bottomSheet, "_grabberStrokeShape"); |
| 565 | + Assert.Equal(grabber?.StrokeShape, grabberStrokeShape); |
| 566 | + } |
| 567 | + |
| 568 | + [Fact] |
| 569 | + public void InitializeContentBorder() |
| 570 | + { |
| 571 | + InvokePrivateMethod(_bottomSheet, "InitializeContentBorder"); |
| 572 | + Border? contentBorder = (Border?)GetPrivateField(_bottomSheet, "_contentBorder"); |
| 573 | + Assert.NotNull(contentBorder); |
| 574 | + } |
| 575 | + |
| 576 | + [Theory] |
| 577 | + [InlineData(0.5, 0.5)] |
| 578 | + [InlineData(0, 0.1)] |
| 579 | + [InlineData(-0.5, 0.1)] |
| 580 | + public void UpdateHalfExpandedRatioProperty(double value, double expectedValue) |
| 581 | + { |
| 582 | + InvokePrivateMethod(_bottomSheet, "UpdateHalfExpandedRatioProperty", [value]); |
| 583 | + double result = _bottomSheet.HalfExpandedRatio; |
| 584 | + Assert.Equal(expectedValue, result); |
| 585 | + } |
| 586 | + |
| 587 | + [Theory] |
| 588 | + [InlineData(0.8, 0.8)] |
| 589 | + [InlineData(0, 0.1)] |
| 590 | + [InlineData(-0.5, 0.1)] |
| 591 | + public void UpdateFullExpandedRatioProperty(double value, double expectedValue) |
| 592 | + { |
| 593 | + InvokePrivateMethod(_bottomSheet, "UpdateFullExpandedRatioProperty", [value]); |
| 594 | + double result = _bottomSheet.FullExpandedRatio; |
| 595 | + Assert.Equal(expectedValue, result); |
| 596 | + } |
| 597 | + |
| 598 | + [Fact] |
| 599 | + public void SetBottomSheetContent() |
| 600 | + { |
| 601 | + var verticalStackLayout = new VerticalStackLayout() |
| 602 | + { |
| 603 | + HorizontalOptions = LayoutOptions.Center, |
| 604 | + }; |
| 605 | + |
| 606 | + var label = new Label() |
| 607 | + { |
| 608 | + Text = "Bottom Sheet" |
| 609 | + }; |
| 610 | + |
| 611 | + verticalStackLayout.Children.Add(label); |
| 612 | + InvokePrivateMethod(_bottomSheet, "SetBottomSheetContent", [verticalStackLayout]); |
| 613 | + SfGrid? grid = (SfGrid?)GetPrivateField(_bottomSheet, "_bottomSheetContent"); |
| 614 | + SfBorder? content = (SfBorder?)GetPrivateField(_bottomSheet, "_contentBorder"); |
| 615 | + Assert.NotNull(content); |
| 616 | + Assert.True(grid?.Children.Contains(content)); |
| 617 | + } |
| 618 | + |
| 619 | + [Fact] |
| 620 | + public void UpdateState_HalfExpanded() |
| 621 | + { |
| 622 | + SetPrivateField(_bottomSheet, "_isSheetOpen", true); |
| 623 | + _bottomSheet.State = BottomSheetState.HalfExpanded; |
| 624 | + var isHalfExpanded = GetPrivateField(_bottomSheet, "_isHalfExpanded"); |
| 625 | + Assert.Equal(BottomSheetState.HalfExpanded, _bottomSheet.State); |
| 626 | + Assert.True((bool?)isHalfExpanded); |
| 627 | + } |
| 628 | + |
| 629 | + [Fact] |
| 630 | + public void UpdateState_FullExpanded() |
| 631 | + { |
| 632 | + SetPrivateField(_bottomSheet, "_isSheetOpen", true); |
| 633 | + _bottomSheet.State = BottomSheetState.Hidden; |
| 634 | + _bottomSheet.AllowedState = BottomSheetAllowedState.FullExpanded; |
| 635 | + var isHalfExpanded = GetPrivateField(_bottomSheet, "_isHalfExpanded"); |
| 636 | + Assert.Equal(BottomSheetState.FullExpanded, _bottomSheet.State); |
| 637 | + Assert.False((bool?)isHalfExpanded); |
| 638 | + } |
| 639 | + |
| 640 | + [Fact] |
| 641 | + public void UpdateState() |
| 642 | + { |
| 643 | + _bottomSheet.State = BottomSheetState.Hidden; |
| 644 | + SetPrivateField(_bottomSheet, "_isSheetOpen", false); |
| 645 | + _bottomSheet.AllowedState = BottomSheetAllowedState.HalfExpanded; |
| 646 | + var isHalfState = GetPrivateField(_bottomSheet, "_isHalfExpanded"); |
| 647 | + Assert.Equal(BottomSheetState.Hidden, _bottomSheet.State); |
| 648 | + } |
| 649 | + |
| 650 | + [Fact] |
| 651 | + public void UpdateBottomSheetBackground() |
| 652 | + { |
| 653 | + var grid = new SfGrid(); |
| 654 | + Brush brush = new SolidColorBrush(Colors.Red); |
| 655 | + SetPrivateField(_bottomSheet, "_bottomSheetContent", grid); |
| 656 | + InvokePrivateMethod(_bottomSheet, "UpdateBottomSheetBackground", [brush]); |
| 657 | + View? content = (View?)GetPrivateField(_bottomSheet, "_bottomSheetContent"); |
| 658 | + Assert.Equal(brush, content?.Background); |
| 659 | + } |
| 660 | + |
| 661 | + [Fact] |
| 662 | + public void UpdateGrabberBackground() |
| 663 | + { |
| 664 | + SfBorder border = new SfBorder(); |
| 665 | + Brush brush = new SolidColorBrush(Colors.Red); |
| 666 | + SetPrivateField(_bottomSheet, "_grabber", border); |
| 667 | + InvokePrivateMethod(_bottomSheet, "UpdateGrabberBackground", [brush]); |
| 668 | + SfBorder? grabber = (SfBorder?)GetPrivateField(_bottomSheet, "_grabber"); |
| 669 | + Assert.Equal((brush), grabber?.Background); |
| 670 | + } |
| 671 | + |
| 672 | + [Theory] |
| 673 | + [MemberData(nameof(CornerRadiusData))] |
| 674 | + public void UpdateCornerRadius(CornerRadius value, CornerRadius expected) |
| 675 | + { |
| 676 | + BottomSheetBorder bottomSheetBorder = new BottomSheetBorder(_bottomSheet); |
| 677 | + RoundRectangle roundRectangle = new RoundRectangle(); |
| 678 | + bottomSheetBorder.StrokeShape = roundRectangle; |
| 679 | + SetPrivateField(_bottomSheet, "_bottomSheetStrokeShape", roundRectangle); |
| 680 | + SetPrivateField(_bottomSheet, "_bottomSheet", bottomSheetBorder); |
| 681 | + InvokePrivateMethod(_bottomSheet, "UpdateCornerRadius", [value]); |
| 682 | + BottomSheetBorder? resultBottomSheetBorder = (BottomSheetBorder?)GetPrivateField(_bottomSheet, "_bottomSheet"); |
| 683 | + RoundRectangle? resultRoundRectangle = (RoundRectangle?)GetPrivateField(_bottomSheet, "_bottomSheetStrokeShape"); |
| 684 | + Assert.Equal(expected, resultRoundRectangle?.CornerRadius); |
| 685 | + Assert.Equal(resultRoundRectangle, resultBottomSheetBorder?.StrokeShape); |
| 686 | + } |
| 687 | + |
| 688 | + [Theory] |
| 689 | + [MemberData(nameof(ContentPaddingData))] |
| 690 | + public void UpdatePadding(Thickness value, Thickness expected) |
| 691 | + { |
| 692 | + SfBorder border = new SfBorder(); |
| 693 | + SetPrivateField(_bottomSheet, "_contentBorder", border); |
| 694 | + InvokePrivateMethod(_bottomSheet, "UpdatePadding", [value]); |
| 695 | + SfBorder? resultBorder = (SfBorder?)GetPrivateField(_bottomSheet, "_contentBorder"); |
| 696 | + Assert.Equal(expected, resultBorder?.Padding); |
| 697 | + } |
| 698 | + |
| 699 | + [Theory] |
| 700 | + [InlineData(30, 30)] |
| 701 | + [InlineData(0, 0)] |
| 702 | + [InlineData(-28, 4)] |
| 703 | + public void UpdateGrabberHeightProperty(double input, double expected) |
| 704 | + { |
| 705 | + InvokePrivateMethod(_bottomSheet, "UpdateGrabberHeightProperty", input); |
| 706 | + SfBorder? grabber = (SfBorder?)GetPrivateField(_bottomSheet, "_grabber"); |
| 707 | + var actual = grabber?.HeightRequest; |
| 708 | + Assert.Equal(expected, actual); |
| 709 | + } |
| 710 | + |
| 711 | + [Theory] |
| 712 | + [InlineData(48, 48)] |
| 713 | + [InlineData(0, 0)] |
| 714 | + [InlineData(-48, 32)] |
| 715 | + public void UpdateGrabberWidthProperty(double input, double expected) |
| 716 | + { |
| 717 | + InvokePrivateMethod(_bottomSheet, "UpdateGrabberWidthProperty", input); |
| 718 | + SfBorder? grabber = (SfBorder?)GetPrivateField(_bottomSheet, "_grabber"); |
| 719 | + var actual = grabber?.WidthRequest; |
| 720 | + Assert.Equal(expected, actual); |
| 721 | + } |
| 722 | + |
| 723 | + public static IEnumerable<object[]> CornerRadiusGrabber => |
| 724 | + new List<object[]> |
| 725 | + { |
| 726 | + new object[] { new CornerRadius(5), new CornerRadius(5) }, |
| 727 | + new object[] { new CornerRadius(0), new CornerRadius(0) }, |
| 728 | + new object[] { new CornerRadius(10, 5, 10, 5), new CornerRadius(10, 5, 10, 5) }, |
| 729 | + new object[] { new CornerRadius(15, 0, 5, 10), new CornerRadius(15, 0, 5, 10) }, |
| 730 | + }; |
| 731 | + |
| 732 | + [Theory] |
| 733 | + [MemberData(nameof(CornerRadiusGrabber))] |
| 734 | + public void UpdateGrabberCornerRadius(CornerRadius input, CornerRadius expected) |
| 735 | + { |
| 736 | + InvokePrivateMethod(_bottomSheet, "UpdateGrabberCornerRadius", input); |
| 737 | + RoundRectangle? strokeShape = (RoundRectangle?)GetPrivateField(_bottomSheet, "_grabberStrokeShape"); |
| 738 | + SfBorder? grabber = (SfBorder?)GetPrivateField(_bottomSheet, "_grabber"); |
| 739 | + Assert.Equal(expected, strokeShape?.CornerRadius); |
| 740 | + Assert.Equal(grabber?.StrokeShape, strokeShape); |
| 741 | + } |
| 742 | + |
| 743 | + [Theory] |
| 744 | + [InlineData(220, BottomSheetAllowedState.FullExpanded, BottomSheetState.Collapsed)] |
| 745 | + public void HandleFullExpandedState(double swipeDistance, BottomSheetAllowedState input, BottomSheetState expected) |
| 746 | + { |
| 747 | + double swipeThreshold = 100; |
| 748 | + double doubleSwipeThreshold = 2 * swipeThreshold; |
| 749 | + var currentState = BottomSheetState.FullExpanded; |
| 750 | + _bottomSheet.State = currentState; |
| 751 | + _bottomSheet.AllowedState = input; |
| 752 | + InvokePrivateMethod(_bottomSheet, "HandleFullExpandedState", swipeDistance, swipeThreshold, doubleSwipeThreshold); |
| 753 | + var actual = _bottomSheet.State; |
| 754 | + Assert.Equal(expected, actual); |
| 755 | + } |
| 756 | + |
| 757 | + [Theory] |
| 758 | + [InlineData(-120, BottomSheetAllowedState.All, BottomSheetState.FullExpanded)] |
| 759 | + [InlineData(140, BottomSheetAllowedState.HalfExpanded, BottomSheetState.Collapsed)] |
| 760 | + public void HandleHalfExpandedState(double swipeDistance, BottomSheetAllowedState input, BottomSheetState expected) |
| 761 | + { |
| 762 | + double swipeThreshold = 100; |
| 763 | + var currentState = BottomSheetState.HalfExpanded; |
| 764 | + _bottomSheet.State = currentState; |
| 765 | + _bottomSheet.AllowedState = input; |
| 766 | + InvokePrivateMethod(_bottomSheet, "HandleHalfExpandedState", swipeDistance, swipeThreshold); |
| 767 | + var actual = _bottomSheet.State; |
| 768 | + Assert.Equal(expected, actual); |
| 769 | + } |
| 770 | + |
| 771 | + [Theory] |
| 772 | + [InlineData(-120, BottomSheetAllowedState.HalfExpanded, BottomSheetState.HalfExpanded)] |
| 773 | + [InlineData(-160, BottomSheetAllowedState.FullExpanded, BottomSheetState.FullExpanded)] |
| 774 | + [InlineData(-80, BottomSheetAllowedState.All, BottomSheetState.Collapsed)] |
| 775 | + public void HandleCollapsedState(double swipeDistance, BottomSheetAllowedState input, BottomSheetState expected) |
| 776 | + { |
| 777 | + double swipeThreshold = 100; |
| 778 | + var currentState = BottomSheetState.Collapsed; |
| 779 | + _bottomSheet.State = currentState; |
| 780 | + _bottomSheet.AllowedState = input; |
| 781 | + InvokePrivateMethod(_bottomSheet, "HandleCollapsedState", swipeDistance, swipeThreshold); |
| 782 | + var actual = _bottomSheet.State; |
| 783 | + Assert.Equal(expected, actual); |
| 784 | + } |
| 785 | + |
| 786 | + [Theory] |
| 787 | + [InlineData(BottomSheetState.Hidden, BottomSheetState.Collapsed, false)] |
| 788 | + [InlineData(BottomSheetState.Hidden, BottomSheetState.HalfExpanded, true)] |
| 789 | + [InlineData(BottomSheetState.Hidden, BottomSheetState.FullExpanded, true)] |
| 790 | + [InlineData(BottomSheetState.Collapsed, BottomSheetState.HalfExpanded, true)] |
| 791 | + [InlineData(BottomSheetState.Collapsed, BottomSheetState.FullExpanded, true)] |
| 792 | + [InlineData(BottomSheetState.HalfExpanded, BottomSheetState.Collapsed, false)] |
| 793 | + [InlineData(BottomSheetState.HalfExpanded, BottomSheetState.FullExpanded, true)] |
| 794 | + [InlineData(BottomSheetState.FullExpanded, BottomSheetState.HalfExpanded, true)] |
| 795 | + [InlineData(BottomSheetState.FullExpanded, BottomSheetState.Collapsed, false)] |
| 796 | + public void UpdateStateChanged(BottomSheetState oldState, BottomSheetState newState, bool expectedOverlay) |
| 797 | + { |
| 798 | + _bottomSheet.State = newState; |
| 799 | + InvokePrivateMethod(_bottomSheet, "UpdateStateChanged", oldState, newState); |
| 800 | + StateChangedEventArgs? eventArgs = (StateChangedEventArgs?)GetPrivateField(_bottomSheet, "_stateChangedEventArgs"); |
| 801 | + SfGrid? overlay = (SfGrid?)GetPrivateField(_bottomSheet, "_overlayGrid"); |
| 802 | + Assert.NotEqual(eventArgs?.OldState, eventArgs?.NewState); |
| 803 | + Assert.Equal(expectedOverlay, overlay?.IsVisible); |
| 804 | + } |
| 805 | + |
| 806 | + [Theory] |
| 807 | + [InlineData(true, true)] |
| 808 | + [InlineData(false, false)] |
| 809 | + public void SetupBottomSheetForShow(bool input, bool expected) |
| 810 | + { |
| 811 | + _bottomSheet.IsModal = input; |
| 812 | + InvokePrivateMethod(_bottomSheet, "SetupBottomSheetForShow"); |
| 813 | + SfGrid? overlay = (SfGrid?)GetPrivateField(_bottomSheet, "_overlayGrid"); |
| 814 | + SfBorder? bottomsheet = (SfBorder?)GetPrivateField(_bottomSheet, "_bottomSheet"); |
| 815 | + Assert.True(bottomsheet?.IsVisible); |
| 816 | + Assert.Equal(0, overlay?.Opacity); |
| 817 | + Assert.Equal(expected, overlay?.IsVisible); |
| 818 | + } |
| 819 | + |
| 820 | + [Fact] |
| 821 | + public void GetCollapsedPosition() |
| 822 | + { |
| 823 | + InvokePrivateMethod(_bottomSheet, "GetCollapsedPosition"); |
| 824 | + SfGrid? overlay = (SfGrid?)GetPrivateField(_bottomSheet, "_overlayGrid"); |
| 825 | + Assert.False(overlay?.IsVisible); |
| 826 | + } |
| 827 | + |
| 828 | + [Fact] |
| 829 | + public void HandleTouchPressed() |
| 830 | + { |
| 831 | + double initialTouchY = 500; |
| 832 | + SetPrivateField(_bottomSheet, "_initialTouchY", initialTouchY); |
| 833 | + SetPrivateField(_bottomSheet, "_isPointerPressed", true); |
| 834 | + |
| 835 | + InvokePrivateMethod(_bottomSheet, "HandleTouchReleased", initialTouchY); |
| 836 | + |
| 837 | + Assert.False(Convert.ToBoolean(GetPrivateField(_bottomSheet, "_isPointerPressed"))); |
| 838 | + } |
| 839 | + |
| 840 | + [Fact] |
| 841 | + public void HandleTouchReleased() |
| 842 | + { |
| 843 | + double initialTouchY = 500; |
| 844 | + SetPrivateField(_bottomSheet, "_initialTouchY", initialTouchY); |
| 845 | + SetPrivateField(_bottomSheet, "_isPointerPressed", true); |
| 846 | + |
| 847 | + InvokePrivateMethod(_bottomSheet,"HandleTouchReleased", initialTouchY); |
| 848 | + |
| 849 | + Assert.Equal(initialTouchY, GetPrivateField(_bottomSheet, "_endTouchY")); |
| 850 | + Assert.False(Convert.ToBoolean(GetPrivateField(_bottomSheet, "_isPointerPressed"))); |
| 851 | + } |
| 852 | + |
| 853 | + #endregion |
| 854 | + |
517 | 855 | #region Events
|
518 | 856 |
|
519 | 857 | public static IEnumerable<object[]> StateData =>
|
|
0 commit comments