Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/components/board/GanttView.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { describe, expect, it, jest } from '@jest/globals'
import GanttView from './GanttView.vue'

jest.mock('@nextcloud/vue', () => ({}), { virtual: true })
jest.mock('frappe-gantt', () => ({}))
jest.mock('frappe-gantt/dist/frappe-gantt.css', () => ({}), { virtual: true })
jest.mock('pinia', () => ({ mapActions: () => ({}), mapState: () => ({}) }))
jest.mock('vue-material-design-icons/ChartGantt.vue', () => ({}))
jest.mock('vue-material-design-icons/ChevronDown.vue', () => ({}))
jest.mock('vue-material-design-icons/ChevronRight.vue', () => ({}))
jest.mock('../../stores/board.js', () => ({}))
jest.mock('../../stores/card.js', () => ({}))

describe('GanttView card partitioning', () => {
it('includes a start-only card in Gantt tasks and leaves undated cards in the undated list', () => {
const startOnlyCard = {
id: 1,
title: 'Start only',
startdate: new Date().toISOString(),
duedate: null,
}
const undatedCard = {
id: 2,
title: 'No dates',
startdate: null,
duedate: null,
}
const cardToGanttTask = jest.fn((card) => ({ id: String(card.id) }))
const context = {
stacks: [{ id: 10 }],
cardsByStack: () => [startOnlyCard, undatedCard],
currentViewMode: 'Day',
cardToGanttTask,
}

const result = GanttView.computed.partitionedCards.call(context)

expect(result.ganttTasks).toEqual([{ id: '1' }])
expect(result.undatedCards).toEqual([undatedCard])
expect(cardToGanttTask).toHaveBeenCalledWith(startOnlyCard, 0)
})
})
10 changes: 5 additions & 5 deletions src/components/board/GanttView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -229,25 +229,25 @@ export default {
} else {
// gantt renders everything at once so large date ranges cause performance issues on render
// therefore we limit the timeframe of visible tasks
const duedate = new Date(card.duedate)
const filterDate = new Date(card.duedate || card.startdate)
switch (this.currentViewMode) {
case 'Hour':
if (duedate < new Date() - 2 * 24 * 3600 * 1000) {
if (filterDate < new Date() - 2 * 24 * 3600 * 1000) {
return
}
break
case 'Day':
if (duedate < new Date() - 30 * 24 * 3600 * 1000) {
if (filterDate < new Date() - 30 * 24 * 3600 * 1000) {
return
}
break
case 'Week':
if (duedate < new Date() - 90 * 24 * 3600 * 1000) {
if (filterDate < new Date() - 90 * 24 * 3600 * 1000) {
return
}
break
case 'Month':
if (duedate < new Date() - 365 * 24 * 3600 * 1000) {
if (filterDate < new Date() - 365 * 24 * 3600 * 1000) {
return
}
break
Expand Down
Loading