github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/chat/utils/collapses_test.go (about)

     1  package utils
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/keybase/client/go/chat/globals"
     8  	"github.com/keybase/client/go/externalstest"
     9  	"github.com/keybase/client/go/protocol/chat1"
    10  	"github.com/keybase/client/go/protocol/gregor1"
    11  	"github.com/keybase/clockwork"
    12  	"github.com/stretchr/testify/require"
    13  	"golang.org/x/net/context"
    14  )
    15  
    16  func TestCollapses(t *testing.T) {
    17  	tc := externalstest.SetupTest(t, "collapses", 0)
    18  	defer tc.Cleanup()
    19  
    20  	g := globals.NewContext(tc.G, &globals.ChatContext{})
    21  	collapses := NewCollapses(g)
    22  
    23  	ctx := context.TODO()
    24  	convID := chat1.ConversationID([]byte{1, 2, 3, 4})
    25  	uid := gregor1.UID([]byte{2, 3, 4, 5})
    26  	clock := clockwork.NewFakeClock()
    27  	collapses.clock = clock
    28  
    29  	require.NoError(t, collapses.ToggleSingle(ctx, uid, convID, 6, true))
    30  	require.True(t, collapses.IsCollapsed(ctx, uid, convID, 6, chat1.MessageType_ATTACHMENT))
    31  	require.NoError(t, collapses.ToggleSingle(ctx, uid, convID, 6, false))
    32  	require.False(t, collapses.IsCollapsed(ctx, uid, convID, 6, chat1.MessageType_ATTACHMENT))
    33  
    34  	require.NoError(t, collapses.ToggleRange(ctx, uid, convID, 10, true))
    35  	clock.Advance(10 * time.Second)
    36  	require.True(t, collapses.IsCollapsed(ctx, uid, convID, 10, chat1.MessageType_ATTACHMENT))
    37  	require.True(t, collapses.IsCollapsed(ctx, uid, convID, 2, chat1.MessageType_UNFURL))
    38  	require.False(t, collapses.IsCollapsed(ctx, uid, convID, 11, chat1.MessageType_ATTACHMENT))
    39  	require.True(t, collapses.IsCollapsed(ctx, uid, convID, 6, chat1.MessageType_ATTACHMENT))
    40  	require.NoError(t, collapses.ToggleSingle(ctx, uid, convID, 6, false))
    41  	clock.Advance(10 * time.Second)
    42  	require.False(t, collapses.IsCollapsed(ctx, uid, convID, 6, chat1.MessageType_ATTACHMENT))
    43  	require.NoError(t, collapses.ToggleRange(ctx, uid, convID, 10, false))
    44  	clock.Advance(10 * time.Second)
    45  	require.False(t, collapses.IsCollapsed(ctx, uid, convID, 10, chat1.MessageType_ATTACHMENT))
    46  	require.False(t, collapses.IsCollapsed(ctx, uid, convID, 2, chat1.MessageType_ATTACHMENT))
    47  	require.False(t, collapses.IsCollapsed(ctx, uid, convID, 6, chat1.MessageType_ATTACHMENT))
    48  }