public async Task AddingAndRemovingTabPanels() { var comp = ctx.RenderComponent <TabsAddingRemovingTabsTest>(); Console.WriteLine(comp.Markup); comp.Find("div.mud-tabs-panels").InnerHtml.Trim().Should().BeEmpty(); comp.FindAll("div.mud-tab").Should().BeEmpty(); // add a panel comp.FindAll("button")[0].Click(); Console.WriteLine("\n" + comp.Markup); comp.Find("div.mud-tabs-panels").InnerHtml.Trim().Should().NotBeEmpty(); comp.FindAll("div.mud-tab").Count.Should().Be(1); comp.FindAll("p.mud-typography").Count.Should().Be(1); // add another comp.FindAll("button")[0].Click(); Console.WriteLine("\n" + comp.Markup); comp.FindAll("div.mud-tab").Count.Should().Be(2); comp.FindAll("p.mud-typography").Count.Should().Be(1, because: "Only the current tab panel is displayed"); // we are now on tab 0 comp.Find("p.mud-typography").TrimmedText().Should().Be("Tab 0"); // switch to tab1 comp.FindAll("div.mud-tab")[1].Click(); comp.Find("p.mud-typography").TrimmedText().Should().Be("Tab 1"); // remove tab1 comp.FindAll("button")[1].Click(); comp.FindAll("div.mud-tab").Count.Should().Be(1); comp.FindAll("p.mud-typography").Count.Should().Be(1); // we should be on tab0 again comp.Find("p.mud-typography").TrimmedText().Should().Be("Tab 0"); // remove another comp.FindAll("button")[1].Click(); comp.Find("div.mud-tabs-panels").InnerHtml.Trim().Should().BeEmpty(); comp.FindAll("div.mud-tab").Should().BeEmpty(); }
public void Basic_Example_of_a_Portaled_Menu() { var comp = ctx.RenderComponent <PortalMenuTest>(); var portalprovider = comp.Find("#mud-portal-container"); //there is already 1 portal; var itemsNumber = portalprovider.GetAttribute("data-items"); itemsNumber.Should().Be("1"); comp.FindAll(".portal-anchor").Should().HaveCount(1); comp.FindAll(".portal").Should().HaveCount(1); //after click the button of the menu, the menu is open comp.Find("button").Click(); //it has 2 popovers, one is what you see, the other is used to make the calculations to //know if it fits the viewport or it needs to be moved inside comp.FindAll(".mud-popover-open").Should().HaveCount(2); //should have 3 items comp.FindAll(".portal-anchor .mud-list-item").Should().HaveCount(3); //clicking in one of them, the popover closes comp.FindAll(".portal-anchor .mud-list-item")[0].Click(); comp.FindAll(".mud-popover-open").Should().HaveCount(0); }
public void MudExpansionPanel_Respects_Collapsing_Order() { var comp = ctx.RenderComponent <ExpansionPanelExpansions>(); //the order in which the panels are going to be clicked //First, the first; then, the third, and then the second var sequence = new List <int> { 0, 2, 1 }; foreach (var item in sequence) { var header = comp.FindAll(".mud-expand-panel-header")[item]; header.Click(); var panels = comp.FindAll(".mud-expand-panel").ToList(); //just the panel that was clicked has the expanded class panels[item].OuterHtml.Should().Contain("mud-panel-expanded"); foreach (var other in sequence.Where(it => it != item)) { //the other panels haven't the class expanded panels[other].OuterHtml.Should().NotContain("mud-panel-expanded"); } } }
public async Task ChipSet_SingleSelection() { var comp = ctx.RenderComponent <ChipSetTest>(); // print the generated html Console.WriteLine(comp.Markup); // select elements needed for the test var chipset = comp.FindComponent <MudChipSet>(); comp.FindAll("div.mud-chip").Count.Should().Be(7); chipset.Instance.SelectedChip.Should().Be(null); comp.FindAll("p")[0].TrimmedText().Should().Be("Nothing selected."); // select cornflakes comp.FindAll("div.mud-chip")[3].Click(); comp.FindAll("p")[0].TrimmedText().Should().Be("Corn flakes"); chipset.Instance.SelectedChip.Text.Should().Be("Corn flakes"); // de-select cornflakes by clicking again comp.FindAll("div.mud-chip")[3].Click(); comp.FindAll("p")[0].TrimmedText().Should().Be("Nothing selected."); chipset.Instance.SelectedChip.Should().Be(null); // select cornflakes comp.FindAll("div.mud-chip")[3].Click(); comp.FindAll("p")[0].TrimmedText().Should().Be("Corn flakes"); chipset.Instance.SelectedChip.Text.Should().Be("Corn flakes"); // select milk comp.FindAll("div.mud-chip")[0].Click(); comp.FindAll("p")[0].TrimmedText().Should().Be("Milk"); chipset.Instance.SelectedChip.Text.Should().Be("Milk"); }
public async Task DefaultValues() { ctx.Services.Add(new ServiceDescriptor(typeof(IResizeObserver), new MockResizeObserver())); var comp = ctx.RenderComponent <MudDynamicTabs>(); var tabs = comp.Instance; tabs.Header.Should().NotBeNull(); tabs.TabPanelHeader.Should().NotBeNull(); tabs.HeaderPosition.Should().Be(TabHeaderPosition.After); tabs.TabPanelHeaderPosition.Should().Be(TabHeaderPosition.After); tabs.AddTabIcon.Should().Be(Icons.Material.Filled.Add); tabs.CloseTabIcon.Should().Be(Icons.Material.Filled.Close); tabs.AddIconClass.Should().BeNullOrEmpty(); tabs.AddIconStyle.Should().BeNullOrEmpty(); tabs.AddIconToolTip.Should().BeNullOrEmpty(); tabs.CloseIconClass.Should().BeNullOrEmpty(); tabs.CloseIconStyle.Should().BeNullOrEmpty(); tabs.CloseIconToolTip.Should().BeNullOrEmpty(); comp.Nodes.Should().ContainSingle(); comp.Nodes[0].Should().BeAssignableTo <IHtmlDivElement>(); (comp.Nodes[0] as IHtmlDivElement).ClassList.Should().BeEquivalentTo(new[] { "mud-tabs", "mud-dynamic-tabs" }); }
public void SelectTest1() { var comp = ctx.RenderComponent <SelectTest1>(); // print the generated html Console.WriteLine(comp.Markup); // select elements needed for the test var select = comp.FindComponent <MudSelect <string> >(); var menu = comp.Find("div.mud-popover"); var input = comp.Find("div.mud-input-control"); // check initial state select.Instance.Value.Should().BeNullOrEmpty(); menu.ClassList.Should().NotContain("mud-popover-open"); // click and check if it has toggled the menu input.Click(); menu.ClassList.Should().Contain("mud-popover-open"); // now click an item and see the value change var items = comp.FindAll("div.mud-list-item").ToArray(); items[1].Click(); // menu should be closed now menu.ClassList.Should().NotContain("mud-popover-open"); select.Instance.Value.Should().Be("2"); // now we cheat and click the list without opening the menu ;) items[0].Click(); select.Instance.Value.Should().Be("1"); }
public void MudHighlighterMarkupTest() { var text = Parameter(nameof(MudHighlighter.Text), TEXT); var highlightedText = Parameter(nameof(MudHighlighter.HighlightedText), "item"); var comp = ctx.RenderComponent <MudHighlighter>(text, highlightedText); comp.MarkupMatches("This is the first <mark>item</mark>"); }
public void OpenMenu_ClickFirstItem_CheckClosed() { var comp = ctx.RenderComponent <MenuTest1>(); comp.FindAll("button.mud-button-root").First().Click(); comp.FindAll("div.mud-list-item").Count().Should().Be(3); comp.FindAll("div.mud-list-item").First().Click(); comp.FindAll("div.mud-popover-open").Count().Should().Be(0); }
public IRenderedComponent <TComponent> RenderComponent <TComponent>(params ComponentParameter[] parameters) where TComponent : IComponent { if (Context == null) { throw new InvalidOperationException("MSTest has not started executing tests yet"); } return(Context.RenderComponent <TComponent>(parameters)); }
public void DebounceInput_should_rendered_initial_value() { var rendered = _testContext.RenderComponent <DebounceInput>(parameters => parameters .Add(p => p.Value, "test")); var input = rendered.Find("input"); Assert.IsNotNull(input); input.MarkupMatches(@"<input value=""test""/>"); }
public void Index_Hellworld_Exist() { //Arr ctx.Services.AddScoped(x => authetificationService.Object); var component = ctx.RenderComponent <Index>(); //Assert Assert.IsTrue(component.Markup.Contains("<h1>Hello, world!</h1>")); }
public void Should_Render_An_Anchor_And_Then_A_Button() { var htmlTag = Parameter(nameof(MudElement.HtmlTag), "a"); var className = Parameter(nameof(MudElement.Class), "mud-button-root"); var comp = ctx.RenderComponent <MudElement>(htmlTag, className); comp.MarkupMatches("<a class=\"mud-button-root\"></a>"); htmlTag = Parameter(nameof(MudElement.HtmlTag), "button"); comp.SetParametersAndRender(htmlTag, className); comp.MarkupMatches("<button class=\"mud-button-root\"></button>"); }
public async Task NavLink_CheckRelAttribute(string target, string expectedRel) { var comp = ctx.RenderComponent <MudNavLink>(new[] { Parameter(nameof(MudNavLink.Target), target), }); // print the generated html Console.WriteLine(comp.Markup); // select elements needed for the test comp.Find("a").GetAttribute("rel").Should().Be(expectedRel); }
public void One_Way_Bindable() { var comp = ctx.RenderComponent <NavMenuOneWay>(); comp.Markup.Should().Contain("expanded"); var navgroup = comp.Find(".mud-nav-group>button"); navgroup.Click(); comp.Markup.Should().NotContain("expanded"); }
public async Task AddingAndRemovingTabPanels() { ctx.Services.Add(new ServiceDescriptor(typeof(IResizeObserver), new MockResizeObserver())); var comp = ctx.RenderComponent <TabsAddingRemovingTabsTest>(); Console.WriteLine(comp.Markup); comp.Find("div.mud-tabs-panels").InnerHtml.Trim().Should().BeEmpty(); comp.FindAll("div.mud-tab").Should().BeEmpty(); comp.Instance.Tabs.Panels.Should().NotBeNull().And.BeEmpty(); // add a panel comp.FindAll("button")[0].Click(); Console.WriteLine("\n" + comp.Markup); comp.Find("div.mud-tabs-panels").InnerHtml.Trim().Should().NotBeEmpty(); comp.FindAll("div.mud-tab").Count.Should().Be(1); comp.FindAll("p.mud-typography").Count.Should().Be(1); comp.Instance.Tabs.Panels.Should().NotBeNull().And.HaveCount(1); comp.FindComponents <MudTabPanel>().First().Instance.Should().Be(comp.Instance.Tabs.Panels[0]); // add another comp.FindAll("button")[0].Click(); Console.WriteLine("\n" + comp.Markup); comp.FindAll("div.mud-tab").Count.Should().Be(2); comp.Instance.Tabs.Panels.Should().NotBeNull().And.HaveCount(2); comp.FindComponents <MudTabPanel>().ElementAt(0).Instance.Should().Be(comp.Instance.Tabs.Panels[0]); comp.FindComponents <MudTabPanel>().ElementAt(1).Instance.Should().Be(comp.Instance.Tabs.Panels[1]); comp.FindAll("p.mud-typography").Count.Should().Be(1, because: "Only the current tab panel is displayed"); // we are now on tab 0 comp.Find("p.mud-typography").TrimmedText().Should().Be("Tab 0"); // switch to tab1 comp.FindAll("div.mud-tab")[1].Click(); comp.Find("p.mud-typography").TrimmedText().Should().Be("Tab 1"); // remove tab1 comp.FindAll("button")[1].Click(); comp.FindAll("div.mud-tab").Count.Should().Be(1); comp.FindAll("p.mud-typography").Count.Should().Be(1); comp.Instance.Tabs.Panels.Should().NotBeNull().And.HaveCount(1); comp.FindComponents <MudTabPanel>().ElementAt(0).Instance.Should().Be(comp.Instance.Tabs.Panels[0]); // we should be on tab0 again comp.Find("p.mud-typography").TrimmedText().Should().Be("Tab 0"); // remove another comp.FindAll("button")[1].Click(); comp.Find("div.mud-tabs-panels").InnerHtml.Trim().Should().BeEmpty(); comp.FindAll("div.mud-tab").Should().BeEmpty(); comp.Instance.Tabs.Panels.Should().NotBeNull().And.BeEmpty(); }
public void MudBreadcrumbs_ShouldRenderItemsWithSeparators() { var comp = ctx.RenderComponent <MudBreadcrumbs>(Parameter("Items", new List <BreadcrumbItem> { new BreadcrumbItem("Link 1", "link1"), new BreadcrumbItem("Link 2", "link2"), new BreadcrumbItem("Link 3", "link3", disabled: true) })); comp.FindAll("li.mud-breadcrumb-item").Should().HaveCount(3); comp.FindAll("li.mud-breadcrumb-separator").Should().HaveCount(2); }
public void TimelineItem_WithoutTimeline_ShouldThrowArgumentNullException() { // Arrange // Act Action action = () => _context.RenderComponent <TimelineItem>(); // Assert action.Should().ThrowExactly <ArgumentNullException>(); }
public void Collapsed_ClickOnArrowButton_CheckClose() { var comp = ctx.RenderComponent <TreeViewTest1>(); Console.WriteLine(comp.Markup); comp.FindAll("li.mud-treeview-item").Count.Should().Be(10); comp.Find("button").Click(); comp.FindAll("li.mud-treeview-item .mud-collapse-container.mud-collapse-entering").Count.Should().Be(1); comp.Find("button").Click(); comp.FindAll("li.mud-treeview-item .mud-collapse-container.mud-collapse-entering").Count.Should().Be(0); comp.Find("div.mud-treeview-item-content").Click(); comp.FindAll("li.mud-treeview-item .mud-collapse-container.mud-collapse-entering").Count.Should().Be(0); }
public void BarcodeComponentTest() { // Arrange string expectedMarkup = "<h3>BlazorBarcode</h3><button class='render'>Click Me</button>"; // Act var cut = Context.RenderComponent <BlazorBarcode2.BlazorBarcode>(); // Assert cut.MarkupMatches(expectedMarkup); }
public void PieChartSelectionTest() { var comp = ctx.RenderComponent <PieExample1>(); // print the generated html Console.WriteLine(comp.Markup); comp.Find("h6").InnerHtml.Trim().Should().Be("Selected portion of the chart: -1"); // now click something and see that the selected index changes: comp.FindAll("path.mud-chart-serie")[0].Click(); comp.Find("h6").InnerHtml.Trim().Should().Be("Selected portion of the chart: 0"); comp.FindAll("path.mud-chart-serie")[3].Click(); comp.Find("h6").InnerHtml.Trim().Should().Be("Selected portion of the chart: 3"); }
public void RenderDateRangePicker_10000_Times_CheckPerformance() { // warmup ctx.RenderComponent <MudDateRangePicker>(); // measure var watch = Stopwatch.StartNew(); for (var i = 0; i < 10000; i++) { ctx.RenderComponent <MudDateRangePicker>(); } watch.Stop(); Console.WriteLine("Elapsed: " + watch.Elapsed); watch.Elapsed.Should().BeLessThan(TimeSpan.FromSeconds(10)); }
public void SelectTest1() { // Click should open the Menu and selecting a value should update the bindable value. // setup using var ctx = new Bunit.TestContext(); ctx.Services.AddSingleton <NavigationManager>(new MockNavigationManager()); var comp = ctx.RenderComponent <SelectTest1>(); // print the generated html Console.WriteLine(comp.Markup); // select elements needed for the test var select = comp.FindComponent <MudSelect <string> >(); var menu = comp.Find("div.mud-popover"); var input = comp.Find("div.mud-input-control"); // check initial state select.Instance.Value.Should().BeNullOrEmpty(); menu.ClassList.Should().NotContain("mud-popover-open"); // click and check if it has toggled the menu input.Click(); menu.ClassList.Should().Contain("mud-popover-open"); // now click an item and see the value change var items = comp.FindAll("div.mud-list-item").ToArray(); items[1].Click(); // menu should be closed now menu.ClassList.Should().NotContain("mud-popover-open"); select.Instance.Value.Should().Be("2"); // now we cheat and click the list without opening the menu ;) items[0].Click(); select.Instance.Value.Should().Be("1"); }
public async Task PerformanceTest1() { using var ctx = new Bunit.TestContext(); ctx.Services.AddSingleton <NavigationManager>(new MockNavigationManager()); // warmup ctx.RenderComponent <DatePickerPerformanceTest>(); // measure var watch = Stopwatch.StartNew(); for (int i = 0; i < 10; i++) { ctx.RenderComponent <DatePickerPerformanceTest>(); } watch.Stop(); Console.WriteLine("Elapsed: " + watch.Elapsed); }
public void CheckBoxTest3() { // there are two checkboxes synced via a bound variable, so checking one also check the other and vice versa. // setup using var ctx = new Bunit.TestContext(); var comp = ctx.RenderComponent <CheckBoxTest3>(); // print the generated html Console.WriteLine(comp.Markup); // select elements needed for the test var boxes = comp.FindComponents <MudCheckBox>(); var inputs = comp.FindAll("input"); // check initial state boxes[0].Instance.Checked.Should().Be(true); boxes[1].Instance.Checked.Should().Be(true); // click and check if it has toggled inputs[0].Change(false); boxes[0].Instance.Checked.Should().Be(false); boxes[1].Instance.Checked.Should().Be(false); inputs = comp.FindAll("input"); inputs[0].Change(true); boxes[0].Instance.Checked.Should().Be(true); boxes[1].Instance.Checked.Should().Be(true); inputs = comp.FindAll("input"); inputs[1].Change(false); boxes[0].Instance.Checked.Should().Be(false); boxes[1].Instance.Checked.Should().Be(false); inputs = comp.FindAll("input"); inputs[1].Change(true); boxes[0].Instance.Checked.Should().Be(true); boxes[1].Instance.Checked.Should().Be(true); }
public async Task ListSelectionTest() { var comp = ctx.RenderComponent <ListSelectionTest>(); Console.WriteLine(comp.Markup); var list = comp.FindComponent <MudList>().Instance; list.SelectedItem.Should().Be(null); // we have seven choices, none is active comp.FindAll("div.mud-list-item").Count.Should().Be(9); // 7 choices, 2 groups comp.FindAll("div.mud-selected-item").Count.Should().Be(0); // click water comp.FindAll("div.mud-list-item")[0].Click(); list.SelectedItem.Text.Should().Be("Sparkling Water"); comp.FindAll("div.mud-selected-item").Count.Should().Be(1); comp.FindComponents <MudListItem>()[0].Markup.Should().Contain("mud-selected-item"); // click Pu'er, a heavily fermented Chinese tea that tastes like an old leather glove comp.FindAll("div.mud-list-item")[4].Click(); list.SelectedItem.Text.Should().Be("Pu'er"); comp.FindAll("div.mud-selected-item").Count.Should().Be(1); comp.FindComponents <MudListItem>()[4].Markup.Should().Contain("mud-selected-item"); // click Cafe Latte comp.FindAll("div.mud-list-item")[8].Click(); list.SelectedItem.Text.Should().Be("Cafe Latte"); comp.FindAll("div.mud-selected-item").Count.Should().Be(1); comp.FindComponents <MudListItem>()[8].Markup.Should().Contain("mud-selected-item"); }
public async Task AlertPage_Test() { var comp = ctx.RenderComponent <Docs.Pages.Components.Alert.AlertPage>(); await ctx.Services.GetService <IRenderQueueService>().WaitUntilEmpty(); System.Console.WriteLine(comp.Markup); }
public void Progress_Should_ConvertValueRangeToPercent() { var comp = ctx.RenderComponent <MudProgressLinear>(x => { x.Add(y => y.Min, -500); x.Add(y => y.Max, 500); x.Add(y => y.Value, -400); x.Add(y => y.BufferValue, 400); }); Console.WriteLine(comp.Markup); // checking range conversion comp.Instance.GetValuePercent().Should().Be(10); comp.Instance.GetBufferPercent().Should().Be(90); // checking cut-off at min and max comp.SetParam(x => x.Min, 0.0); comp.Instance.GetValuePercent().Should().Be(0); comp.SetParam(x => x.Min, -500.0); comp.SetParam(x => x.Max, 0.0); comp.Instance.GetBufferPercent().Should().Be(100); comp.SetParam(x => x.Min, 0.0); comp.SetParam(x => x.Max, 100.0); comp.SetParam(x => x.Value, 100.0); comp.Instance.GetValuePercent().Should().Be(100); comp.SetParam(x => x.Value, -2.0); comp.SetParam(x => x.Min, -7.0); comp.SetParam(x => x.Max, 7.0); comp.SetParam(x => x.Buffer, false); var percent = (-2 - (-7)) / 14.0 * 100; comp.Instance.GetValuePercent().Should().Be(percent); comp.Find("div.mud-progress-linear-bar").MarkupMatches( $"<div class=\"mud-progress-linear-bar mud-default mud-progress-linear-bar-1-determinate\" style=\"transform: translateX(-{Math.Round(100 - percent)}%);\"></div>"); }
public async Task SelectUnrepresentableValueTest2() { using var ctx = new Bunit.TestContext(); ctx.Services.AddSingleton <NavigationManager>(new MockNavigationManager()); var comp = ctx.RenderComponent <SelectUnrepresentableValueTest2>(); // print the generated html Console.WriteLine(comp.Markup); // select elements needed for the test var select = comp.FindComponent <MudSelect <int> >(); select.Instance.Value.Should().Be(17); select.Instance.Text.Should().Be("17"); await Task.Delay(100); // BUT: we have a select with Strict="true" so the Text will not be shown because it is not in the list of selectable values comp.FindComponent <MudInput <string> >().Instance.Value.Should().Be(null); comp.FindComponent <MudInput <string> >().Instance.InputType.Should().Be(InputType.Hidden); var items = comp.FindAll("div.mud-list-item").ToArray(); items[1].Click(); select.Instance.Value.Should().Be(2); select.Instance.Text.Should().Be("2"); comp.FindComponent <MudInput <string> >().Instance.Value.Should().Be("2"); comp.FindComponent <MudInput <string> >().Instance.InputType.Should().Be(InputType.Text); // because list item has no render fragment, so we show it as text }
public async Task SelectWithEnumTest() { // Initial Text should be enums default value // setup using var ctx = new Bunit.TestContext(); ctx.Services.AddSingleton <NavigationManager>(new MockNavigationManager()); var comp = ctx.RenderComponent <SelectWithEnumTest>(); // print the generated html Console.WriteLine(comp.Markup); // select elements needed for the test var select = comp.FindComponent <MudSelect <MyEnum> >(); select.Instance.Value.Should().Be(default(MyEnum)); select.Instance.Text.Should().Be(default(MyEnum).ToString()); await Task.Delay(50); comp.Find("div.mud-input-slot").TextContent.Trim().Should().Be("First"); comp.RenderCount.Should().Be(2); //Console.WriteLine(comp.Markup); var items = comp.FindAll("div.mud-list-item").ToArray(); items[1].Click(); comp.Find("div.mud-input-slot").TextContent.Trim().Should().Be("Second"); comp.RenderCount.Should().Be(3); }
public void TableMultiSelectionTest1() { // the selected items (check-box click or row click) should be in SelectedItems // setup using var ctx = new Bunit.TestContext(); var comp = ctx.RenderComponent <TableMultiSelectionTest1>(); // print the generated html Console.WriteLine(comp.Markup); // select elements needed for the test var table = comp.FindComponent <MudTable <int> >().Instance; var text = comp.FindComponent <MudText>(); var tr = comp.FindAll("tr").ToArray(); tr.Length.Should().Be(3); var td = comp.FindAll("td").ToArray(); td.Length.Should().Be(6); // two td per row for multi selection var inputs = comp.FindAll("input").ToArray(); inputs.Length.Should().Be(3); // one checkbox per row table.SelectedItems.Count.Should().Be(0); // selected items should be empty // click checkboxes and verify selection text inputs[0].Change(true); table.SelectedItems.Count.Should().Be(1); comp.Find("p").TextContent.Should().Be("SelectedItems { 0 }"); inputs = comp.FindAll("input").ToArray(); inputs[0].Change(false); table.SelectedItems.Count.Should().Be(0); comp.Find("p").TextContent.Should().Be("SelectedItems { }"); // row click tr[1].Click(); comp.Find("p").TextContent.Should().Be("SelectedItems { 1 }"); }