-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #218 from K-Phoen/text-var
Text var
- Loading branch information
Showing
5 changed files
with
160 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package text | ||
|
||
import ( | ||
"github.com/K-Phoen/sdk" | ||
) | ||
|
||
// Option represents an option that can be used to configure a textbox variable. | ||
type Option func(constant *Text) | ||
|
||
// Text represents a "textbox" templated variable. | ||
type Text struct { | ||
Builder sdk.TemplateVar | ||
} | ||
|
||
// New creates a new "query" templated variable. | ||
func New(name string, options ...Option) *Text { | ||
query := &Text{Builder: sdk.TemplateVar{ | ||
Name: name, | ||
Label: name, | ||
Type: "textbox", | ||
Options: []sdk.Option{}, | ||
}} | ||
|
||
for _, opt := range options { | ||
opt(query) | ||
} | ||
|
||
return query | ||
} | ||
|
||
// Label sets the label of the variable. | ||
func Label(label string) Option { | ||
return func(query *Text) { | ||
query.Builder.Label = label | ||
} | ||
} | ||
|
||
// HideLabel ensures that this variable's label will not be displayed. | ||
func HideLabel() Option { | ||
return func(query *Text) { | ||
query.Builder.Hide = 1 | ||
} | ||
} | ||
|
||
// Hide ensures that the variable will not be displayed. | ||
func Hide() Option { | ||
return func(query *Text) { | ||
query.Builder.Hide = 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package text | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewTextVariablesCanBeCreated(t *testing.T) { | ||
req := require.New(t) | ||
|
||
panel := New("filter") | ||
|
||
req.Equal("filter", panel.Builder.Name) | ||
req.Equal("filter", panel.Builder.Label) | ||
req.Equal("textbox", panel.Builder.Type) | ||
} | ||
|
||
func TestLabelCanBeSet(t *testing.T) { | ||
req := require.New(t) | ||
|
||
panel := New("filter", Label("Filter")) | ||
|
||
req.Equal("filter", panel.Builder.Name) | ||
req.Equal("Filter", panel.Builder.Label) | ||
} | ||
|
||
func TestLabelCanBeHidden(t *testing.T) { | ||
req := require.New(t) | ||
|
||
panel := New("", HideLabel()) | ||
|
||
req.Equal(uint8(1), panel.Builder.Hide) | ||
} | ||
|
||
func TestVariableCanBeHidden(t *testing.T) { | ||
req := require.New(t) | ||
|
||
panel := New("", Hide()) | ||
|
||
req.Equal(uint8(2), panel.Builder.Hide) | ||
} |