Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions cmd/blocks/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,14 @@ package blocks
import (
"github.com/slackapi/slack-cli/internal/shared"
"github.com/slackapi/slack-cli/internal/style"
"github.com/slackapi/slack-cli/internal/useragent"
"github.com/spf13/cobra"
)

// aiAgentFunc is a package variable so it can be stubbed in tests.
var aiAgentFunc = useragent.GetAIAgent

func NewCommand(clients *shared.ClientFactory) *cobra.Command {
cmd := &cobra.Command{
Use: "blocks <subcommand> [flags]",
Short: "Build with Block Kit",
Long: "Build layouts using Block Kit and iterate on designs with Block Kit Builder.",
Hidden: aiAgentFunc() == nil,
Use: "blocks <subcommand> [flags]",
Short: "Build with Block Kit",
Long: "Build layouts using Block Kit and iterate on designs with Block Kit Builder.",
Example: style.ExampleCommandsf([]style.ExampleCommand{
{
Meaning: "Preview blocks in Block Kit Builder",
Expand Down
29 changes: 0 additions & 29 deletions cmd/blocks/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ import (
"testing"

"github.com/slackapi/slack-cli/internal/shared"
"github.com/slackapi/slack-cli/internal/useragent"
"github.com/slackapi/slack-cli/test/testutil"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)

func Test_Blocks_Command(t *testing.T) {
Expand All @@ -39,30 +37,3 @@ func Test_Blocks_Command(t *testing.T) {
return NewCommand(cf)
})
}

func Test_Blocks_Command_Hidden(t *testing.T) {
tests := map[string]struct {
aiAgent *useragent.AIAgent
expectedHidden bool
}{
"hidden when no AI coding tool is detected": {
aiAgent: nil,
expectedHidden: true,
},
"visible when an AI coding tool is detected": {
aiAgent: &useragent.AIAgent{Name: "claude-code"},
expectedHidden: false,
},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
restore := stubAIAgent(tc.aiAgent)
defer restore()

clientsMock := shared.NewClientsMock()
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
cmd := NewCommand(clients)
assert.Equal(t, tc.expectedHidden, cmd.Hidden)
})
}
}
9 changes: 0 additions & 9 deletions cmd/blocks/preview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,13 @@ import (
"github.com/slackapi/slack-cli/internal/shared/types"
"github.com/slackapi/slack-cli/internal/slackerror"
"github.com/slackapi/slack-cli/internal/slacktrace"
"github.com/slackapi/slack-cli/internal/useragent"
"github.com/slackapi/slack-cli/test/testutil"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)

// stubAIAgent stubs the detected AI coding tool and returns a function that
// restores the original detection.
func stubAIAgent(agent *useragent.AIAgent) func() {
original := aiAgentFunc
aiAgentFunc = func() *useragent.AIAgent { return agent }
return func() { aiAgentFunc = original }
}

func Test_Blocks_PreviewCommand(t *testing.T) {
// teamlessURL is the Block Kit Builder URL rendered when no team can be
// resolved. The browser resolves the team from its own session.
Expand Down
Loading