Skip to content

Commit 637d552

Browse files
committed
test: add coverage for formatDate, isOverdue, handleDragEnd, handleCardClick, handleModalClose (#517)
Brings src/components/board/** function coverage above the 70% threshold. CardItem.vue reaches 100% function coverage.
1 parent 305dc7e commit 637d552

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

frontend/taskdeck-web/src/tests/components/CardItem.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,25 @@ function createCard(): Card {
2121
}
2222
}
2323

24+
describe('CardItem — date display', () => {
25+
it('renders formatted due date and overdue indicator when dueDate is in the past', () => {
26+
const card = createCard()
27+
card.dueDate = '2020-01-01T00:00:00.000Z' // definitely in the past
28+
const wrapper = mount(CardItem, { props: { card } })
29+
expect(wrapper.find('.td-board-card__due').exists()).toBe(true)
30+
expect(wrapper.find('.td-board-card__due--overdue').exists()).toBe(true)
31+
expect(wrapper.text()).toContain('Overdue')
32+
})
33+
34+
it('renders due date without overdue indicator when dueDate is in the future', () => {
35+
const card = createCard()
36+
card.dueDate = '2099-12-31T00:00:00.000Z'
37+
const wrapper = mount(CardItem, { props: { card } })
38+
expect(wrapper.find('.td-board-card__due').exists()).toBe(true)
39+
expect(wrapper.find('.td-board-card__due--overdue').exists()).toBe(false)
40+
})
41+
})
42+
2443
describe('CardItem drag guardrails', () => {
2544
it('exposes an explicit enlarged drag handle control', () => {
2645
const wrapper = mount(CardItem, {
@@ -71,4 +90,11 @@ describe('CardItem drag guardrails', () => {
7190
expect(setData).toHaveBeenCalledWith('text/plain', card.id)
7291
expect(wrapper.emitted('dragstart')).toEqual([[card]])
7392
})
93+
94+
it('emits dragend and clears dragging state on dragend', async () => {
95+
const card = createCard()
96+
const wrapper = mount(CardItem, { props: { card } })
97+
await wrapper.get('[data-action="drag-card-handle"]').trigger('dragend')
98+
expect(wrapper.emitted('dragend')).toHaveLength(1)
99+
})
74100
})

frontend/taskdeck-web/src/tests/components/ColumnLane.spec.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,44 @@ describe('ColumnLane — WIP limit enforcement', () => {
290290
})
291291
})
292292
})
293+
294+
describe('ColumnLane — card modal', () => {
295+
beforeEach(() => {
296+
setActivePinia(createPinia())
297+
vi.mocked(useBoardStore).mockReturnValue({
298+
createCard: vi.fn().mockResolvedValue({}),
299+
moveCard: vi.fn().mockResolvedValue({}),
300+
} as any)
301+
})
302+
303+
it('opens the card modal when handleCardClick is called', async () => {
304+
const column = makeColumn()
305+
const card = makeCard('c1')
306+
const wrapper = mount(ColumnLane, {
307+
props: { ...defaultProps, column, cards: [card] },
308+
global: { stubs: { CardItem: true, CardModal: true, ColumnEditModal: true } },
309+
})
310+
311+
await (wrapper.vm as any).handleCardClick(card)
312+
await wrapper.vm.$nextTick()
313+
314+
expect((wrapper.vm as any).selectedCard).toEqual(card)
315+
expect((wrapper.vm as any).showCardModal).toBe(true)
316+
})
317+
318+
it('closes the card modal and clears selectedCard when handleModalClose is called', async () => {
319+
const column = makeColumn()
320+
const card = makeCard('c1')
321+
const wrapper = mount(ColumnLane, {
322+
props: { ...defaultProps, column, cards: [card] },
323+
global: { stubs: { CardItem: true, CardModal: true, ColumnEditModal: true } },
324+
})
325+
326+
await (wrapper.vm as any).handleCardClick(card)
327+
await (wrapper.vm as any).handleModalClose()
328+
await wrapper.vm.$nextTick()
329+
330+
expect((wrapper.vm as any).selectedCard).toBeNull()
331+
expect((wrapper.vm as any).showCardModal).toBe(false)
332+
})
333+
})

0 commit comments

Comments
 (0)