From 0b4b54ffbf07693fb352ff90db8858fbecd3a746 Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Sun, 18 Jun 2017 18:38:00 -0700 Subject: [PATCH] Add Button Type Fixes #12 --- .vscode/tasks.json | 23 ++++++++++++++++++++++- Ooui/Button.cs | 20 ++++++++++++++++++++ Tests/ButtonTests.cs | 11 +++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 1aa7b34..18c0baf 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -18,7 +18,28 @@ "${workspaceRoot}/Tests/Tests.csproj" ], "isTestCommand": true, - "problemMatcher": "$msCompile" + "problemMatcher": { + "owner": "external", + "fileLocation": "absolute", + "severity": "error", + "pattern": [ + { + "regexp": "^Error Message:\\s*$" + }, + { + "regexp": "^\\s*(.*)$", + "message": 1 + }, + { + "regexp": "^Stack Trace:\\s*$" + }, + { + "regexp": "^\\s*at (.*\\(\\)) in (.*):line (\\d+)$", + "file": 2, + "location": 3 + } + ] + } } ] } \ No newline at end of file diff --git a/Ooui/Button.cs b/Ooui/Button.cs index 90bc0f1..4f52d4b 100644 --- a/Ooui/Button.cs +++ b/Ooui/Button.cs @@ -1,9 +1,18 @@ using System; +using System.Runtime.Serialization; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Ooui { public class Button : FormControl { + ButtonType typ = ButtonType.Submit; + public ButtonType Type { + get => typ; + set => SetProperty (ref typ, value, "type"); + } + public event EventHandler Clicked { add => AddEventListener ("click", value); remove => RemoveEventListener ("click", value); @@ -20,4 +29,15 @@ namespace Ooui Text = text; } } + + [JsonConverter (typeof (StringEnumConverter))] + public enum ButtonType + { + [EnumMember (Value = "submit")] + Submit, + [EnumMember (Value = "reset")] + Reset, + [EnumMember (Value = "button")] + Button, + } } diff --git a/Tests/ButtonTests.cs b/Tests/ButtonTests.cs index 45a1596..09ba075 100644 --- a/Tests/ButtonTests.cs +++ b/Tests/ButtonTests.cs @@ -43,5 +43,16 @@ namespace Tests b.Receive (Message.Event (b.Id, "click")); Assert.IsTrue (clicked); } + + [TestMethod] + public void ChangeButtonType () + { + var b = new Button (); + Assert.AreEqual (1, b.StateMessages.Count); + Assert.AreEqual (ButtonType.Submit, b.Type); + b.Type = ButtonType.Button; + Assert.AreEqual (2, b.StateMessages.Count); + Assert.AreEqual (ButtonType.Button, b.StateMessages[1].Value); + } } }