|
| 1 | +using Bunit; |
| 2 | +using Microsoft.AspNetCore.Components; |
| 3 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 4 | + |
| 5 | +namespace Bit.BlazorUI.Tests.Components.Navs.DropMenu; |
| 6 | + |
| 7 | +[TestClass] |
| 8 | +public class BitDropMenuTests : BunitTestContext |
| 9 | +{ |
| 10 | + [TestMethod] |
| 11 | + public void BitDropMenuShouldRenderRootElement() |
| 12 | + { |
| 13 | + var component = RenderComponent<BitDropMenu>(parameters => |
| 14 | + { |
| 15 | + parameters.Add(p => p.Text, "Menu"); |
| 16 | + }); |
| 17 | + |
| 18 | + var root = component.Find(".bit-drm"); |
| 19 | + var button = component.Find(".bit-drm-btn"); |
| 20 | + |
| 21 | + Assert.IsNotNull(root); |
| 22 | + Assert.IsNotNull(button); |
| 23 | + } |
| 24 | + |
| 25 | + [TestMethod] |
| 26 | + public void BitDropMenuShouldRenderIconAndText() |
| 27 | + { |
| 28 | + var component = RenderComponent<BitDropMenu>(parameters => |
| 29 | + { |
| 30 | + parameters.Add(p => p.IconName, "Home"); |
| 31 | + parameters.Add(p => p.Text, "MenuText"); |
| 32 | + }); |
| 33 | + |
| 34 | + var icon = component.Find(".bit-drm-icn"); |
| 35 | + var text = component.Find(".bit-drm-txt"); |
| 36 | + |
| 37 | + Assert.IsNotNull(icon); |
| 38 | + Assert.IsTrue(icon.ClassList.Contains("bit-icon--Home")); |
| 39 | + Assert.AreEqual("MenuText", text.TextContent); |
| 40 | + } |
| 41 | + |
| 42 | + [TestMethod] |
| 43 | + public void BitDropMenuShouldToggleCalloutOnClick() |
| 44 | + { |
| 45 | + var component = RenderComponent<BitDropMenu>(parameters => |
| 46 | + { |
| 47 | + parameters.Add(p => p.Text, "Menu"); |
| 48 | + parameters.Add(p => p.Body, (RenderFragment)(b => b.AddMarkupContent(0, @"<div class=""body"">BodyContent</div>"))); |
| 49 | + }); |
| 50 | + |
| 51 | + var root = component.Find(".bit-drm"); |
| 52 | + |
| 53 | + var overlay = component.Find(".bit-drm-ovl"); |
| 54 | + Assert.IsTrue(overlay.GetAttribute("style").Contains("display:none")); |
| 55 | + |
| 56 | + var button = component.Find(".bit-drm-btn"); |
| 57 | + button.Click(); |
| 58 | + |
| 59 | + overlay = component.Find(".bit-drm-ovl"); |
| 60 | + Assert.IsTrue(overlay.GetAttribute("style").Contains("display:block")); |
| 61 | + |
| 62 | + overlay.Click(); |
| 63 | + |
| 64 | + overlay = component.Find(".bit-drm-ovl"); |
| 65 | + Assert.IsTrue(overlay.GetAttribute("style").Contains("display:none")); |
| 66 | + } |
| 67 | + |
| 68 | + [TestMethod] |
| 69 | + public void BitDropMenuShouldRespectHtmlAttributes() |
| 70 | + { |
| 71 | + var component = RenderComponent<BitDropMenuHtmlAttributesTest>(); |
| 72 | + |
| 73 | + component.MarkupMatches(@" |
| 74 | +<div data-val-test=""bit"" type=""button"" class=""bit-drm"" tabindex=""0"" id:ignore> |
| 75 | + <button type=""button"" class=""bit-drm-btn""> |
| 76 | + <div class=""bit-drm-txt "">Menu</div> |
| 77 | + <i class=""bit-icon bit-icon--ChevronRight bit-ico-r90""></i> |
| 78 | + </button> |
| 79 | + <div style=""display:none;"" class=""bit-drm-ovl ""></div> |
| 80 | + <div class=""bit-drm-cal bit-drm-end"" id:ignore> |
| 81 | + <div>Body</div> |
| 82 | + </div> |
| 83 | +</div>"); |
| 84 | + |
| 85 | + var markup = component.Markup; |
| 86 | + |
| 87 | + Assert.IsTrue(markup.Contains("data-val-test=\"bit\"")); |
| 88 | + Assert.IsTrue(markup.Contains("bit-drm")); |
| 89 | + Assert.IsTrue(markup.Contains("Body")); |
| 90 | + } |
| 91 | +} |
0 commit comments