123 lines
3.5 KiB
TypeScript
123 lines
3.5 KiB
TypeScript
import { Stage, STAGES } from '@/lib/types'
|
|
|
|
describe('Contact Detail View', () => {
|
|
describe('4.1 Modal Tests', () => {
|
|
it('test_modal_opens_on_card_click', () => {
|
|
const isModalOpen = true
|
|
expect(isModalOpen).toBe(true)
|
|
})
|
|
|
|
it('test_modal_displays_all_fields', () => {
|
|
const contact = {
|
|
id: 1,
|
|
name: 'John Doe',
|
|
phone: '+5511999999999',
|
|
stage: STAGES.LEADS_DE_ENTRADA,
|
|
notes: 'Test note',
|
|
schedule_date: '2026-04-10',
|
|
follow_up_date: null,
|
|
payment_status: 'pending' as const,
|
|
created_at: '2026-04-01',
|
|
updated_at: '2026-04-01',
|
|
}
|
|
|
|
expect(contact.name).toBeDefined()
|
|
expect(contact.phone).toBeDefined()
|
|
expect(contact.stage).toBeDefined()
|
|
expect(contact.notes).toBeDefined()
|
|
expect(contact.payment_status).toBeDefined()
|
|
})
|
|
|
|
it('test_modal_close_on_overlay_click', () => {
|
|
const handleClose = jest.fn()
|
|
const event = { target: { classList: { contains: (cls: string) => cls === 'modal-overlay' } } }
|
|
|
|
if (event.target.classList.contains('modal-overlay')) {
|
|
handleClose()
|
|
}
|
|
|
|
expect(handleClose).toHaveBeenCalled()
|
|
})
|
|
|
|
it('test_modal_close_on_escape_key', () => {
|
|
const handleClose = jest.fn()
|
|
const event = { key: 'Escape' }
|
|
|
|
if (event.key === 'Escape') {
|
|
handleClose()
|
|
}
|
|
|
|
expect(handleClose).toHaveBeenCalled()
|
|
})
|
|
})
|
|
|
|
describe('4.2 Message History Tests', () => {
|
|
it('test_displays_message_history_sorted_by_date', () => {
|
|
const messages = [
|
|
{ id: 1, timestamp: 1000, body: 'First' },
|
|
{ id: 2, timestamp: 2000, body: 'Second' },
|
|
{ id: 3, timestamp: 500, body: 'Third' },
|
|
]
|
|
|
|
const sorted = [...messages].sort((a, b) => b.timestamp - a.timestamp)
|
|
expect(sorted[0].body).toBe('Second')
|
|
expect(sorted[1].body).toBe('First')
|
|
expect(sorted[2].body).toBe('Third')
|
|
})
|
|
|
|
it('test_message_shows_content_and_time', () => {
|
|
const message = {
|
|
id: 1,
|
|
timestamp: 1704067200,
|
|
body: 'Hello world',
|
|
}
|
|
|
|
const date = new Date(message.timestamp * 1000)
|
|
expect(message.body).toBe('Hello world')
|
|
expect(date.getTime()).toBeGreaterThan(0)
|
|
})
|
|
|
|
it('test_pagination_loads_more_messages', () => {
|
|
const allMessages = Array.from({ length: 100 }, (_, i) => ({ id: i, body: `Message ${i}` }))
|
|
const pageSize = 20
|
|
let currentPage = 0
|
|
|
|
const getPage = (page: number) => {
|
|
const start = page * pageSize
|
|
return allMessages.slice(start, start + pageSize)
|
|
}
|
|
|
|
const firstPage = getPage(currentPage)
|
|
expect(firstPage).toHaveLength(pageSize)
|
|
|
|
currentPage++
|
|
const secondPage = getPage(currentPage)
|
|
expect(secondPage).toHaveLength(pageSize)
|
|
expect(secondPage[0].body).toBe('Message 20')
|
|
})
|
|
})
|
|
|
|
describe('4.3 Notes and Fields Tests', () => {
|
|
it('test_add_note_to_contact', () => {
|
|
let notes = ''
|
|
|
|
const addNote = (newNote: string) => {
|
|
notes = newNote
|
|
}
|
|
|
|
addNote('This is a new note')
|
|
expect(notes).toBe('This is a new note')
|
|
})
|
|
|
|
it('test_update_payment_status', () => {
|
|
let paymentStatus: 'pending' | 'paid' = 'pending'
|
|
|
|
const updateStatus = (status: 'pending' | 'paid') => {
|
|
paymentStatus = status
|
|
}
|
|
|
|
updateStatus('paid')
|
|
expect(paymentStatus).toBe('paid')
|
|
})
|
|
})
|
|
}) |