public void Focus_specified_field_after_changing_FormDefinition() { var view = new NZazuView { FormDefinition = new FormDefinition { Fields = new[] { new FieldDefinition { Key = "other", Type = "string" }, new FieldDefinition { Key = "focus", Type = "string" } } }, FormData = new FormData { Values = { { "__focusOn", "focus" } } } }; var otherCtrl = view.GetField("other").ValueControl; var keyCtrl = view.GetField("focus").ValueControl; view.TrySetFocusOn().Should().BeTrue(); otherCtrl.IsFocused.Should().BeFalse(); keyCtrl.IsFocused.Should().BeTrue(); view.TrySetFocusOn("other", true).Should().BeTrue(); keyCtrl.IsFocused.Should().BeFalse(); otherCtrl.IsFocused.Should().BeTrue(); }
public void Throw_KeyNotFoundException_On_GetField_For_Wrong_Key() { const string key = "key"; const string value = "value"; var fieldDefinition = new FieldDefinition { Key = key, Type = "string", Prompt = "Name" }; var field = Substitute.For <INZazuWpfField>(); field.Key.Returns(key); var formDefinition = new FormDefinition { Fields = new[] { fieldDefinition } }; var formData = new FormData(new Dictionary <string, string> { { key, value } }); var factory = Substitute.For <INZazuWpfFieldFactory>(); factory.CreateField(fieldDefinition).Returns(field); var sut = new NZazuView { FormDefinition = formDefinition, FormData = formData, FieldFactory = factory }; new Action(() => sut.GetField("I do not exist")).Invoking(a => a()).Should().Throw <KeyNotFoundException>(); }
public void Update_FormData_On_LostFocus() { var view = new NZazuView(); const string key = "key"; const string value = "value"; var formDefinition = new FormDefinition { Fields = new[] { new FieldDefinition { Key = key, Type = "string" } } }; view.FormDefinition = formDefinition; var values = new Dictionary <string, string> { { key, value } }; view.FormData = values; view.FormData.Values.Should().BeEquivalentTo(values); // simulate user editing const string changedValue = "other"; view.GetField(key).SetValue(changedValue); // simulate user leaves the field -> LostFoucs view.RaiseEvent(new RoutedEventArgs(UIElement.LostFocusEvent)); // verify (bound) FormData has been updated, so thumbs up for binding experience view.FormData.Values[key].Should().Be(changedValue); }
public void Support_IsReadOnly() { var sut = new NZazuView { FieldFactory = new NZazuFieldFactory(), FormDefinition = new FormDefinition { Fields = new[] { new FieldDefinition { Key = "1", Type = "label" }, new FieldDefinition { Key = "2", Type = "string" }, new FieldDefinition { Key = "3", Type = "date" }, new FieldDefinition { Key = "4", Type = "bool" }, new FieldDefinition { Key = "5", Type = "double" }, new FieldDefinition { Key = "6", Type = "int" } } } }; sut.IsReadOnly.Should().BeFalse(); sut.IsReadOnly = true; var controls = sut.FormDefinition.Fields.Select(f => sut.GetField(f.Key)); controls.All(c => c.IsReadOnly()).Should().BeTrue(); }