-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathListboxTests.razor
More file actions
132 lines (111 loc) · 4.27 KB
/
ListboxTests.razor
File metadata and controls
132 lines (111 loc) · 4.27 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
@namespace LumexUI.Tests.Components
@inherits TestContext
@using Microsoft.Extensions.DependencyInjection
@using TailwindMerge
@code {
public ListboxTests()
{
Services.AddSingleton<TwMerge>();
}
[Fact]
public void ShouldRenderCorrectly()
{
var action = () => Render(
@<LumexListbox TValue="string">
<LumexListboxItem>New file</LumexListboxItem>
<LumexListboxItem>Edit file</LumexListboxItem>
<LumexListboxItem>Share file</LumexListboxItem>
<LumexListboxItem>Delete file</LumexListboxItem>
</LumexListbox>
);
action.Should().NotThrow();
}
[Fact]
public void ShouldRenderEmptyContent()
{
var cut = Render(
@<LumexListbox TValue="string" />
);
cut.Find("[data-slot=empty-content]").Should().NotBeNull();
}
[Fact]
public void ShouldRenderItemDescription()
{
var cut = Render(
@<LumexListbox TValue="string">
<LumexListboxItem Description="test">New file</LumexListboxItem>
<LumexListboxItem>Edit file</LumexListboxItem>
<LumexListboxItem>Share file</LumexListboxItem>
<LumexListboxItem>Delete file</LumexListboxItem>
</LumexListbox>
);
cut.Find("li [data-slot=wrapper]").Should().NotBeNull();
}
[Fact]
public void ShouldSelectSingleItem()
{
var selectedValue = "";
var cut = Render<LumexListbox<string>>(
@<LumexListbox @bind-Value="@selectedValue">
<LumexListboxItem Value="@("new")">New file</LumexListboxItem>
<LumexListboxItem Value="@("edit")">Edit file</LumexListboxItem>
<LumexListboxItem Value="@("share")">Share file</LumexListboxItem>
<LumexListboxItem Value="@("delete")">Delete file</LumexListboxItem>
</LumexListbox>
);
var items = cut.FindAll("li");
items[0].Click();
selectedValue.Should().Be("new");
cut.Instance.Value.Should().Be("new");
}
[Fact]
public void ShouldSelectMultipleItems()
{
ICollection<string> selectedValues = [];
var cut = Render<LumexListbox<string>>(
@<LumexListbox @bind-Values="@selectedValues">
<LumexListboxItem Value="@("new")">New file</LumexListboxItem>
<LumexListboxItem Value="@("edit")">Edit file</LumexListboxItem>
<LumexListboxItem Value="@("share")">Share file</LumexListboxItem>
<LumexListboxItem Value="@("delete")">Delete file</LumexListboxItem>
</LumexListbox>
);
var items = cut.FindAll("li");
items[0].Click();
items[1].Click();
selectedValues.Should().HaveCount(2);
selectedValues.Should().Contain("new").And.Contain("edit");
cut.Instance.Values.Should().HaveCount(2);
cut.Instance.Values.Should().Contain("new").And.Contain("edit");
}
[Fact]
public void ShouldThrowWhenValueAndValuesProvided()
{
string selectedValue = "";
ICollection<string> selectedValues = [];
var action = () => Render(
@<LumexListbox @bind-Value="@selectedValue" @bind-Values="@selectedValues">
<LumexListboxItem Value="@("new")">New file</LumexListboxItem>
<LumexListboxItem Value="@("edit")">Edit file</LumexListboxItem>
<LumexListboxItem Value="@("share")">Share file</LumexListboxItem>
<LumexListboxItem Value="@("delete")">Delete file</LumexListboxItem>
</LumexListbox>
);
action.Should().Throw<InvalidOperationException>();
}
[Fact]
public void ShouldNotTriggerItemEventsWhenDisabled()
{
var count = 0;
var cut = Render(
@<LumexListbox TValue="string">
<LumexListboxItem Disabled="@true" OnClick="(() => count++)">New file</LumexListboxItem>
<LumexListboxItem>Edit file</LumexListboxItem>
<LumexListboxItem>Share file</LumexListboxItem>
<LumexListboxItem>Delete file</LumexListboxItem>
</LumexListbox>
);
cut.Find("li").Click();
count.Should().Be(0);
}
}