-
Notifications
You must be signed in to change notification settings - Fork 9
/
ListboxTests.razor
77 lines (55 loc) · 2.07 KB
/
ListboxTests.razor
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
@inherits TestContext
@code
{
[Fact]
public void Button_OnClick()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
JSInterop.Mode = JSRuntimeMode.Loose;
var cut = Render(@<Listbox TValue="object">
<ListboxButton>
</ListboxButton>
</Listbox>);
cut.Find("button").Click();
var listbox = cut.FindComponent<Listbox<object>>();
Assert.True(listbox.Instance.IsOpen);
cut.Find("button").Click();
Assert.False(listbox.Instance.IsOpen);
}
[Fact]
public void Button_OnClick_PreventDefault()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
JSInterop.Mode = JSRuntimeMode.Loose;
var cut = Render(@<Listbox TValue="object">
<ListboxButton OnClick="e => e.PreventDefault()">
</ListboxButton>
</Listbox>);
cut.Find("button").Click();
var listbox = cut.FindComponent<Listbox<object>>();
Assert.False(listbox.Instance.IsOpen);
}
[Fact]
public async Task ListboxInDialog()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
JSInterop.Mode = JSRuntimeMode.Loose;
const string openButtonId = "open-button";
const string listboxButtonId = "listbox-button";
const string intOptionId = nameof(Int32);
var cut = Render(@<ListboxInDialogTest></ListboxInDialogTest>);
var openButton = cut.Find($"#{openButtonId}");
openButton.Click();
await Task.Delay(400);
var listboxButton = cut.Find($"#{listboxButtonId}");
listboxButton.Click();
var intOption = cut.Find($"#{intOptionId}");
intOption.Click();
await Task.Delay(200);
var listbox = cut.FindComponent<Listbox<Type>>();
Assert.Equal(typeof(int), listbox.Instance.Value);
}
}