79 lines
No EOL
2.6 KiB
TypeScript
79 lines
No EOL
2.6 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest'
|
|
import { mount, flushPromises } from '@vue/test-utils'
|
|
import { createPinia, setActivePinia } from 'pinia'
|
|
|
|
vi.mock('@/api', () => ({
|
|
getToday: vi.fn(),
|
|
getSuggestions: vi.fn().mockResolvedValue([]),
|
|
getNotificationLog: vi.fn().mockResolvedValue([]),
|
|
acceptSuggestion: vi.fn(),
|
|
dismissSuggestion: vi.fn(),
|
|
getTelemetryTasks: vi.fn().mockResolvedValue([]),
|
|
HttpError: class HttpError extends Error {
|
|
status: number
|
|
body: unknown
|
|
constructor(status: number, body: unknown, msg?: string) {
|
|
super(msg ?? `HTTP ${status}`)
|
|
this.status = status
|
|
this.body = body
|
|
}
|
|
}
|
|
}))
|
|
|
|
describe('TodayView deadlines strip', () => {
|
|
it('renders deadline cards with urgent styling when <= 2 days', async () => {
|
|
setActivePinia(createPinia())
|
|
const api = await import('@/api')
|
|
const TodayView = (await import('@/views/TodayView.vue')).default
|
|
|
|
// Build deadlines: one urgent (tomorrow) and one normal (5 days)
|
|
const tomorrow = new Date()
|
|
tomorrow.setDate(tomorrow.getDate() + 1)
|
|
const fiveDays = new Date()
|
|
fiveDays.setDate(fiveDays.getDate() + 5)
|
|
|
|
;(api.getToday as ReturnType<typeof vi.fn>).mockResolvedValue({
|
|
digest: [],
|
|
nudges: [],
|
|
pending_approvals: 0,
|
|
deadlines: [
|
|
{ application_id: 'app-1', title: 'Backend Dev', company: 'Acme', apply_by: tomorrow.toISOString().slice(0, 10) },
|
|
{ application_id: 'app-2', title: 'Frontend Dev', company: 'Globex', apply_by: fiveDays.toISOString().slice(0, 10) }
|
|
]
|
|
})
|
|
|
|
const wrapper = mount(TodayView)
|
|
await flushPromises()
|
|
|
|
// Section heading present
|
|
expect(wrapper.text()).toContain('Deadlines This Week')
|
|
|
|
// Both companies shown
|
|
expect(wrapper.text()).toContain('Acme')
|
|
expect(wrapper.text()).toContain('Globex')
|
|
|
|
// Urgent card has red background class
|
|
const urgentCard = wrapper.findAll('.bg-red-50')
|
|
expect(urgentCard.length).toBeGreaterThanOrEqual(1)
|
|
expect(urgentCard[0].text()).toContain('Backend Dev')
|
|
expect(urgentCard[0].text()).toContain('Acme')
|
|
})
|
|
|
|
it('does not render deadlines section when no deadlines', async () => {
|
|
setActivePinia(createPinia())
|
|
const api = await import('@/api')
|
|
const TodayView = (await import('@/views/TodayView.vue')).default
|
|
|
|
;(api.getToday as ReturnType<typeof vi.fn>).mockResolvedValue({
|
|
digest: [],
|
|
nudges: [],
|
|
pending_approvals: 0,
|
|
deadlines: []
|
|
})
|
|
|
|
const wrapper = mount(TodayView)
|
|
await flushPromises()
|
|
|
|
expect(wrapper.text()).not.toContain('Deadlines This Week')
|
|
})
|
|
}) |