Skip to content

Commit 5fe5588

Browse files
authored
feat(blazorui): add BitOverlay tests #4418 (#5305)
1 parent 93ea4bc commit 5fe5588

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System;
2+
using Bunit;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
namespace Bit.BlazorUI.Tests.Overlay;
5+
6+
[TestClass]
7+
public class BitOverlayTests : BunitTestContext
8+
{
9+
10+
[TestMethod]
11+
public void BitOverlayInitialTest()
12+
{
13+
var com = RenderComponent<BitOverlay>();
14+
var element = com.Find(".bit-ovl");
15+
16+
Assert.IsFalse(element.ClassList.Contains("bit-ovl-vis")); //shouldn't be visible when rendered
17+
18+
}
19+
20+
[TestMethod]
21+
public void BitOverlayIsVisibleTest()
22+
{
23+
var isVisible = true;
24+
var com = RenderComponent<BitOverlay>(parameters =>
25+
{
26+
parameters.Bind(p => p.IsVisible, isVisible, value => isVisible = value);
27+
});
28+
29+
var element = com.Find(".bit-ovl");
30+
31+
Assert.IsTrue(element.ClassList.Contains("bit-ovl-vis"));
32+
}
33+
34+
[TestMethod]
35+
public void BitOverlayAutoCloseTest()
36+
{
37+
var isVisible = true;
38+
var com = RenderComponent<BitOverlay>(parameters =>
39+
{
40+
parameters.Bind(p => p.IsVisible, isVisible, value => isVisible = value);
41+
});
42+
43+
var element = com.Find(".bit-ovl");
44+
45+
element.Click();
46+
47+
Assert.IsFalse(element.ClassList.Contains("bit-ovl-vis"));
48+
}
49+
50+
[TestMethod]
51+
public void BitOverlayDisabledAutoCloseTest()
52+
{
53+
var isVisible = true;
54+
var com = RenderComponent<BitOverlay>(parameters =>
55+
{
56+
parameters.Bind(p => p.IsVisible, isVisible, value => isVisible = value);
57+
parameters.Add(p => p.AutoClose, false);
58+
});
59+
60+
var element = com.Find(".bit-ovl");
61+
62+
element.Click();
63+
64+
Assert.IsTrue(element.ClassList.Contains("bit-ovl-vis"));
65+
}
66+
67+
[TestMethod]
68+
public void BitOverlayAbsolutePositionTest()
69+
{
70+
var com = RenderComponent<BitOverlay>(parameters =>
71+
{
72+
parameters.Add(p => p.AbsolutePosition, true);
73+
});
74+
75+
var element = com.Find(".bit-ovl");
76+
77+
Assert.IsTrue(element.ClassList.Contains("bit-ovl-abs"));
78+
}
79+
80+
[TestMethod]
81+
public void BitOverlayAutoToggleScrollTest()
82+
{
83+
Context.JSInterop.Mode = JSRuntimeMode.Loose;
84+
85+
var isVisible = true;
86+
var com = RenderComponent<BitOverlay>(parameters =>
87+
{
88+
parameters.Bind(p => p.IsVisible, isVisible, value => isVisible = value);
89+
});
90+
91+
var element = com.Find(".bit-ovl");
92+
element.Click();
93+
94+
//AutoToggleScroll is false by default so it should invoke "BitOverlay.toggleScroll" once and then once again on closing component
95+
Context.JSInterop.VerifyInvoke("BitOverlay.toggleScroll", 2);
96+
}
97+
98+
}

0 commit comments

Comments
 (0)