-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathEditorTest.cs
More file actions
94 lines (82 loc) · 2.75 KB
/
EditorTest.cs
File metadata and controls
94 lines (82 loc) · 2.75 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
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/
using Bunit;
namespace UnitTestEditor;
public class EditorTest : BootstrapBlazorTestBase
{
[Fact]
public async Task Editor_Ok()
{
var value = new Foo();
var cut = Context.Render<Editor>(pb =>
{
pb.Add(a => a.Value, value.Name);
pb.Add(a => a.ValueChanged, v => value.Name = v);
pb.Add(a => a.IsEditor, false);
pb.Add(a => a.Height, 200);
});
await cut.InvokeAsync(() => cut.Instance.Update("Test"));
Assert.Equal("Test", value.Name);
cut.Render(pb =>
{
pb.Add(a => a.OnValueChanged, v =>
{
value.Name = v;
return Task.CompletedTask;
});
});
await cut.InvokeAsync(() => cut.Instance.Update("Test1"));
Assert.Equal("Test1", value.Name);
}
[Fact]
public async Task CustomerToolbarButtons_Ok()
{
var cut = Context.Render<Editor>(pb =>
{
pb.Add(a => a.Value, "Test");
pb.Add(a => a.CustomerToolbarButtons, new EditorToolbarButton[]
{
new()
{
ButtonName = "Test1",
IconClass = "Class1",
Tooltip = "Tooltip1"
}
});
});
IEnumerable<object>? buttons = null;
await cut.InvokeAsync(async () => buttons = await cut.Instance.GetToolBar());
Assert.NotNull(buttons);
IEnumerable<EditorToolbarButton>? toolbarButtons = null;
await cut.InvokeAsync(async () => toolbarButtons = await cut.Instance.GetPluginAttributes());
Assert.NotNull(toolbarButtons);
Assert.Single(toolbarButtons);
Assert.Equal("Class1", toolbarButtons!.First().IconClass);
Assert.Equal("Tooltip1", toolbarButtons!.First().Tooltip);
var name = "";
cut.Render(pb =>
{
pb.Add(a => a.OnClickButton, v =>
{
return Task.FromResult("Test");
});
pb.Add(a => a.Value, null);
});
await cut.InvokeAsync(async () => name = await cut.Instance.ClickPluginItem("Test1"));
Assert.Equal("Test", name);
}
[Fact]
public async Task DoMethodAsync_Ok()
{
var cut = Context.Render<Editor>(pb =>
{
pb.Add(a => a.Value, "Test");
});
await cut.Instance.DoMethodAsync("test", ["1"]);
}
class Foo
{
public string? Name { get; set; }
}
}