public void ChangingValueOnModelUpdatesDisplayedValue() { const string newTitle = "New Title"; var model = new NodeModel { Title = "" }; var field = new ModelPropertyField <string>(null, model, nameof(NodeModel.Title), null); var inputField = field.SafeQ <BaseField <string> >(null, BaseField <string> .ussClassName); Assert.AreNotEqual(newTitle, model.Title); Assert.AreNotEqual(newTitle, inputField.value); model.Title = newTitle; field.UpdateDisplayedValue(); Assert.AreEqual(model.Title, inputField.value); }
public void SettingValueOnFieldTriggersOnValueChanged() { const string newTitle = "New Title"; var model = new NodeModel { Title = "" }; bool callbackCalled = false; var field = new ModelPropertyField <string>(null, model, nameof(NodeModel.Title), null, (v, f) => callbackCalled = true); Window.rootVisualElement.Add(field); var inputField = field.SafeQ <BaseField <string> >(null, BaseField <string> .ussClassName); Assert.AreNotEqual(newTitle, model.Title); Assert.AreNotEqual(newTitle, inputField.value); inputField.value = newTitle; Assert.IsTrue(callbackCalled); }
public void ProvidedValueGetterIsUsed() { const string newTitle = "New Title"; const string overriddenTitle = "42"; var model = new NodeModel { Title = "" }; var field = new ModelPropertyField <string>(null, model, nameof(NodeModel.Title), null, (Action <string, ModelPropertyField <string> >)null, elementModel => overriddenTitle); var inputField = field.SafeQ <BaseField <string> >(null, BaseField <string> .ussClassName); Assert.AreNotEqual(newTitle, model.Title); Assert.AreNotEqual(newTitle, inputField.value); Assert.AreNotEqual(overriddenTitle, model.Title); Assert.AreNotEqual(overriddenTitle, inputField.value); model.Title = newTitle; field.UpdateDisplayedValue(); Assert.AreEqual(overriddenTitle, inputField.value); }
public void SettingValueOnFieldDispatchesCommand() { const string newTitle = "New Title"; var model = new NodeModel { Title = "" }; var commandDispatcher = new TestDispatcher(); var field = new ModelPropertyField <string>(commandDispatcher, model, nameof(NodeModel.Title), null, typeof(TestCommand)); Window.rootVisualElement.Add(field); var inputField = field.SafeQ <BaseField <string> >(null, BaseField <string> .ussClassName); Assert.AreNotEqual(newTitle, model.Title); Assert.AreNotEqual(newTitle, inputField.value); Assert.AreNotEqual(typeof(TestCommand), TestDispatcher.LastDispatchedCommandType); inputField.value = newTitle; Assert.AreEqual(typeof(TestCommand), TestDispatcher.LastDispatchedCommandType); }