public async Task TextField_ShouldNot_ShowRequiredErrorWhenThereIsAConversionError() { var comp = Context.RenderComponent <MudTextField <int?> >(ComponentParameter.CreateParameter("Required", true)); var textfield = comp.Instance; comp.Find("input").Change("A"); comp.Find("input").Blur(); textfield.Text.Should().Be("A"); textfield.HasErrors.Should().Be(true); textfield.ErrorText.Should().Be("Not a valid number"); }
public async Task TextField_Should_HaveCorrectMessageWithCustomAttr_Failing() { var model = new TestFailingModel(); var comp = Context.RenderComponent <MudTextField <string> >(ComponentParameter.CreateParameter("For", (Expression <Func <string> >)(() => model.Foo))); await comp.InvokeAsync(() => comp.Instance.Validate()); comp.Instance.Error.Should().BeTrue(); comp.Instance.ValidationErrors.Should().HaveCount(1); comp.Instance.ValidationErrors[0].Should().Be("TEST ERROR"); comp.Instance.GetErrorText().Should().Be("TEST ERROR"); }
public IRenderedComponent <TComponent> GetComponent <TComponent>(Dictionary <string, object> parameters = null) where TComponent : IComponent { var componentParameters = (parameters ?? new Dictionary <string, object>()) .Select(p => ComponentParameter.CreateParameter(p.Key, p.Value)) .ToList(); componentParameters.Add(CascadingValue(Task.FromResult(new AuthenticationState(TestContext.AuthenticatedUser)))); return(_hostContext.RenderComponent <TComponent>(componentParameters.ToArray())); }
public IComponentBuilder <TComponent> RenderFragment( Expression <Func <TComponent, RenderFragment> > expression, Action <RenderFragmentBuilder> renderFragmentBuilder ) { var propertyName = GetPropertyName(expression); var builder = new RenderFragmentBuilder(); renderFragmentBuilder(builder); _componentParameters.Add(ComponentParameter.CreateParameter(propertyName, builder.ToRenderFragment())); return(this); }
public void Open_FixDay_ClickYear_Click2ndMonth_CheckDate() { var comp = OpenPicker(ComponentParameter.CreateParameter("FixDay", 1)); comp.Find("div.mud-picker-datepicker-toolbar > button.mud-button-year").Click(); comp.FindAll("div.mud-picker-calendar-container > div.mud-picker-year-container").Count.Should().Be(1); comp.FindAll("div.mud-picker-calendar-container > div.mud-picker-year-container > div.mud-picker-year") .Where(x => x.TrimmedText().Contains("2022")).First().Click(); comp.FindAll("div.mud-picker-month-container").Count.Should().Be(1); comp.FindAll("div.mud-picker-calendar-container > div.mud-picker-month-container > button.mud-picker-month")[1].Click(); comp.Instance.Date.Value.Date.Should().Be(new DateTime(2022, 2, 1)); }
public void CheckBoxTriStateTest() { var comp = Context.RenderComponent <MudCheckBox <bool?> >(ComponentParameter.CreateParameter("TriState", true)); // print the generated html Console.WriteLine(comp.Markup); // select elements needed for the test var box = comp.Instance; var input = comp.Find("input"); // check initial state box.Checked.Should().Be(default);
public void Numeric_UpDown_NotRenderedIfHidden() { using var ctx = new TestContext(); var component = ctx.RenderComponent <RadzenNumeric <double> >(ComponentParameter.CreateParameter(nameof(RadzenNumeric <double> .ShowUpDown), false)); component.Render(); Assert.DoesNotContain(@$ "rz-spinner-button-icon", component.Markup); Assert.DoesNotContain(@$ "rz-spinner-up", component.Markup); Assert.DoesNotContain(@$ "rz-spinner-down", component.Markup); }
public IComponentBuilder <TComponent> EventCallback <T>( Expression <Func <TComponent, EventCallback <T> > > expression, Func <T, Task> callback ) { var propertyName = GetPropertyName(expression); _componentParameters.Add( ComponentParameter.CreateParameter(propertyName, EC.Factory.Create(null, callback)) ); return(this); }
public void CodeBlock_Test() { var mockJs = Services.AddMockJSRuntime(); mockJs.SetupVoid("blazorMonaco.editor.create"); var component = RenderComponent <CodeBlock> ( ComponentParameter.CreateParameter(nameof(CodeBlock.Value), "{'test': 'json'}"), ComponentParameter.CreateParameter(nameof(CodeBlock.Language), CodeLanguage.Unspecified) ); Assert.Equal(1, mockJs.Invocations.Count); }
public void SelectListComponentRendersCorrectly() { ValuesDictionary.Add("test", "test"); ComponentParameter[] parameters = { ComponentParameter.CreateParameter("ValuesDictionary", ValuesDictionary), ComponentParameter.CreateParameter("Name", "test") }; var cut = RenderComponent <SelectListComponent>(parameters); cut.MarkupMatches(@"<div class=""input-group pt-1"" data-target-input=""nearest""> <select class=""form-control""> <option>Select test</option> <option value=""test"">test</option> </select> </div>"); }
public async Task NumericFieldWithNullableTypes() { var comp = ctx.RenderComponent <MudNumericField <int?> >(ComponentParameter.CreateParameter("Value", 17)); // print the generated html Console.WriteLine(comp.Markup); comp.SetParametersAndRender(ComponentParameter.CreateParameter("Value", null)); comp.Find("input").Blur(); comp.FindAll("div.mud-input-error").Count.Should().Be(0); comp.Find("input").Change(""); comp.Find("input").Blur(); comp.FindAll("div.mud-input-error").Count.Should().Be(0); }
public void Open_FixYear_Click2ndMonth_Click3_CheckDate() { var comp = OpenPicker(ComponentParameter.CreateParameter("FixYear", 2021)); comp.FindAll("div.mud-picker-datepicker-toolbar > button.mud-button-year").Count.Should().Be(0); comp.Find("div.mud-picker-calendar-container > .mud-picker-calendar-header > .mud-picker-calendar-header-switch > .mud-button-month").Click(); comp.FindAll("div.mud-picker-month-container").Count.Should().Be(1); comp.FindAll("div.mud-picker-calendar-container > div.mud-picker-month-container > button.mud-picker-month")[1].Click(); comp.FindAll("div.mud-picker-calendar-container > div.mud-picker-calendar-header").Count.Should().Be(1); comp.FindAll("button.mud-picker-calendar-day") .Where(x => x.TrimmedText().Equals("3")).First().Click(); comp.Instance.Date.Value.Date.Should().Be(new DateTime(2021, 2, 3)); }
public async Task when_updating_status_the_status_should_be_changed_in_component() { var starpointsItem = CreateStarpointsItem(); Authorize(starpointsItem, false); MockHttp.Expect($"http://localhost/StarpointsManager/UpdateValidationStatus/-1/{starpointsItem.Id}/{ValidationState.Validated}").Respond(HttpStatusCode.OK); var component = CreateComponent(ComponentParameter.CreateParameter("Item", starpointsItem)); component.WaitForState(() => component.Nodes?.Length > 0); await component.Instance.UpdateState(ValidationState.Validated); starpointsItem.ValidationState.Should().Be(ValidationState.Validated); }
public void Should_DisplayUserLogin_When_IdIsPresent() { //Arrange var user = _fixture.Create <UserModel>(); _userService.Setup(service => service.Get(It.IsAny <string>())).Returns(Task.FromResult(user)); var userDetail = RenderComponent <UserDetail>(ComponentParameter.CreateParameter("Id", "test")); // Act var title = userDetail.Find("h2"); // Assert title.MarkupMatches($"<h2><span>User</span> [<b>{user.Login}</b>]</h2>"); }
public void Should_DisplayCountry_When_IdIsPresent() { //Arrange var country = _fixture.Create <CountryModel>(); _countryService.Setup(service => service.Get(It.IsAny <string>())).Returns(Task.FromResult(country)); var countryDetail = RenderComponent <CountryDetail>(ComponentParameter.CreateParameter("Id", 1)); // Act var title = countryDetail.Find("h2"); // Assert title.MarkupMatches($"<h2><span>Country</span>{country.Id}</h2>"); }
public void Should_DisplayJob_When_IdIsPresent() { //Arrange var job = _fixture.Create <JobModel>(); _jobService.Setup(service => service.Get(It.IsAny <string>())).Returns(Task.FromResult(job)); var jobDetail = RenderComponent <JobDetail>(ComponentParameter.CreateParameter("Id", 1)); // Act var title = jobDetail.Find("h2"); // Assert title.MarkupMatches($"<h2><span>Job</span>{job.Id}</h2>"); }
public void Should_DisplayPieceOfWork_When_IdIsPresent() { //Arrange var pieceofwork = _fixture.Create <PieceOfWorkModel>(); _pieceofworkService.Setup(service => service.Get(It.IsAny <string>())).Returns(Task.FromResult(pieceofwork)); var pieceofworkDetail = RenderComponent <PieceOfWorkDetail>(ComponentParameter.CreateParameter("Id", 1)); // Act var title = pieceofworkDetail.Find("h2"); // Assert title.MarkupMatches($"<h2><span>PieceOfWork</span>{pieceofwork.Id}</h2>"); }
public async Task TextField_Should_HaveCorrectMessageWithCustomAttr_Override_Failing() { TestFailingModel model = new TestFailingModel2(); var comp = Context.RenderComponent <MudTextField <string> >( ComponentParameter.CreateParameter("For", (Expression <Func <string> >)(() => (model as TestFailingModel2).Foo)) //ComponentParameter.CreateParameter("ForModel", typeof(TestFailingModel2)) // Explicitly set the `For` class ); await comp.InvokeAsync(() => comp.Instance.Validate()); comp.Instance.Error.Should().BeTrue(); comp.Instance.ValidationErrors.Should().HaveCount(1); comp.Instance.ValidationErrors[0].Should().Be("Bar"); comp.Instance.GetErrorText().Should().Be("Bar"); }
public void Should_DisplayEmployee_When_IdIsPresent() { //Arrange var employee = _fixture.Create <EmployeeModel>(); _employeeService.Setup(service => service.Get(It.IsAny <string>())).Returns(Task.FromResult(employee)); var employeeDetail = RenderComponent <EmployeeDetail>(ComponentParameter.CreateParameter("Id", 1)); // Act var title = employeeDetail.Find("h2"); // Assert title.MarkupMatches($"<h2><span>Employee</span>{employee.Id}</h2>"); }
public void Should_DisplayLocation_When_IdIsPresent() { //Arrange var location = _fixture.Create <LocationModel>(); _locationService.Setup(service => service.Get(It.IsAny <string>())).Returns(Task.FromResult(location)); var locationDetail = RenderComponent <LocationDetail>(ComponentParameter.CreateParameter("Id", 1)); // Act var title = locationDetail.Find("h2"); // Assert title.MarkupMatches($"<h2><span>Location</span>{location.Id}</h2>"); }
public void Should_DisplayDepartment_When_IdIsPresent() { //Arrange var department = _fixture.Create <DepartmentModel>(); _departmentService.Setup(service => service.Get(It.IsAny <string>())).Returns(Task.FromResult(department)); var departmentDetail = RenderComponent <DepartmentDetail>(ComponentParameter.CreateParameter("Id", 1)); // Act var title = departmentDetail.Find("h2"); // Assert title.MarkupMatches($"<h2><span>Department</span>{department.Id}</h2>"); }
public void Renders_Label_ForPropertyWithDisplayAttributeAndAdditionalAttributes() { // Arrange Expression <Func <string> > For = () => _model.First; var parameters = new[] { ComponentParameter.CreateParameter("For", For), ComponentParameter.CreateParameter("class", "c") }; // Act var component = RenderComponent <LabelText <string> >(parameters); // Assert Assert.Equal("<label class=\"c\">my_value</label>", component.Find("label").OuterHtml); // Verify _stringLocalizerMock.Verify(localizer => localizer["Person_First"], Times.Once); }
public void Timeline_Title_ShouldRenderWithTitle() { // Arrange const string expectedTitle = "Test Title"; // Act var timeline = _context.RenderComponent <Timeline>( ComponentParameter.CreateParameter(nameof(Timeline.Title), expectedTitle) ); // Assert var container = timeline.Find("div"); var projectTitle = container.GetElementsByTagName("h1"); projectTitle.Should().HaveCount(1); projectTitle[0].Text().Should().Be(expectedTitle); }
public async Task NumericFieldUpdateLoopProtectionTest() { var comp = ctx.RenderComponent <MudNumericField <int> >(); // these conversion funcs are nonsense of course, but they are designed this way to // test against an infinite update loop that numericFields and other inputs are now protected against. var numericField = comp.Instance; numericField.Converter.SetFunc = s => s.ToString(); numericField.Converter.GetFunc = s => int.Parse(s); comp.SetParametersAndRender(ComponentParameter.CreateParameter("Value", 1)); numericField.Value.Should().Be(1); numericField.Text.Should().Be("1"); comp.Find("input").Change("3"); numericField.Value.Should().Be(3); numericField.Text.Should().Be("3"); }
public void CheckBoxTest2() { var comp = Context.RenderComponent <MudCheckBox <bool> >(ComponentParameter.CreateParameter("Checked", true)); //Console.WriteLine(comp.Markup); // select elements needed for the test var box = comp.Instance; var input = comp.Find("input"); // check initial state box.Checked.Should().Be(true); // click and check if it has toggled input.Change(false); box.Checked.Should().Be(false); input.Change(true); box.Checked.Should().Be(true); }
public async Task TextFieldUpdateLoopProtectionTest() { var comp = Context.RenderComponent <MudTextField <string> >(); // these conversion funcs are nonsense of course, but they are designed this way to // test against an infinite update loop that textfields and other inputs are now protected against. var textfield = comp.Instance; textfield.Converter.SetFunc = s => $"{s}x"; textfield.Converter.GetFunc = s => $"{s}y"; comp.SetParametersAndRender(ComponentParameter.CreateParameter("Value", "A")); textfield.Value.Should().Be("A"); textfield.Text.Should().Be("Ax"); comp.Find("input").Change("B"); textfield.Value.Should().Be("By"); textfield.Text.Should().Be("B"); }
public void Numeric_Formatted() { using var ctx = new TestContext(); double valueToTest = 100.234; string format = "0.00"; var component = ctx.RenderComponent <RadzenNumeric <double> >( ComponentParameter.CreateParameter(nameof(RadzenNumeric <double> .Format), format), ComponentParameter.CreateParameter(nameof(RadzenNumeric <double> .Value), valueToTest) ); component.Render(); Assert.Contains($" value=\"{valueToTest.ToString(format)}\"", component.Markup); }
public async Task TextFieldWithNullableTypes() { var comp = ctx.RenderComponent <MudTextField <int?> >(ComponentParameter.CreateParameter("Value", 17)); // print the generated html Console.WriteLine(comp.Markup); var textfield = comp.Instance; await comp.InvokeAsync(() => textfield.Value = null); comp.Find("input").Blur(); comp.FindAll("div.mud-input-error").Count.Should().Be(0); await comp.InvokeAsync(() => textfield.Text = ""); comp.Find("input").Blur(); comp.FindAll("div.mud-input-error").Count.Should().Be(0); }
public async Task when_suppressing_item_if_the_pop_up_retrieve_no_the_item_should_not_be_suppressed() { ConfirmDisplayer.Setup(x => x.Confirm(It.IsAny <string>(), It.IsAny <string>())).Returns(Task.Factory.StartNew(() => false)); bool hasCallRemoveCallback = false; var removeItemEventCallBack = EventCallbackFactory.Create <StarpointsItem>(new object(), _ => hasCallRemoveCallback = true); var starpointsItem = CreateStarpointsItem(); Authorize(starpointsItem, false); var component = CreateComponent(ComponentParameter.CreateParameter("Item", starpointsItem) , ComponentParameter.CreateParameter("PleaseRemoveItem", removeItemEventCallBack)); component.WaitForState(() => component.Nodes?.Length > 0); await component.Instance.CancelItem(); await Task.Delay(30); hasCallRemoveCallback.Should().BeFalse(); }
public async Task when_updating_status_the_update_status_api_method_should_be_called() { ConfirmDisplayer.Setup(x => x.Confirm(It.IsAny <string>(), It.IsAny <string>())).Returns(Task.Factory.StartNew(() => true)); var removeItemEventCallBack = EventCallbackFactory.Create <StarpointsItem>(new object(), _ => { }); var starpointsItem = CreateStarpointsItem(); MockHttp.Expect($"http://localhost/StarpointsManager/CancelStarpoints/-1/{starpointsItem.Id}").Respond(HttpStatusCode.OK); Authorize(starpointsItem, false); var component = CreateComponent(ComponentParameter.CreateParameter("Item", starpointsItem) , ComponentParameter.CreateParameter("PleaseRemoveItem", removeItemEventCallBack)); component.WaitForState(() => component.Nodes?.Length > 0); await component.Instance.CancelItem(); await Task.Delay(30); MockHttp.VerifyNoOutstandingExpectation(); }