diff --git a/internal/ui/components/auth/model.go b/internal/ui/components/auth/model.go index e0aae7c..cdd5e53 100644 --- a/internal/ui/components/auth/model.go +++ b/internal/ui/components/auth/model.go @@ -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) @@ -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: diff --git a/internal/ui/components/auth/model_test.go b/internal/ui/components/auth/model_test.go new file mode 100644 index 0000000..5683a4a --- /dev/null +++ b/internal/ui/components/auth/model_test.go @@ -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) + } +}