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: 7 additions & 4 deletions internal/ui/components/auth/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ func (m Model) submit() (Model, tea.Cmd) {
switch m.step {
case StepPhone:
m.authorizer.SubmitPhone(value)
m.step = StepCode
m.step = StepLoading
m.input.Reset()
m.input.Placeholder = "12345"
m.hint = "Enter the verification code sent to your phone"
m.hint = "Requesting verification code..."

case StepCode:
m.authorizer.SubmitCode(value)
Expand Down Expand Up @@ -162,7 +161,11 @@ func (m Model) View() string {
m.theme.AuthLabel.Render(m.hint),
)
case StepLoading:
sp := widgets.NewSpinner("Authenticating...")
label := m.hint
if label == "" {
label = "Authenticating..."
}
sp := widgets.NewSpinner(label)
sp.Style = m.theme.Spinner
content = sp.View()
case StepDone:
Expand Down
28 changes: 28 additions & 0 deletions internal/ui/components/auth/model_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package auth

import (
"strings"
"testing"

"github.com/imtaqin/telegram-cli/internal/config"
"github.com/imtaqin/telegram-cli/internal/telegram"
"github.com/imtaqin/telegram-cli/internal/ui/theme"
)

func TestSubmitPhoneWaitsForCodeRequestConfirmation(t *testing.T) {
authorizer := telegram.NewTUIAuthorizer(&config.Config{})
model := New(theme.DarkTheme(), authorizer)
model.input.Value = "+15551234567"

got, _ := model.submit()

if got.step != StepLoading {
t.Fatalf("expected phone submission to wait in loading step, got %v", got.step)
}
if got.hint != "Requesting verification code..." {
t.Fatalf("expected pending request hint, got %q", got.hint)
}
if view := got.View(); !strings.Contains(view, "Requesting verification code...") {
t.Fatalf("expected pending request hint to be rendered, got %q", view)
}
}