示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }