|
5 | 5 | using System;
|
6 | 6 | using System.Collections.Generic;
|
7 | 7 | using System.Linq;
|
8 |
| -using System.Text.Json; |
9 | 8 | using System.Text.RegularExpressions;
|
10 |
| -using System.Threading.Tasks; |
11 | 9 | using Xunit;
|
12 |
| -using Xunit.Abstractions; |
13 |
| -using static System.Reflection.Metadata.BlobBuilder; |
14 | 10 |
|
15 | 11 | namespace Radzen.Blazor.Tests
|
16 | 12 | {
|
@@ -842,152 +838,5 @@ public void DataGrid_Respects_PageSizeParameter()
|
842 | 838 | Assert.True(newArgs.Skip == 20);
|
843 | 839 | Assert.True(newArgs.Top == 20);
|
844 | 840 | }
|
845 |
| - |
846 |
| - // Filter tests |
847 |
| - |
848 |
| - /// <summary> |
849 |
| - /// Utility class for testing. |
850 |
| - /// </summary> |
851 |
| - /// <remarks> |
852 |
| - /// Tests that involves filtering on <see cref="RadzenDataGrid{TItem}"/> requires the generic parameter to be a specific type. |
853 |
| - /// They do not work using <c>object</c> or <c>dynamic</c>. |
854 |
| - /// </remarks> |
855 |
| - /// <param name="Name"></param> |
856 |
| - /// <param name="Roles"></param> |
857 |
| - private sealed record User(string Name, IEnumerable<Role> Roles); |
858 |
| - /// <summary> |
859 |
| - /// Utility class for testing. |
860 |
| - /// </summary> |
861 |
| - /// <remarks> |
862 |
| - /// Tests that involves filtering on <see cref="RadzenDataGrid{TItem}"/> requires the generic parameter to be a specific type. |
863 |
| - /// They do not work using <c>object</c> or <c>dynamic</c>. |
864 |
| - /// </remarks> |
865 |
| - /// <param name="Id"></param> |
866 |
| - /// <param name="Description"></param> |
867 |
| - private sealed record Role(int Id, string Description); |
868 |
| - |
869 |
| - [Fact] |
870 |
| - public async Task DataGrid_FilterBySubProperties_ReturnsDataFiltered() |
871 |
| - { |
872 |
| - // Arrange |
873 |
| - using var ctx = new TestContext(); |
874 |
| - ctx.JSInterop.Mode = JSRuntimeMode.Loose; |
875 |
| - ctx.JSInterop.SetupModule("_content/Radzen.Blazor/Radzen.Blazor.js"); |
876 |
| - |
877 |
| - Role admin = new(0, "Admin"); |
878 |
| - Role guest = new(1, "Guest"); |
879 |
| - User moe = new("Moe", [admin]); |
880 |
| - User tom = new("Tom", [admin, guest]); |
881 |
| - User sam = new("Sam", [guest]); |
882 |
| - |
883 |
| - User[] data = [moe, tom, sam]; |
884 |
| - |
885 |
| - var component = ctx.RenderComponent<RadzenDataGrid<User>>(parameters => |
886 |
| - { |
887 |
| - parameters.Add(p => p.Data, data); |
888 |
| - parameters.Add(p => p.AllowFiltering, true); |
889 |
| - parameters.Add(p => p.FilterMode, FilterMode.CheckBoxList); |
890 |
| - parameters.Add(p => p.Columns, builder => |
891 |
| - { |
892 |
| - builder.OpenComponent(0, typeof(RadzenDataGridColumn<User>)); |
893 |
| - builder.AddAttribute(1, "Property", "Name"); |
894 |
| - builder.AddAttribute(2, "Title", "User"); |
895 |
| - builder.CloseComponent(); |
896 |
| - builder.OpenComponent(0, typeof(RadzenDataGridColumn<User>)); |
897 |
| - builder.AddAttribute(1, "Property", "Roles"); |
898 |
| - builder.AddAttribute(2, "FilterProperty", "Id"); |
899 |
| - builder.AddAttribute(3, "Type", typeof(IEnumerable<Role>)); |
900 |
| - builder.AddAttribute(4, "Title", "Roles"); |
901 |
| - builder.CloseComponent(); |
902 |
| - }); |
903 |
| - }); |
904 |
| - |
905 |
| - // Act |
906 |
| - await component.InvokeAsync(() => component |
907 |
| - .Instance |
908 |
| - .ColumnsCollection |
909 |
| - .First(c => c.Property == "Roles") |
910 |
| - .SetFilterValueAsync(new[] { 1 }) |
911 |
| - ); |
912 |
| - |
913 |
| - component.Render(); |
914 |
| - |
915 |
| - var filteredData = await component.InvokeAsync(component.Instance.View.ToArray); |
916 |
| - |
917 |
| - // Assert |
918 |
| - Assert.DoesNotContain(moe, filteredData); |
919 |
| - Assert.Contains(sam, filteredData); |
920 |
| - Assert.Contains(tom, filteredData); |
921 |
| - } |
922 |
| - |
923 |
| - [Fact] |
924 |
| - public async Task DataGrid_LoadFilterSettingsFromJson_ReturnsDataFiltered() |
925 |
| - { |
926 |
| - // Arrange |
927 |
| - using var ctx = new TestContext(); |
928 |
| - ctx.JSInterop.Mode = JSRuntimeMode.Loose; |
929 |
| - ctx.JSInterop.SetupModule("_content/Radzen.Blazor/Radzen.Blazor.js"); |
930 |
| - |
931 |
| - Role admin = new(0, "Admin"); |
932 |
| - Role guest = new(1, "Guest"); |
933 |
| - User moe = new("Moe", [admin]); |
934 |
| - User tom = new("Tom", [admin, guest]); |
935 |
| - User sam = new("Sam", [guest]); |
936 |
| - |
937 |
| - User[] data = [moe, tom, sam]; |
938 |
| - |
939 |
| - string settings = string.Empty; |
940 |
| - |
941 |
| - var component = ctx.RenderComponent<RadzenDataGrid<User>>(parameters => |
942 |
| - { |
943 |
| - parameters.Add(p => p.Data, data); |
944 |
| - parameters.Add(p => p.AllowFiltering, true); |
945 |
| - parameters.Add(p => p.FilterMode, FilterMode.CheckBoxList); |
946 |
| - parameters.Add(p => p.LoadSettings, OnLoadSettings); |
947 |
| - parameters.Add(p => p.SettingsChanged, OnSettingsChanged); |
948 |
| - parameters.Add(p => p.Columns, builder => |
949 |
| - { |
950 |
| - builder.OpenComponent(0, typeof(RadzenDataGridColumn<User>)); |
951 |
| - builder.AddAttribute(1, "Property", "Name"); |
952 |
| - builder.AddAttribute(2, "Title", "User"); |
953 |
| - builder.CloseComponent(); |
954 |
| - builder.OpenComponent(0, typeof(RadzenDataGridColumn<User>)); |
955 |
| - builder.AddAttribute(1, "Property", "Roles"); |
956 |
| - builder.AddAttribute(2, "FilterProperty", "Id"); |
957 |
| - builder.AddAttribute(3, "Type", typeof(IEnumerable<Role>)); |
958 |
| - builder.AddAttribute(4, "Title", "Roles"); |
959 |
| - builder.CloseComponent(); |
960 |
| - }); |
961 |
| - }); |
962 |
| - |
963 |
| - void OnSettingsChanged(DataGridSettings args) |
964 |
| - { |
965 |
| - settings = JsonSerializer.Serialize(args); |
966 |
| - } |
967 |
| - |
968 |
| - void OnLoadSettings(DataGridLoadSettingsEventArgs args) |
969 |
| - { |
970 |
| - if (string.IsNullOrEmpty(settings)) return; |
971 |
| - |
972 |
| - args.Settings = JsonSerializer.Deserialize<DataGridSettings>(settings); |
973 |
| - } |
974 |
| - |
975 |
| - // Act |
976 |
| - await component.InvokeAsync(() => component |
977 |
| - .Instance |
978 |
| - .ColumnsCollection |
979 |
| - .First(c => c.Property == "Roles") |
980 |
| - .SetFilterValueAsync(new[] { 1 }) |
981 |
| - ); |
982 |
| - |
983 |
| - component.Render(); |
984 |
| - |
985 |
| - var filteredData = await component.InvokeAsync(component.Instance.View.ToArray); |
986 |
| - |
987 |
| - // Assert |
988 |
| - Assert.DoesNotContain(moe, filteredData); |
989 |
| - Assert.Contains(sam, filteredData); |
990 |
| - Assert.Contains(tom, filteredData); |
991 |
| - } |
992 | 841 | }
|
993 | 842 | }
|
0 commit comments