Add Button Type

Fixes #12
This commit is contained in:
Frank A. Krueger 2017-06-18 18:38:00 -07:00
parent 9f46d03447
commit 0b4b54ffbf
3 changed files with 53 additions and 1 deletions

23
.vscode/tasks.json vendored
View File

@ -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
}
]
}
}
]
}

View File

@ -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,
}
}

View File

@ -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);
}
}
}