github.com/wtfutil/wtf@v0.43.0/app/widget_maker_test.go (about)

     1  package app
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/olebedev/config"
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/wtfutil/wtf/modules/clocks"
     9  	"github.com/wtfutil/wtf/wtf"
    10  )
    11  
    12  const (
    13  	disabled = `
    14  wtf:
    15    mods:
    16      clocks:
    17        enabled: false
    18        position:
    19          top: 0
    20          left: 0
    21          height: 1
    22          width: 1
    23        refreshInterval: 30`
    24  
    25  	enabled = `
    26  wtf:
    27    mods:
    28      clocks:
    29        enabled: true
    30        position:
    31          top: 0
    32          left: 0
    33          height: 1
    34          width: 1
    35        refreshInterval: 30`
    36  )
    37  
    38  func Test_MakeWidget(t *testing.T) {
    39  	tests := []struct {
    40  		name       string
    41  		moduleName string
    42  		config     *config.Config
    43  		expected   wtf.Wtfable
    44  	}{
    45  		{
    46  			name:       "invalid module",
    47  			moduleName: "",
    48  			config:     &config.Config{},
    49  			expected:   nil,
    50  		},
    51  		{
    52  			name:       "valid disabled module",
    53  			moduleName: "clocks",
    54  			config: func() *config.Config {
    55  				cfg, _ := config.ParseYaml(disabled)
    56  				return cfg
    57  			}(),
    58  			expected: nil,
    59  		},
    60  		{
    61  			name:       "valid enabled module",
    62  			moduleName: "clocks",
    63  			config: func() *config.Config {
    64  				cfg, _ := config.ParseYaml(enabled)
    65  				return cfg
    66  			}(),
    67  			expected: &clocks.Widget{},
    68  		},
    69  	}
    70  
    71  	for _, tt := range tests {
    72  		t.Run(tt.name, func(t *testing.T) {
    73  			actual := MakeWidget(nil, nil, tt.moduleName, tt.config, make(chan bool))
    74  			assert.IsType(t, tt.expected, actual)
    75  		})
    76  	}
    77  }