|
| 1 | +using Bunit; |
| 2 | +using Microsoft.AspNetCore.Components; |
| 3 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 4 | + |
| 5 | +namespace Bit.BlazorUI.Tests.Components.Surfaces.Splitter; |
| 6 | + |
| 7 | +[TestClass] |
| 8 | +public class BitSplitterTests : BunitTestContext |
| 9 | +{ |
| 10 | + [TestMethod] |
| 11 | + public void BitSplitterShouldRenderExpectedElement() |
| 12 | + { |
| 13 | + var component = RenderComponent<BitSplitter>(); |
| 14 | + |
| 15 | + component.MarkupMatches(@" |
| 16 | +<div class=""bit-spl"" id:ignore> |
| 17 | + <div class=""bit-spl-pnl bit-spl-fpn""> |
| 18 | + </div> |
| 19 | + <div class=""bit-spl-gtr""> |
| 20 | + <div class=""bit-spl-gti""> |
| 21 | + </div> |
| 22 | + </div> |
| 23 | + <div class=""bit-spl-pnl bit-spl-spn""> |
| 24 | + </div> |
| 25 | +</div>"); |
| 26 | + } |
| 27 | + |
| 28 | + [TestMethod] |
| 29 | + public void BitSplitterShouldRespectGutterSizeStyle() |
| 30 | + { |
| 31 | + var gutter = 20; |
| 32 | + var component = RenderComponent<BitSplitter>(parameters => |
| 33 | + { |
| 34 | + parameters.Add(p => p.GutterSize, gutter); |
| 35 | + }); |
| 36 | + |
| 37 | + var root = component.Find(".bit-spl"); |
| 38 | + var style = root.GetAttribute("style"); |
| 39 | + |
| 40 | + Assert.IsNotNull(style); |
| 41 | + Assert.IsTrue(style.Contains($"--gutter-size:{gutter}px")); |
| 42 | + } |
| 43 | + |
| 44 | + [TestMethod] |
| 45 | + public void BitSplitterShouldRenderGutterIconWhenProvided() |
| 46 | + { |
| 47 | + var iconName = "GripperDotsVertical"; |
| 48 | + var component = RenderComponent<BitSplitter>(parameters => |
| 49 | + { |
| 50 | + parameters.Add(p => p.GutterIcon, iconName); |
| 51 | + }); |
| 52 | + |
| 53 | + var icon = component.Find(".bit-spl .bit-icon"); |
| 54 | + |
| 55 | + Assert.IsTrue(icon.ClassList.Contains($"bit-icon--{iconName}")); |
| 56 | + } |
| 57 | + |
| 58 | + [TestMethod] |
| 59 | + public void BitSplitterShouldRespectVerticalClass() |
| 60 | + { |
| 61 | + var component = RenderComponent<BitSplitter>(parameters => |
| 62 | + { |
| 63 | + parameters.Add(p => p.Vertical, true); |
| 64 | + }); |
| 65 | + |
| 66 | + var root = component.Find(".bit-spl"); |
| 67 | + Assert.IsTrue(root.ClassList.Contains("bit-spl-vrt")); |
| 68 | + } |
| 69 | + |
| 70 | + [TestMethod] |
| 71 | + public void BitSplitterShouldRenderPanelSizesAsCssVariables() |
| 72 | + { |
| 73 | + var component = RenderComponent<BitSplitter>(parameters => |
| 74 | + { |
| 75 | + parameters.Add(p => p.FirstPanelSize, 128); |
| 76 | + parameters.Add(p => p.FirstPanelMaxSize, 256); |
| 77 | + parameters.Add(p => p.FirstPanelMinSize, 64); |
| 78 | + |
| 79 | + parameters.Add(p => p.SecondPanelSize, 200); |
| 80 | + parameters.Add(p => p.SecondPanelMaxSize, 300); |
| 81 | + parameters.Add(p => p.SecondPanelMinSize, 100); |
| 82 | + }); |
| 83 | + |
| 84 | + var root = component.Find(".bit-spl"); |
| 85 | + var style = root.GetAttribute("style"); |
| 86 | + |
| 87 | + Assert.IsNotNull(style); |
| 88 | + Assert.IsTrue(style.Contains("--first-panel:128px")); |
| 89 | + Assert.IsTrue(style.Contains("--first-panel-max:256px")); |
| 90 | + Assert.IsTrue(style.Contains("--first-panel-min:64px")); |
| 91 | + |
| 92 | + Assert.IsTrue(style.Contains("--second-panel:200px")); |
| 93 | + Assert.IsTrue(style.Contains("--second-panel-max:300px")); |
| 94 | + Assert.IsTrue(style.Contains("--second-panel-min:100px")); |
| 95 | + } |
| 96 | + |
| 97 | + [TestMethod] |
| 98 | + public void BitSplitterShouldRenderChildContentInPanels() |
| 99 | + { |
| 100 | + RenderFragment first = builder => builder.AddContent(0, "First Panel Content"); |
| 101 | + RenderFragment second = builder => builder.AddContent(0, "Second Panel Content"); |
| 102 | + |
| 103 | + var component = RenderComponent<BitSplitter>(parameters => |
| 104 | + { |
| 105 | + parameters.Add(p => p.FirstPanel, first); |
| 106 | + parameters.Add(p => p.SecondPanel, second); |
| 107 | + }); |
| 108 | + |
| 109 | + var firstPanel = component.Find(".bit-spl-fpn"); |
| 110 | + var secondPanel = component.Find(".bit-spl-spn"); |
| 111 | + |
| 112 | + Assert.IsTrue(firstPanel.TextContent.Contains("First Panel Content")); |
| 113 | + Assert.IsTrue(secondPanel.TextContent.Contains("Second Panel Content")); |
| 114 | + } |
| 115 | +} |
0 commit comments