Files
workspace/apps/go-crm/internal/handlers/status_test.go
gabspereira 9c3bfd131d feat(go-crm): industrial terminal-core UI redesign
Complete visual overhaul of the go-crm web interface:

- New shared layout system (internal/templates/ui.go) with dark zinc
  industrial theme, JetBrains Mono typography, grid/noise textures
- Redesigned all pages: Dashboard, Login/Signup, Clients, Customers,
  Services, Scheduling, Payments, Questions, Answers, Leads,
  Review Queue, Report, Keyword Mapping
- Tailwind CSS via CDN with custom color palette (amber/emerald/rose/sky)
- HTMX-powered interactions with CSS swap animations
- Status pills, KPI cards, data tables, empty states, inline forms
- Mobile-responsive sidebar with collapsible navigation
- All existing tests updated and passing
- Zero new build dependencies — works with existing go run/air workflow
2026-05-23 18:00:32 -03:00

119 lines
3.1 KiB
Go

package handlers
import (
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
"time"
"go-crm/internal/db"
"go-crm/internal/whatsapp"
"golang.org/x/crypto/bcrypt"
)
func TestListClientsWhatsAppStatusIndicators(t *testing.T) {
tmpfile, err := os.CreateTemp("", "test_*.db")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmpfile.Name())
tmpfile.Close()
testDB, err := db.Init(tmpfile.Name())
if err != nil {
t.Fatalf("failed to init db: %v", err)
}
defer testDB.Close()
fakeWA := whatsapp.NewFakeConnector()
fakeWA.MarkConnected(1)
DB = testDB
WAConnector = fakeWA
hashedPassword, _ := bcrypt.GenerateFromPassword([]byte("password"), bcrypt.DefaultCost)
_, err = testDB.Exec(
"INSERT INTO accounts (email, name, password, created_at) VALUES (?, ?, ?, ?)",
"test@example.com", "Test Account", string(hashedPassword), time.Now().Unix(),
)
if err != nil {
t.Fatalf("failed to create account: %v", err)
}
var accountID int64
err = testDB.QueryRow("SELECT account_id FROM accounts WHERE email = ?", "test@example.com").Scan(&accountID)
if err != nil {
t.Fatalf("failed to get account id: %v", err)
}
_, err = testDB.Exec(
"INSERT INTO clients (account_id, name, phone, whatsapp_number, whatsapp_connected, created_at) VALUES (?, ?, ?, ?, ?, ?)",
accountID, "Connected Client", "+5521987654321", "+5521987654321", 1, time.Now().Unix(),
)
if err != nil {
t.Fatalf("failed to create connected client: %v", err)
}
_, err = testDB.Exec(
"INSERT INTO clients (account_id, name, phone, whatsapp_number, whatsapp_connected, created_at) VALUES (?, ?, ?, ?, ?, ?)",
accountID, "Disconnected Client", "+5521987654322", "+5521987654322", 1, time.Now().Unix(),
)
if err != nil {
t.Fatalf("failed to create disconnected client: %v", err)
}
_, err = testDB.Exec(
"INSERT INTO clients (account_id, name, phone, created_at) VALUES (?, ?, ?, ?)",
accountID, "No WhatsApp Client", "+5521987654323", time.Now().Unix(),
)
if err != nil {
t.Fatalf("failed to create no-wa client: %v", err)
}
sessionID := "test-session-status"
expires := time.Now().Add(time.Hour).Unix()
_, err = testDB.Exec(
"INSERT INTO sessions (session_id, account_id, expires) VALUES (?, ?, ?)",
sessionID, accountID, expires,
)
if err != nil {
t.Fatalf("failed to create session: %v", err)
}
req := httptest.NewRequest(http.MethodGet, "/clients", nil)
req.AddCookie(&http.Cookie{Name: "session", Value: sessionID})
w := httptest.NewRecorder()
ListClients(w, req)
if w.Code != http.StatusOK {
t.Fatalf("expected status 200, got %d", w.Code)
}
body := w.Body.String()
if !strings.Contains(body, "Connected Client") {
t.Error("expected to find connected client")
}
if !strings.Contains(body, "Disconnected Client") {
t.Error("expected to find disconnected client")
}
if !strings.Contains(body, "No WhatsApp Client") {
t.Error("expected to find no-wa client")
}
if !strings.Contains(body, "Connect") {
t.Error("expected Connect link for clients without active connection")
}
greenDot := `bg-emerald-400`
if !strings.Contains(body, greenDot) {
t.Error("expected green dot for connected client")
}
}