github.com/grahambrereton-form3/tilt@v0.10.18/internal/hud/webview/analytics_nudge_test.go (about)

     1  package webview
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/windmilleng/wmclient/pkg/analytics"
     9  
    10  	"github.com/windmilleng/tilt/internal/k8s"
    11  	"github.com/windmilleng/tilt/internal/k8s/testyaml"
    12  	"github.com/windmilleng/tilt/internal/store"
    13  	"github.com/windmilleng/tilt/pkg/model"
    14  )
    15  
    16  func TestNeedsNudgeK8sYaml(t *testing.T) {
    17  	state := store.NewState()
    18  
    19  	m, err := k8s.NewK8sOnlyManifestFromYAML(testyaml.SanchoYAML)
    20  	assert.NoError(t, err)
    21  	targ := store.NewManifestTarget(m)
    22  	targ.State = &store.ManifestState{LastSuccessfulDeployTime: time.Now()}
    23  	state.UpsertManifestTarget(targ)
    24  
    25  	nudge := NeedsNudge(*state)
    26  	assert.False(t, nudge,
    27  		"manifest is k8s_yaml, expected needsNudge = false")
    28  }
    29  
    30  func TestNeedsNudgeRedManifest(t *testing.T) {
    31  	state := store.NewState()
    32  
    33  	m := model.Manifest{Name: "server"}
    34  	targ := store.NewManifestTarget(m)
    35  	state.UpsertManifestTarget(targ)
    36  
    37  	nudge := NeedsNudge(*state)
    38  	assert.False(t, nudge,
    39  		"manifest has never had successful build, expected needsNudge = false")
    40  }
    41  
    42  func TestNeedsNudgeGreenManifest(t *testing.T) {
    43  	state := store.NewState()
    44  
    45  	m := model.Manifest{Name: "server"}
    46  	targ := store.NewManifestTarget(m)
    47  	targ.State = &store.ManifestState{LastSuccessfulDeployTime: time.Now()}
    48  	state.UpsertManifestTarget(targ)
    49  
    50  	nudge := NeedsNudge(*state)
    51  	assert.True(t, nudge,
    52  		"manifest HAS had had successful build, expected needsNudge = true")
    53  }
    54  
    55  func TestNeedsNudgeAlreadyOpted(t *testing.T) {
    56  	state := store.NewState()
    57  
    58  	state.AnalyticsUserOpt = analytics.OptIn
    59  	m := model.Manifest{Name: "server"}
    60  	targ := store.NewManifestTarget(m)
    61  	targ.State = &store.ManifestState{LastSuccessfulDeployTime: time.Now()}
    62  	state.UpsertManifestTarget(targ)
    63  
    64  	nudge := NeedsNudge(*state)
    65  	assert.False(t, nudge,
    66  		"user already opted in, expected needsNudge = false")
    67  }