-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathSelectExtendedTests.cs
More file actions
1372 lines (1224 loc) · 75.8 KB
/
SelectExtendedTests.cs
File metadata and controls
1372 lines (1224 loc) · 75.8 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma warning disable CS1998 // async without await
#pragma warning disable IDE1006 // leading underscore
#pragma warning disable BL0005 // Set parameter outside component
using Bunit;
using MudExtensions.UnitTests.TestComponents;
using AwesomeAssertions;
using Microsoft.AspNetCore.Components.Web;
using MudExtensions;
using NUnit.Framework;
using static MudExtensions.UnitTests.TestComponents.SelectWithEnumTest;
using MudBlazor;
using MudExtensions.UnitTests.Extensions;
using MudBlazor.Extensions;
namespace MudExtensions.UnitTests.Components
{
[TestFixture]
public class SelectExtendedTests : BunitTest
{
/// <summary>
/// Select id should propagate to label for attribute
/// </summary>
[Test]
public void SelectLabelFor()
{
var comp = Context.Render<SelectRequiredTest>();
var label = comp.FindAll(".mud-input-label");
label[0].Attributes.GetNamedItem("for")?.Value.Should().Be("selectLabelTest");
}
// Note: MudSelect doesn't guaranteed the consequences of changing Value if MultiSelection is true for now.
// When this feature will add, just uncomment the testcase to test it. No need to write new test.
[Test]
[TestCase(false)]
//[TestCase(true)]
public void Select_InitialValueTest(bool multiSelection)
{
var comp = Context.Render<SelectInitialValueTest>(x =>
{
x.Add(c => c.SelectedValue, "1");
x.Add(c => c.MultiSelection, multiSelection);
});
var select = comp.FindComponent<MudSelectExtended<string>>();
select.Instance.GetState(x => x.Value).Should().Be("1");
select.Instance.SelectedValues.Should().BeEquivalentTo(new HashSet<string>() { "1" });
select.Instance.GetState(x => x.Text).Should().Be("1");
}
// Note: MudSelect doesn't guaranteed the consequences of changing SelectedValues if MultiSelection is false for now.
// When this feature will add, just uncomment the testcase to test it. No need to write new test.
[Test]
//[TestCase(false)]
[TestCase(true)]
public void Select_InitialValuesTest(bool multiSelection)
{
var comp = Context.Render<SelectInitialValueTest>(x =>
{
x.Add(c => c.SelectedValues, new HashSet<string>() { "1" });
x.Add(c => c.MultiSelection, multiSelection);
});
var select = comp.FindComponent<MudSelectExtended<string>>();
select.Instance.GetState(x => x.Value).Should().Be("1");
select.Instance.SelectedValues.Should().BeEquivalentTo(new HashSet<string>() { "1" });
select.Instance.GetState(x => x.Text).Should().Be("1");
}
[Test]
public async Task Select_ValueBubblingTest()
{
var comp = Context.Render<SelectInitialValueTest>();
var select = comp.FindComponent<MudSelectExtended<string>>();
select.Instance.GetState(x => x.Value).Should().BeNull();
select.Instance.GetState(x => x.Text).Should().BeNull();
comp.Render(p => p.Add(x => x.SelectedValue, "1"));
await comp.InvokeAsync(() => select.Instance.ForceUpdate());
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().Be("1"));
select.Instance.SelectedValues.Should().BeEquivalentTo(new HashSet<string>() { "1" });
select.Instance.GetState(x => x.Text).Should().Be("1");
comp.Render(p => p.Add(x => x.SelectedValue, "2"));
await comp.InvokeAsync(() => select.Instance.ForceUpdate());
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().Be("2"));
select.Instance.SelectedValues.Should().BeEquivalentTo(new HashSet<string>() { "2" });
select.Instance.GetState(x => x.Text).Should().Be("2");
}
[Test]
public void Select_ValueBubblingTest_MultiSelection()
{
var comp = Context.Render<SelectInitialValueTest>(x =>
{
x.Add(c => c.MultiSelection, true);
});
var select = comp.FindComponent<MudSelectExtended<string>>();
select.Instance.GetState(x => x.Value).Should().BeNull();
select.Instance.GetState(x => x.Text).Should().BeNullOrEmpty();
comp.Render(p => p.Add(x => x.SelectedValues, new HashSet<string>() { "1" }));
select.Instance.GetState(x => x.Value).Should().Be("1");
select.Instance.SelectedValues.Should().BeEquivalentTo(new HashSet<string>() { "1" });
select.Instance.GetState(x => x.Text).Should().Be("1");
comp.Render(p => p.Add(x => x.SelectedValues, new HashSet<string>() { "2", "1" }));
select.Instance.GetState(x => x.Value).Should().Be("1");
select.Instance.SelectedValues.Should().BeEquivalentTo(new HashSet<string>() { "2", "1" });
select.Instance.GetState(x => x.Text).Should().Be("2, 1");
}
[Test]
public async Task Select_ValueChangeEventCountTest()
{
var comp = Context.Render<SelectEventCountTest>(x =>
{
x.Add(c => c.MultiSelection, false);
});
var select = comp.FindComponent<MudSelectExtended<string>>();
var input = comp.Find("div.mud-input-control");
comp.Instance.ValueChangeCount.Should().Be(0);
comp.Instance.ValuesChangeCount.Should().Be(0);
await comp.InvokeAsync(() => select.Render(p => p.Add(x => x.Value, "1")));
await comp.InvokeAsync(() => select.Instance.ForceUpdate());
comp.WaitForAssertion(() => comp.Instance.ValueChangeCount.Should().Be(1));
comp.Instance.ValuesChangeCount.Should().Be(1);
select.Instance.GetState(x => x.Value).Should().Be("1");
// Changing value programmatically without ForceUpdate should change value, but should not fire change events
// Its by design, so this part can be change if design changes
await comp.InvokeAsync(() => select.Render(p => p.Add(x => x.Value, "2")));
comp.WaitForAssertion(() => comp.Instance.ValueChangeCount.Should().Be(1));
comp.Instance.ValuesChangeCount.Should().Be(1);
select.Instance.GetState(x => x.Value).Should().Be("2");
}
[Test]
public async Task Select_ValueChangeEventCountTest_MultiSelection()
{
var comp = Context.Render<SelectEventCountTest>(x =>
{
x.Add(c => c.MultiSelection, true);
});
var select = comp.FindComponent<MudSelectExtended<string>>();
comp.Instance.ValueChangeCount.Should().Be(0);
comp.Instance.ValuesChangeCount.Should().Be(0);
comp.Instance.ItemChangeCount.Should().Be(0);
comp.Instance.ItemsChangeCount.Should().Be(0);
await comp.InvokeAsync(() => select.Render(p => p.Add(x => x.SelectedValues, new HashSet<string>() { "1" })));
comp.WaitForAssertion(() => comp.Instance.ValueChangeCount.Should().Be(1));
comp.Instance.ValuesChangeCount.Should().Be(1);
// Setting same value should not fire events
await comp.InvokeAsync(() => select.Render(p => p.Add(x => x.SelectedValues, new HashSet<string>() { "1" })));
comp.WaitForAssertion(() => comp.Instance.ValueChangeCount.Should().Be(1));
comp.Instance.ValuesChangeCount.Should().Be(1);
}
/// <summary>
/// Click should open the Menu and selecting a value should update the bindable value.
/// </summary>
[Test]
public async Task SelectTest1()
{
var comp = Context.Render<SelectTest1>();
// print the generated html
//Console.WriteLine(comp.Markup);
// select elements needed for the test
var select = comp.FindComponent<MudSelectExtended<string>>();
var menu = comp.Find("div.mud-popover");
var input = comp.Find("div.mud-input-control");
// check popover class
menu.ClassList.Should().Contain("select-popover-class");
// check initial state
select.Instance.GetState(x => x.Value).Should().BeNullOrEmpty();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));
// click and check if it has toggled the menu
input.Click();
menu.ClassList.Should().Contain("mud-popover-open");
// now click an item and see the value change
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
var items = comp.FindAll("div.mud-list-item-extended").ToArray();
items[1].Click();
// menu should be closed now
comp.WaitForAssertion(() => menu.ClassList.Should().NotContain("mud-popover-open"));
select.Instance.GetState(x => x.Value).Should().Be("2");
// now we cheat and click the list without opening the menu ;)
input.Click();
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
items = comp.FindAll("div.mud-list-item-extended").ToArray();
items[0].Click();
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().Be("1"));
//Check user on blur implementation works
var @switch = comp.FindComponent<MudSwitch<bool>>();
@switch.Instance.Value = true;
await comp.InvokeAsync(() => select.Instance.OnLostFocus(new FocusEventArgs()));
comp.WaitForAssertion(() => @switch.Instance.GetState(x => x.Value).Should().Be(false));
}
/// <summary>
/// Click should not close the menu and selecting multiple values should update the bindable value with a comma separated list.
/// </summary>
[Test]
public async Task MultiSelectTest1()
{
//await ImproveChanceOfSuccess(async () =>
//{
var comp = Context.Render<MultiSelectTest1>();
// print the generated html
Console.WriteLine(comp.Markup);
// select elements needed for the test
var select = comp.FindComponent<MudSelectExtended<string>>();
var menu = comp.Find("div.mud-popover");
var input = comp.Find("div.mud-input-control");
// check initial state
select.Instance.GetState(x => x.Value).Should().BeNullOrEmpty();
comp.WaitForAssertion(() =>
comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));
// click and check if it has toggled the menu
await comp.InvokeAsync(() => input.Click());
comp.WaitForAssertion(() => menu.ClassList.Should().Contain("mud-popover-open"));
// now click an item and see the value change
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
var items = comp.FindAll("div.mud-list-item-extended").ToArray();
items[1].Click();
// menu should still be open now!!
menu.ClassList.Should().Contain("mud-popover-open");
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Text).Should().Be("2"));
items[0].Click();
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Text).Should().Be("2, 1"));
items[2].Click();
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Text).Should().Be("2, 1, 3"));
items[0].Click();
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Text).Should().Be("2, 3"));
select.Instance.SelectedValues?.Count().Should().Be(2);
select.Instance.SelectedValues.Should().Contain("2");
select.Instance.SelectedValues.Should().Contain("3");
//Console.WriteLine(comp.Markup);
const string @unchecked =
"M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z";
const string @checked =
"M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z";
// check that the correct items are checked
comp.WaitForAssertion(() =>
comp.FindAll("div.mud-list-item-extended path")[1]?.Attributes["d"]?.Value.Should().Be(@unchecked));
comp.FindAll("div.mud-list-item-extended path")[3]?.Attributes["d"]?.Value.Should().Be(@checked);
comp.FindAll("div.mud-list-item-extended path")[5]?.Attributes["d"]?.Value.Should().Be(@checked);
// now check how setting the SelectedValues makes items checked or unchecked
// Note: If popover is open, selecting values programmatically doesn't work for now.
await comp.InvokeAsync(() => select.Instance.CloseMenu());
await comp.InvokeAsync(() =>
{
select.Instance.SelectedValues = new HashSet<string>() { "1", "2" };
});
await comp.InvokeAsync(() => input.Click());
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended path")[1]?.Attributes["d"]?.Value.Should().Be(@checked));
comp.FindAll("div.mud-list-item-extended path")[3]?.Attributes["d"]?.Value.Should().Be(@checked);
select.Instance.SelectedValues.Should().NotContain("3");
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended path")[5]?.Attributes["d"]?.Value.Should().Be(@unchecked));
//Console.WriteLine(comp.Markup);
//});
}
/// <summary>
/// Initial Text should be enums default value
/// Initial render fragment in input should be the pre-selected value's items's render fragment.
/// After clicking the second item, the render fragment should update
/// </summary>
[Test]
public async Task SelectWithEnumTest()
{
var comp = Context.Render<SelectWithEnumTest>();
//Console.WriteLine(comp.Markup);
// select elements needed for the test
var select = comp.FindComponent<MudSelectExtended<MyEnum>>();
var input = comp.Find("div.mud-input-control");
select.Instance.GetState(x => x.Value).Should().Be(default(MyEnum));
select.Instance.GetState(x => x.Text).Should().Be(default(MyEnum).ToString());
comp.Find("input").Attributes["value"]?.Value.Should().Be("First");
//comp.RenderCount.Should().Be(1);
//Console.WriteLine(comp.Markup);
input.Click();
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
var items = comp.FindAll("div.mud-list-item-extended").ToArray();
items[1].Click();
comp.WaitForAssertion(() => comp.Find("input").Attributes["value"]?.Value.Should().Be("Second"));
}
/// <summary>
/// Initially we have a value of 17 which is not in the list. So we render it as text via MudInput
/// </summary>
[Test]
public void SelectUnrepresentableValueTest()
{
var comp = Context.Render<SelectUnrepresentableValueTest>();
// select elements needed for the test
var select = comp.FindComponent<MudSelectExtended<int>>();
var input = comp.Find("div.mud-input-control");
select.Instance.GetState(x => x.Value).Should().Be(17);
select.Instance.GetState(x => x.Text).Should().Be("17");
comp.Find("input").Attributes["value"]?.Value.Should().Be("17");
input.Click();
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
var items = comp.FindAll("div.mud-list-item-extended").ToArray();
items[1].TextContent.Should().Be("Two");
items[1].Click();
//Console.WriteLine(comp.Markup);
//comp.WaitForAssertion(() => comp.Find("div.mud-input-slot").TextContent.Trim().Should().Be("Two"));
select.Instance.GetState(x => x.Value).Should().Be(2);
select.Instance.GetState(x => x.Text).Should().Be("2");
}
/// <summary>
/// Don't show initial value which is not in list because of Strict=true.
/// </summary>
[Test]
public void SelectUnrepresentableValueTest2()
{
var comp = Context.Render<SelectUnrepresentableValueTest2>();
//Console.WriteLine(comp.Markup);
// select elements needed for the test
var select = comp.FindComponent<MudSelectExtended<int>>();
var input = comp.Find("div.mud-input-control");
select.Instance.GetState(x => x.Value).Should().Be(17);
select.Instance.GetState(x => x.Text).Should().Be("17");
//await Task.Delay(100);
// BUT: we have a select with Strict="true" so the Text will not be shown because it is not in the list of selectable values
comp.FindComponent<MudInputExtended<string>>().Instance.GetState(x => x.Value).Should().Be(null);
comp.FindComponent<MudInputExtended<string>>().Instance.InputType.Should().Be(InputType.Hidden);
input.Click();
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
var items = comp.FindAll("div.mud-list-item-extended").ToArray();
items[1].Click();
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().Be(2));
select.Instance.GetState(x => x.Text).Should().Be("2");
//Console.WriteLine(comp.Markup);
comp.FindComponent<MudInputExtended<string>>().Instance.GetState(x => x.Value).Should().Be("2");
comp.FindComponent<MudInputExtended<string>>().Instance.InputType.Should().Be(InputType.Hidden); // because list item has no render fragment, so we show it as text
}
/// <summary>
/// The items have no render fragments, so instead of RF the select must display the converted string value
/// </summary>
[Test]
public void SelectWithoutItemPresentersTest()
{
var comp = Context.Render<SelectTextValueTest>();
//Console.WriteLine(comp.Markup);
// select elements needed for the test
var select = comp.FindComponent<MudSelectExtended<bool?>>();
var input = comp.Find("div.mud-input-control");
select.Instance.GetState(x => x.Value).Should().BeTrue();
select.Instance.GetState(x => x.Text).Should().Be("Open");
//comp.Find("div.mud-input-slot").Attributes["style"].Value.Should().Contain("display:none");
//comp.RenderCount.Should().Be(1);
////Console.WriteLine(comp.Markup);
//Last item doesn't have text, so it should show value as text.
input.Click();
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
var items = comp.FindAll("div.mud-list-item-extended").ToArray();
items[2].Click();
//comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));
//comp.WaitForAssertion(() => comp.Find("div.mud-input-slot").Attributes["style"].Value.Should().Contain("display:none"));
select.Instance.GetState(x => x.Value).Should().BeFalse();
select.Instance.GetState(x => x.Text).Should().Be("False");
input.Click();
items = comp.FindAll("div.mud-list-item-extended").ToArray();
items[0].Click();
select.Instance.GetState(x => x.Value).Should().BeNull();
select.Instance.GetState(x => x.Text).Should().Be("Open and Closed");
}
[Test]
public void Select_Should_FireTextChangedWithNewValue()
{
var comp = Context.Render<SelectTest1>();
//Console.WriteLine(comp.Markup);
var select = comp.FindComponent<MudSelectExtended<string>>();
string? text = null;
select.SetParametersAndRenderAsync(parameters => parameters.Add(s => s.TextChanged, (Action<string>)(x => text = x)));
var menu = comp.Find("div.mud-popover");
var input = comp.Find("div.mud-input-control");
// check initial state
select.Instance.GetState(x => x.Value).Should().BeNullOrEmpty();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));
// click and check if it has toggled the menu
input.Click();
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
menu.ClassList.Should().Contain("mud-popover-open");
// now click an item and see the value change
var items = comp.FindAll("div.mud-list-item-extended").ToArray();
items[1].Click();
// menu should be closed now
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().Be("2"));
select.Instance.GetState(x => x.Text).Should().Be("2");
text.Should().Be("2");
//open the menu again
input.Click();
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
items = comp.FindAll("div.mud-list-item-extended").ToArray();
items[0].Click();
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().Be("1"));
select.Instance.GetState(x => x.Text).Should().Be("1");
text.Should().Be("1");
}
/// <summary>
/// SingleSelect: SelectedValuesChanged should be fired before TextChanged
/// We test this by checking the counter. The event which should be fired first must always
/// find an even counter value, the second must always find an odd value.
/// </summary>
[Test]
public void SingleSelect_Should_FireTextChangedBeforeSelectedValuesChanged()
{
var comp = Context.Render<SelectTest1>();
//Console.WriteLine(comp.Markup);
var select = comp.FindComponent<MudSelectExtended<string>>();
string? text = null;
IEnumerable<string?>? selectedValues = null;
var eventCounter = 0;
var textChangedCount = 0;
var selectedValuesChangedCount = 0;
select.SetParametersAndRenderAsync(parameters => parameters.Add(s => s.TextChanged, (Action<string>)(x =>
{
textChangedCount = eventCounter++;
text = x;
})));
select.SetParametersAndRenderAsync(parameters => parameters.Add(s => s.SelectedValuesChanged, (Action<IEnumerable<string>>)(x =>
{
selectedValuesChangedCount = eventCounter++;
selectedValues = x;
})));
var menu = comp.Find("div.mud-popover");
var input = comp.Find("div.mud-input-control");
// check initial state
select.Instance.GetState(x => x.Value).Should().BeNullOrEmpty();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));
// click and check if it has toggled the menu
input.Click();
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
menu.ClassList.Should().Contain("mud-popover-open");
// now click an item and see the value change
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
var items = comp.FindAll("div.mud-list-item-extended").ToArray();
items[1].Click();
// menu should be closed now
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().Be("2"));
select.Instance.GetState(x => x.Text).Should().Be("2");
text.Should().Be("2");
selectedValuesChangedCount.Should().Be(1);
textChangedCount.Should().Be(0);
string.Join(",", selectedValues ?? new List<string>()).Should().Be("2");
input.Click();
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
items = comp.FindAll("div.mud-list-item-extended").ToArray();
items[0].Click();
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().Be("1"));
select.Instance.GetState(x => x.Text).Should().Be("1");
text.Should().Be("1");
string.Join(",", selectedValues ?? new List<string>()).Should().Be("1");
comp.WaitForAssertion(() => selectedValuesChangedCount.Should().Be(3));
comp.WaitForAssertion(() => textChangedCount.Should().Be(2));
}
/// <summary>
/// MultiSelect: SelectedValuesChanged should be fired before TextChanged
/// We test this by checking the counter. The event which should be fired first must always
/// find an even counter value, the second must always find an odd value.
/// </summary>
[Test]
public void MultiSelect_Should_FireTextChangedBeforeSelectedValuesChanged()
{
var comp = Context.Render<SelectTest1>();
//Console.WriteLine(comp.Markup);
var select = comp.FindComponent<MudSelectExtended<string>>();
string? text = null;
IEnumerable<string?>? selectedValues = null;
var eventCounter = 0;
var textChangedCount = 0;
var selectedValuesChangedCount = 0;
select.Render(p => p.Add(x => x.MultiSelection, true));
select.SetParametersAndRenderAsync(parameters => parameters.Add(s => s.TextChanged, (Action<string>)(x =>
{
textChangedCount = eventCounter++;
text = x;
})));
select.SetParametersAndRenderAsync(parameters => parameters.Add(s => s.SelectedValuesChanged, (Action<IEnumerable<string>>)(x =>
{
selectedValuesChangedCount = eventCounter++;
selectedValues = x;
})));
var selectElement = comp.Find("div.mud-input-control");
selectElement.Click();
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
var items = comp.FindAll("div.mud-list-item-extended").ToArray();
// click list item
items[1].Click();
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().Be("2"));
select.Instance.GetState(x => x.Text).Should().Be("2");
text.Should().Be("2");
selectedValuesChangedCount.Should().Be(1);
textChangedCount.Should().Be(0);
string.Join(",", selectedValues ?? new List<string>()).Should().Be("2");
// click another list item
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
items = comp.FindAll("div.mud-list-item-extended").ToArray();
items[0].Click();
comp.WaitForAssertion(() => select.Instance.SelectedValues.Should().BeEquivalentTo(new HashSet<string>() { "2", "1" }));
select.Instance.GetState(x => x.Text).Should().Be("2, 1");
text.Should().Be("2, 1");
string.Join(",", selectedValues ?? new List<string>()).Should().Be("2,1");
selectedValuesChangedCount.Should().Be(3);
textChangedCount.Should().Be(2);
}
[Test]
public async Task Select_Should_Not_FireOnBlur()
{
var comp = Context.Render<SelectTest1>();
//Console.WriteLine(comp.Markup);
var select = comp.FindComponent<MudSelectExtended<string>>();
var eventCounter = 0;
await select.SetParametersAndRenderAsync(parameters => parameters.Add(s => s.OnBlur, () => eventCounter++));
await comp.InvokeAsync(async () =>
{
await select.Instance.OpenMenu();
await select.Instance.CloseMenu();
});
eventCounter.Should().Be(0);
}
[Test]
public void Disabled_SelectItem_Should_Be_Respected()
{
var comp = Context.Render<SelectTest1>();
var select = comp.FindComponent<MudSelectExtended<string>>();
//Console.WriteLine(comp.Markup);
var selectElement = comp.Find("div.mud-input-control");
selectElement.Click();
// Disabled item found twice because we have 2 shadow lists. Need to be discussed later
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-disabled-extended").Count.Should().Be(2));
comp.FindAll("div.mud-list-item-disabled-extended")[0].Click();
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().BeNull());
}
[Test]
public async Task MultiSelect_ShouldCallValidationFunc()
{
//await ImproveChanceOfSuccess(async () =>
//{
var comp = Context.Render<MultiSelectTest1>();
// print the generated html
//Console.WriteLine(comp.Markup);
// select elements needed for the test
var select = comp.FindComponent<MudSelectExtended<string>>();
IEnumerable<string?>? validatedValue = null;
select.Render(p => p.Add(x => x.Validation,
new Func<string, bool>(value =>
{
validatedValue = select.Instance.SelectedValues;
return true;
})));
var menu = comp.Find("div.mud-popover");
var input = comp.Find("div.mud-input-control");
// check initial state
select.Instance.GetState(x => x.Value).Should().BeNullOrEmpty();
select.Instance.SelectedValues.Should().BeNullOrEmpty();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));
// click and check if it has toggled the menu
input.Click();
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
comp.WaitForAssertion(() => menu.ClassList.Should().Contain("mud-popover-open"));
// now click an item and see the value change
var items = comp.FindAll("div.mud-list-item-extended").ToArray();
await comp.InvokeAsync(() => items[1].Click());
// menu should still be open now!!
comp.WaitForAssertion(() => menu.ClassList.Should().Contain("mud-popover-open"));
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Text).Should().Be("2"));
comp.WaitForAssertion(() => select.Instance.SelectedValues.Should().Contain("2"));
validatedValue.Should().BeEquivalentTo(new HashSet<string>() { "2" });
items[0].Click();
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Text).Should().Be("2, 1"));
validatedValue.Should().BeEquivalentTo(new HashSet<string>() { "2", "1" });
items[2].Click();
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Text).Should().Be("2, 1, 3"));
validatedValue.Should().BeEquivalentTo(new HashSet<string>() { "2", "1", "3" });
items[0].Click();
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Text).Should().Be("2, 3"));
validatedValue.Should().BeEquivalentTo(new HashSet<string>() { "2", "3" });
//});
}
[Test]
public void MultiSelect_SelectAll()
{
var comp = Context.Render<MultiSelectTest2>();
// select element needed for the test
var select = comp.FindComponent<MudSelectExtended<string>>();
IEnumerable<string?>? validatedValue = null;
select.Render(p => p.Add(x => x.Validation,
(object)new Func<string, bool>(value =>
{
validatedValue = select.Instance.SelectedValues; // NOTE: select does only update the value for T string
return true;
})));
var menu = comp.Find("div.mud-popover");
var input = comp.Find("div.mud-input-control");
// Open the menu
input.Click();
menu.ClassList.Should().Contain("mud-popover-open");
comp.FindAll("div.mud-list-item-extended")[0].Click();
// validate the result. all items should be selected
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Text).Should().Be("FirstA^SecondA^ThirdA"));
validatedValue.Should().BeEquivalentTo(new HashSet<string>() { "FirstA", "SecondA", "ThirdA"});
}
[Test]
public void MultiSelect_SelectAll2()
{
var comp = Context.Render<MultiSelectTest3>();
// select element needed for the test
var select = comp.FindComponent<MudSelectExtended<string>>();
var menu = comp.Find("div.mud-popover");
var input = comp.Find("div.mud-input-control");
// Open the menu
input.Click();
menu.ClassList.Should().Contain("mud-popover-open");
// get the first (select all item) and check if it is indeterminate
var selectAllItem = comp.FindComponent<MudListItemExtended<string>>();
selectAllItem.Instance.Icon.Should().Be(Icons.Material.Filled.IndeterminateCheckBox);
// Check that all normal select items are actually selected
//var items = comp.FindComponents<MudSelectItem<string>>().Where(x=>x.Instance.HideContent==false).ToArray();
//items.Should().HaveCount(7);
//foreach (var item in items)
//{
// item.Instance.IsSelected.Should().BeTrue();
// item.FindComponent<MudListItem<string>>().Instance.Icon.Should().Be("<path d=\"M0 0h24v24H0z\" fill=\"none\"/><path d=\"M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z\"/>");
//}
//// Check shadow items
//var shadowItems = comp.FindComponents<MudSelectItem<string>>().Where(x => x.Instance.HideContent == true).ToArray();
//foreach (var item in shadowItems)
//{
// // shadow items don't render, their state is irrelevant, all they do is provide render fragments to the select
// Assert.Throws<Bunit.Rendering.ComponentNotFoundException>(() => item.FindComponent<MudListItem<string>>());
//}
}
[Test]
public void MultiSelect_SelectAll3()
{
var comp = Context.Render<MultiSelectTest4>();
// select element needed for the test
var select = comp.FindComponent<MudSelectExtended<string>>();
var menu = comp.Find("div.mud-popover");
var input = comp.Find("div.mud-input-control");
// Open the menu
input.Click();
menu.ClassList.Should().Contain("mud-popover-open");
// Check that the icon corresponds to an unchecked checkbox
var mudListItem = comp.FindComponent<MudListItemExtended<string>>();
mudListItem.Instance.Icon.Should().Be("<path d=\"M0 0h24v24H0z\" fill=\"none\"/><path d=\"M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z\"/>");
}
[Test]
public void SingleSelect_Should_CallValidationFunc()
{
var comp = Context.Render<SelectTest1>();
//Console.WriteLine(comp.Markup);
var select = comp.FindComponent<MudSelectExtended<string>>();
string? validatedValue = null;
select.Render(p => p.Add(x => x.Validation,
(object)new Func<string, bool>(value =>
{
validatedValue = value; // NOTE: select does only update the value for T string
return true;
})));
var menu = comp.Find("div.mud-popover");
var input = comp.Find("div.mud-input-control");
// check initial state
select.Instance.GetState(x => x.Value).Should().BeNullOrEmpty();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));
// click and check if it has toggled the menu
input.Click();
menu.ClassList.Should().Contain("mud-popover-open");
// now click an item and see the value change
comp.WaitForAssertion(()=> comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
comp.FindAll("div.mud-list-item-extended")[1].Click();
// menu should be closed now
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().Be("2"));
select.Instance.GetState(x => x.Text).Should().Be("2");
validatedValue.Should().Be("2");
input.Click();
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
comp.FindAll("div.mud-list-item-extended")[0].Click();
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().Be("1"));
select.Instance.GetState(x => x.Text).Should().Be("1");
validatedValue.Should().Be("1");
}
/// <summary>
/// We filled the multiselect with initial selected values, that must
/// show in the value of the input as a comma separated list of strings
/// </summary>
/// <returns></returns>
[Test]
public async Task MultiSelect_Initial_Values()
{
var comp = Context.Render<MultiSelectWithInitialValues>();
// print the generated html
//Console.WriteLine(comp.Markup);
// select the input of the select
var input = comp.Find("input");
//the value of the input
var value = input.Attributes.Where(a => a.LocalName == "value").First().Value;
value.Should().Be("FirstA, SecondA");
}
[Test]
public async Task MultiSelectTextTest()
{
var comp = Context.Render<MultiSelectTextTest>();
var select = comp.FindComponent<MudSelectExtended<int?>>();
await comp.InvokeAsync(() => select.Instance.HandleKeyDownAsync(new KeyboardEventArgs() { Key = "Enter" }));
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().Contain("mud-popover-open"));
var selectItems = comp.FindAll("div.mud-list-item-extended");
foreach (var item in selectItems)
{
item.Click();
}
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Text).Should().Be("Empty, One, 2, 3"));
}
/// <summary>
/// We filled the multiselect with initial selected values.
/// Then the returned text in the selection is customized.
/// </summary>
/// <returns></returns>
[Test]
public async Task MultiSelectCustomizedTextTest()
{
var comp = Context.Render<MultiSelectCustomizedTextTest>();
// Select the input of the select
var input = comp.Find("input");
// The value of the input
var value = input.Attributes.Where(a => a.LocalName == "value").First().Value;
// Value is equal to the customized values returned by the method
value.Should().Be("Selected values: FirstA, SecondA");
}
[Test]
public async Task SelectClearableTest()
{
var comp = Context.Render<SelectClearableTest>();
var select = comp.FindComponent<MudSelectExtended<string>>();
var input = comp.Find("div.mud-input-control");
// No button when initialized
comp.FindAll("button").Should().BeEmpty();
input.Click();
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
// Button shows after selecting item
var items = comp.FindAll("div.mud-list-item-extended").ToArray();
items[1].Click();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().Be("2"));
comp.Find("button").Should().NotBeNull();
// Selection cleared and button removed after clicking clear button
comp.Find("button").MouseDown();
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().BeNullOrEmpty());
comp.FindAll("button").Should().BeEmpty();
// Clear button click handler should have been invoked
comp.Instance.ClearButtonClicked.Should().BeTrue();
}
/// <summary>
/// Reselect an already selected value should not call SelectedValuesChanged event.
/// </summary>
[Test]
public void SelectReselectTest()
{
var comp = Context.Render<ReselectValueTest>();
// print the generated html
//Console.WriteLine(comp.Markup);
// select elements needed for the test
var select = comp.FindComponent<MudSelectExtended<string>>();
var menu = comp.Find("div.mud-popover");
var input = comp.Find("div.mud-input-control");
input.Click();
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
select.Instance.GetState(x => x.Value).Should().Be("Apple");
comp.Instance.ChangeCount.Should().Be(0);
// now click an item and see the value change
var items = comp.FindAll("div.mud-list-item-extended").ToArray();
items[1].Click();
// menu should be closed now
comp.WaitForAssertion(() => menu.ClassList.Should().NotContain("mud-popover-open"));
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().Be("Orange"));
comp.Instance.ChangeCount.Should().Be(1);
// now click an item and see the value change
input.Click();
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
items = comp.FindAll("div.mud-list-item-extended").ToArray();
items[1].Click();
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().Be("Orange"));
comp.Instance.ChangeCount.Should().Be(1);
}
#region DataAttribute validation
//[Test]
//public async Task TextField_Should_Validate_Data_Attribute_Fail()
//{
// var comp = Context.Render<SelectValidationDataAttrTest>();
// //Console.WriteLine(comp.Markup);
// var selectcomp = comp.FindComponent<MudSelectExtended<string>>();
// var select = selectcomp.Instance;
// // Select invalid option
// await comp.InvokeAsync(() => select.SelectOption("Quux"));
// // check initial state
// select.GetState(x => x.Value).Should().Be("Quux");
// select.GetState(x => x.Text).Should().Be("Quux");
// // check validity
// await comp.InvokeAsync(() => select.ValidateAsync());
// select.ValidationErrors.Should().NotBeEmpty();
// select.ValidationErrors.Should().HaveCount(1);
// select.ValidationErrors[0].Should().Be("Should not be longer than 3");
//}
[Test]
public async Task TextField_Should_Validate_Data_Attribute_Success()
{
var comp = Context.Render<SelectValidationDataAttrTest>();
//Console.WriteLine(comp.Markup);
var selectcomp = comp.FindComponent<MudSelectExtended<string>>();
var select = selectcomp.Instance;
// Select valid option
await comp.InvokeAsync(() => select.SelectOption("Qux"));
// check initial state
select.GetState(x => x.Value).Should().Be("Qux");
select.GetState(x => x.Text).Should().Be("Qux");
// check validity
await comp.InvokeAsync(() => select.ValidateAsync());
select.ValidationErrors.Should().BeEmpty();
}
#endregion
/// <summary>
/// Tests the required property.
/// </summary>
[Test]
public async Task Select_Should_SetRequiredTrue()
{
var comp = Context.Render<SelectRequiredTest>();
var select = comp.FindComponent<MudSelectExtended<string>>().Instance;
select.Required.Should().BeTrue();
await comp.InvokeAsync(() => select.ValidateAsync());
select.ValidationErrors.First().Should().Be("Required");
}
/// <summary>
/// Selected option should be hilighted when drop-down opens
/// </summary>
[Test]
public async Task Select_Should_HilightSelectedValue()
{
var comp = Context.Render<SelectTest1>();
// print the generated html
//Console.WriteLine(comp.Markup);
var select = comp.FindComponent<MudSelectExtended<string?>>();
var input = comp.Find("div.mud-input-control");
comp.Find("div.mud-popover").ClassList.Should().Contain("select-popover-class");
select.Instance.GetState(x => x.Value).Should().BeNullOrEmpty();
comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open");
// open the select
comp.Find("div.mud-input-control").Click();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().Contain("mud-popover-open"));
// no option should be hilited
comp.WaitForAssertion(() => comp.FindAll("div.mud-selected-item").Count.Should().Be(0));
// now click an item and see the value change
comp.FindAll("div.mud-list-item-extended")[1].Click();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().Be("2"));
// open again and check hilited option
comp.Find("div.mud-input-control").Click();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().Contain("mud-popover-open"));
// Nr 2 should be hilited
comp.WaitForAssertion(() => comp.FindAll("div.mud-selected-item").Count.Should().Be(1));
comp.FindAll("div.mud-list-item-extended")[1].ToMarkup().Should().Contain("mud-selected-item");
await comp.InvokeAsync(() => select.Instance.CloseMenu());
//select.SetParam(nameof(MudSelectExtended<string?>.Value), null);
select.Render(p => p.Add(x => x.Value, null));
await comp.InvokeAsync(() => select.Instance.OpenMenu());
// no option should be hilited
comp.WaitForAssertion(() => comp.FindAll("div.mud-selected-item").Count.Should().Be(0));
}
/// <summary>
/// Initially selected option should be hilighted when drop-down opens
/// </summary>
[Test]
public void Select_Should_HilightInitiallySelectedValue()
{
var comp = Context.Render<SelectTest2>();
// print the generated html
//Console.WriteLine(comp.Markup);
var select = comp.FindComponent<MudSelectExtended<string>>();
comp.Find("div.mud-popover").ClassList.Should().Contain("select-popover-class");
select.Instance.GetState(x => x.Value).Should().Be("2");
comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open");
// open the select
comp.Find("div.mud-input-control").Click();
//Console.WriteLine(comp.Markup);
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().Contain("mud-popover-open"));
// Nr 2 should be hilited
comp.WaitForAssertion(() => comp.FindAll("div.mud-selected-item").Count.Should().Be(2));
comp.FindAll("div.mud-list-item-extended")[1].ToMarkup().Should().Contain("mud-selected-item");
// now click an item and see the value change
comp.FindAll("div.mud-list-item-extended")[0].Click();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().Be("1"));
// open again and check hilited option
comp.Find("div.mud-input-control").Click();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().Contain("mud-popover-open"));
// Nr 1 should be hilited
comp.WaitForAssertion(() => comp.FindAll("div.mud-selected-item").Count.Should().Be(2));
comp.FindAll("div.mud-list-item-extended")[0].ToMarkup().Should().Contain("mud-selected-item");
comp.Find("div.mud-input-control").Click();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));
}
[Test]
public async Task Select_Should_AllowReloadingItems()
{
var comp = Context.Render<ReloadSelectItemsTest>();
var select = comp.FindComponent<MudSelectExtended<string>>();
// normal, without reloading
comp.Find("div.mud-input-control").Click();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().Contain("mud-popover-open"));
comp.FindAll("div.mud-list-item-extended")[0].Click();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().Be("American Samoa"));
comp.Find("div.mud-input-control").Click();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().Contain("mud-popover-open"));
comp.FindAll("div.mud-list-item-extended")[1].Click();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().Be("Arizona"));
comp.Find("div.mud-input-control").Click();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().Contain("mud-popover-open"));
comp.FindAll("div.mud-list-item-extended")[2].Click();
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));
comp.WaitForAssertion(() => select.Instance.GetState(x => x.Value).Should().Be("Arkansas"));
// reloading!