github.com/wtfutil/wtf@v0.43.0/modules/gcal/display_test.go (about)

     1  package gcal
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  	"github.com/wtfutil/wtf/cfg"
     8  	"google.golang.org/api/calendar/v3"
     9  )
    10  
    11  func Test_display_content(t *testing.T) {
    12  	startTime := &calendar.EventDateTime{DateTime: "1986-04-19T01:00:00.00Z"}
    13  	endTime := &calendar.EventDateTime{DateTime: "1986-04-19T02:00:00.00Z"}
    14  	event := &calendar.Event{Summary: "Foo", Start: startTime, End: endTime}
    15  
    16  	testCases := []struct {
    17  		descriptionWanted string
    18  		events            []*CalEvent
    19  		name              string
    20  		settings          *Settings
    21  	}{
    22  		{
    23  			name:              "Event content without any events",
    24  			settings:          &Settings{Common: &cfg.Common{}},
    25  			events:            nil,
    26  			descriptionWanted: "No calendar events",
    27  		},
    28  		{
    29  			name:              "Event content with a single event, without end times displayed",
    30  			settings:          &Settings{Common: &cfg.Common{}, showEndTime: false},
    31  			events:            []*CalEvent{NewCalEvent(event)},
    32  			descriptionWanted: "[]Saturday, Apr 19\n  []01:00 []Foo[white]\n   \n",
    33  		},
    34  		{
    35  			name:              "Event content with a single event without showEndTime explicitly set in settings",
    36  			settings:          &Settings{Common: &cfg.Common{}},
    37  			events:            []*CalEvent{NewCalEvent(event)},
    38  			descriptionWanted: "[]Saturday, Apr 19\n  []01:00 []Foo[white]\n   \n",
    39  		},
    40  		{
    41  			name:              "Event content with a single event with end times displayed",
    42  			settings:          &Settings{Common: &cfg.Common{}, showEndTime: true},
    43  			events:            []*CalEvent{NewCalEvent(event)},
    44  			descriptionWanted: "[]Saturday, Apr 19\n  []01:00-02:00 []Foo[white]\n   \n",
    45  		},
    46  	}
    47  
    48  	for _, tt := range testCases {
    49  		t.Run(tt.name, func(t *testing.T) {
    50  			w := &Widget{calEvents: tt.events, settings: tt.settings, err: nil}
    51  			_, description, err := w.content()
    52  
    53  			assert.Equal(t, false, err, tt.name)
    54  			assert.Equal(t, tt.descriptionWanted, description, tt.name)
    55  		})
    56  	}
    57  
    58  }