github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/chat/commands/flip_test.go (about)

     1  package commands
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/keybase/client/go/chat/globals"
     9  	"github.com/keybase/client/go/chat/types"
    10  	"github.com/keybase/client/go/externalstest"
    11  	"github.com/keybase/client/go/kbtest"
    12  	"github.com/keybase/client/go/protocol/chat1"
    13  	"github.com/keybase/client/go/protocol/gregor1"
    14  	"github.com/stretchr/testify/require"
    15  )
    16  
    17  func TestFlipPreview(t *testing.T) {
    18  	tc := externalstest.SetupTest(t, "flip", 0)
    19  	defer tc.Cleanup()
    20  
    21  	ui := kbtest.NewChatUI()
    22  	g := globals.NewContext(tc.G, &globals.ChatContext{})
    23  	g.CoinFlipManager = types.DummyCoinFlipManager{}
    24  	g.UIRouter = kbtest.NewMockUIRouter(ui)
    25  	flip := NewFlip(g)
    26  	ctx := context.TODO()
    27  	uid := gregor1.UID{1, 2, 3, 4}
    28  	convID := chat1.ConversationID{1, 2, 3, 4}
    29  	timeout := 20 * time.Second
    30  
    31  	flip.Preview(ctx, uid, convID, "", "/flip")
    32  	select {
    33  	case s := <-ui.CommandMarkdown:
    34  		require.NotNil(t, s)
    35  	case <-time.After(timeout):
    36  		require.Fail(t, "no text")
    37  	}
    38  
    39  	flip.Preview(ctx, uid, convID, "", "/flip 6")
    40  	select {
    41  	case s := <-ui.CommandMarkdown:
    42  		require.NotNil(t, s)
    43  	case <-time.After(timeout):
    44  		require.Fail(t, "no text")
    45  	}
    46  
    47  	flip.Preview(ctx, uid, convID, "", "/flip ")
    48  	select {
    49  	case s := <-ui.CommandMarkdown:
    50  		require.NotNil(t, s)
    51  	case <-time.After(timeout):
    52  		require.Fail(t, "no text")
    53  	}
    54  
    55  	flip.Preview(ctx, uid, convID, "", "/fli")
    56  	select {
    57  	case s := <-ui.CommandMarkdown:
    58  		require.Nil(t, s)
    59  	case <-time.After(timeout):
    60  		require.Fail(t, "no text")
    61  	}
    62  
    63  	flip.Preview(ctx, uid, convID, "", "/fli")
    64  	select {
    65  	case <-ui.CommandMarkdown:
    66  		require.Fail(t, "no text expected")
    67  	default:
    68  	}
    69  }