feat: initial setup with WhatsApp CRM apps and sync services
This commit is contained in:
183
apps/whatsapp-crm/tests/kanban.test.ts
Normal file
183
apps/whatsapp-crm/tests/kanban.test.ts
Normal file
@@ -0,0 +1,183 @@
|
||||
import { STAGES, Stage, Contact } from '@/lib/types'
|
||||
|
||||
describe('Kanban Board', () => {
|
||||
describe('3.1 Column Component Tests', () => {
|
||||
it('test_renders_four_columns', () => {
|
||||
const { STAGE_LIST } = require('@/lib/types')
|
||||
expect(STAGE_LIST).toHaveLength(4)
|
||||
expect(STAGE_LIST).toContain('LEADS DE ENTRADA')
|
||||
expect(STAGE_LIST).toContain('DECIDINDO')
|
||||
expect(STAGE_LIST).toContain('DISCUSSAO DE CONTRATO')
|
||||
expect(STAGE_LIST).toContain('DECISAO FINAL')
|
||||
})
|
||||
|
||||
it('test_column_displays_contact_count', () => {
|
||||
const contacts: Contact[] = [
|
||||
{ id: 1, name: 'Contact 1', phone: '+5511999999991', stage: STAGES.LEADS_DE_ENTRADA, notes: null, schedule_date: null, follow_up_date: null, payment_status: 'pending', created_at: '', updated_at: '' },
|
||||
{ id: 2, name: 'Contact 2', phone: '+5511999999992', stage: STAGES.LEADS_DE_ENTRADA, notes: null, schedule_date: null, follow_up_date: null, payment_status: 'pending', created_at: '', updated_at: '' },
|
||||
]
|
||||
|
||||
const leadsContacts = contacts.filter(c => c.stage === STAGES.LEADS_DE_ENTRADA)
|
||||
expect(leadsContacts.length).toBe(2)
|
||||
})
|
||||
|
||||
it('test_empty_column_shows_placeholder', () => {
|
||||
const contacts: Contact[] = []
|
||||
const leadsContacts = contacts.filter(c => c.stage === STAGES.LEADS_DE_ENTRADA)
|
||||
|
||||
const shouldShowEmpty = leadsContacts.length === 0
|
||||
expect(shouldShowEmpty).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('3.2 Contact Card Tests', () => {
|
||||
it('test_card_displays_contact_name', () => {
|
||||
const contact: Contact = {
|
||||
id: 1,
|
||||
name: 'John Doe',
|
||||
phone: '+5511999999999',
|
||||
stage: STAGES.LEADS_DE_ENTRADA,
|
||||
notes: null,
|
||||
schedule_date: null,
|
||||
follow_up_date: null,
|
||||
payment_status: 'pending',
|
||||
created_at: '',
|
||||
updated_at: ''
|
||||
}
|
||||
|
||||
expect(contact.name).toBe('John Doe')
|
||||
})
|
||||
|
||||
it('test_card_displays_formatted_phone', () => {
|
||||
const formatPhone = (phone: string) => {
|
||||
const cleaned = phone.replace(/\D/g, '')
|
||||
if (cleaned.length === 13) {
|
||||
return `+${cleaned.slice(0, 2)} (${cleaned.slice(3, 5)}) ${cleaned.slice(5, 10)}-${cleaned.slice(10)}`
|
||||
}
|
||||
if (cleaned.length === 12) {
|
||||
return `+${cleaned.slice(0, 2)} (${cleaned.slice(2, 4)}) ${cleaned.slice(4, 9)}-${cleaned.slice(9)}`
|
||||
}
|
||||
if (cleaned.length === 11) {
|
||||
return `(${cleaned.slice(0, 2)}) ${cleaned.slice(2, 7)}-${cleaned.slice(7)}`
|
||||
}
|
||||
return phone
|
||||
}
|
||||
|
||||
const formatted = formatPhone('+5511999999999')
|
||||
expect(formatted).toContain('+55')
|
||||
expect(formatted).toContain('99999')
|
||||
})
|
||||
|
||||
it('test_card_displays_message_preview', () => {
|
||||
const contact: Contact = {
|
||||
id: 1,
|
||||
name: 'John Doe',
|
||||
phone: '+5511999999999',
|
||||
stage: STAGES.LEADS_DE_ENTRADA,
|
||||
notes: 'This is a very long note that should be truncated when displayed in the card preview area',
|
||||
schedule_date: null,
|
||||
follow_up_date: null,
|
||||
payment_status: 'pending',
|
||||
created_at: '',
|
||||
updated_at: ''
|
||||
}
|
||||
|
||||
const preview = contact.notes ? contact.notes.substring(0, 50) + (contact.notes.length > 50 ? '...' : '') : ''
|
||||
expect(preview.length).toBe(53)
|
||||
expect(preview).toContain('...')
|
||||
})
|
||||
|
||||
it('test_card_displays_task_count_badge', () => {
|
||||
const contact: Contact = {
|
||||
id: 1,
|
||||
name: 'John Doe',
|
||||
phone: '+5511999999999',
|
||||
stage: STAGES.LEADS_DE_ENTRADA,
|
||||
notes: null,
|
||||
schedule_date: null,
|
||||
follow_up_date: null,
|
||||
payment_status: 'pending',
|
||||
created_at: '',
|
||||
updated_at: '',
|
||||
taskCount: 3
|
||||
}
|
||||
|
||||
expect(contact.taskCount).toBe(3)
|
||||
expect(contact.taskCount! > 0).toBe(true)
|
||||
})
|
||||
|
||||
it('test_card_displays_overdue_indicator', () => {
|
||||
const pastDate = '2020-01-01'
|
||||
const futureDate = '2030-01-01'
|
||||
|
||||
const isPastOverdue = pastDate && new Date(pastDate) < new Date()
|
||||
const isFutureOverdue = futureDate && new Date(futureDate) < new Date()
|
||||
|
||||
expect(isPastOverdue).toBe(true)
|
||||
expect(isFutureOverdue).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('3.3 Drag and Drop Tests', () => {
|
||||
it('test_drag_card_to_different_stage', () => {
|
||||
const contact: Contact = {
|
||||
id: 1,
|
||||
name: 'John Doe',
|
||||
phone: '+5511999999999',
|
||||
stage: STAGES.LEADS_DE_ENTRADA,
|
||||
notes: null,
|
||||
schedule_date: null,
|
||||
follow_up_date: null,
|
||||
payment_status: 'pending',
|
||||
created_at: '',
|
||||
updated_at: ''
|
||||
}
|
||||
|
||||
const newStage = STAGES.DECIDINDO
|
||||
const updatedContact = { ...contact, stage: newStage }
|
||||
|
||||
expect(updatedContact.stage).toBe(STAGES.DECIDINDO)
|
||||
expect(updatedContact.stage).not.toBe(contact.stage)
|
||||
})
|
||||
|
||||
it('test_cannot_drag_to_same_column', () => {
|
||||
const contact: Contact = {
|
||||
id: 1,
|
||||
name: 'John Doe',
|
||||
phone: '+5511999999999',
|
||||
stage: STAGES.LEADS_DE_ENTRADA,
|
||||
notes: null,
|
||||
schedule_date: null,
|
||||
follow_up_date: null,
|
||||
payment_status: 'pending',
|
||||
created_at: '',
|
||||
updated_at: ''
|
||||
}
|
||||
|
||||
const sameStage = STAGES.LEADS_DE_ENTRADA
|
||||
const updatedContact = { ...contact, stage: sameStage }
|
||||
|
||||
expect(updatedContact.stage).toBe(contact.stage)
|
||||
expect(updatedContact.stage).not.toBe(STAGES.DECIDINDO)
|
||||
})
|
||||
|
||||
it('test_drag_cancelled_returns_card', () => {
|
||||
const contact: Contact = {
|
||||
id: 1,
|
||||
name: 'John Doe',
|
||||
phone: '+5511999999999',
|
||||
stage: STAGES.LEADS_DE_ENTRADA,
|
||||
notes: null,
|
||||
schedule_date: null,
|
||||
follow_up_date: null,
|
||||
payment_status: 'pending',
|
||||
created_at: '',
|
||||
updated_at: ''
|
||||
}
|
||||
|
||||
const originalContact = { ...contact }
|
||||
|
||||
expect(contact.stage).toBe(originalContact.stage)
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user