Skip to content

Commit

Permalink
Adding tests for the Props yaml field
Browse files Browse the repository at this point in the history
  • Loading branch information
Danzabar committed Nov 13, 2015
1 parent 4509d6b commit 3126c48
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
26 changes: 15 additions & 11 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,23 @@ type Builder struct {

// The YAML config struct
type Config struct {
Name string `yaml:"Name"`
Description string `yaml:"Description"`
Action string `yaml:"Action"`
Method string `yaml:"Method"`
Fields []ConfigField `yaml:"Fields"`
Name string `yaml:"Name"`
Description string `yaml:"Description"`
Action string `yaml:"Action"`
Method string `yaml:"Method"`
Props map[string]string `yaml:"Props"`
Fields []ConfigField `yaml:"Fields"`
}

// The YAML config struct for a field
type ConfigField struct {
Name string `yaml:"Name"`
Label string `yaml:"Label"`
Type string `yaml:"Type"`
Default string `yaml:"Default"`
Values []string `yaml:"Values"`
Rules []ConfigRule `yaml:"Rules"`
Name string `yaml:"Name"`
Label string `yaml:"Label"`
Type string `yaml:"Type"`
Default string `yaml:"Default"`
Props map[string]string `yaml:"Props"`
Values []string `yaml:"Values"`
Rules []ConfigRule `yaml:"Rules"`
}

// The validation struct
Expand Down Expand Up @@ -78,6 +80,7 @@ func (b *Builder) build() {
b.Form.Name = b.Config.Name
b.Form.Description = b.Config.Description
b.Form.Action = b.Config.Action
b.Form.Props = b.Config.Props
b.Form.Method = b.Config.Method

// Now we can add fields
Expand All @@ -86,6 +89,7 @@ func (b *Builder) build() {
Name: field.Name,
Label: field.Label,
Type: field.Type,
Props: field.Props,
Default: field.Default,
Values: field.Values,
}
Expand Down
8 changes: 8 additions & 0 deletions builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ func TestValidationItems(t *testing.T) {
assert.Equal(t, false, b.Form.Valid)
}

// Testing that props are set
func TestPropsSet(t *testing.T) {
b := NewBuilder("example.yml", request)
b.build()

assert.Equal(t, 2, len(b.Form.Props))
}

// Test building a form with pre-defined values
func TestBuildPreValues(t *testing.T) {
r := http.Request{
Expand Down
1 change: 1 addition & 0 deletions example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Name: Test
Description: Test
Action: test
Method: POST
Props: { class: test, data-id: test }
Fields:
- Name: test
Label: Test
Expand Down

0 comments on commit 3126c48

Please sign in to comment.