|
1 | 1 | import Gantt from "frappe-gantt"; |
2 | 2 |
|
3 | | -const tasks = [ |
| 3 | +// Test basic task structure |
| 4 | +const tasks: Gantt.Task[] = [ |
4 | 5 | { |
5 | 6 | id: "Task 1", |
6 | 7 | name: "Redesign website", |
7 | 8 | start: "2016-12-28", |
8 | 9 | end: "2016-12-31", |
9 | 10 | progress: 20, |
| 11 | + color: "#fff", |
10 | 12 | dependencies: "Task 2, Task 3", |
11 | 13 | }, |
| 14 | + { |
| 15 | + id: "Task 2", |
| 16 | + name: "Task with duration", |
| 17 | + start: "2016-12-28", |
| 18 | + duration: "2 days", |
| 19 | + color: "#000", |
| 20 | + progress: 50, |
| 21 | + }, |
| 22 | + { |
| 23 | + id: "Task 3", |
| 24 | + name: "Custom class task", |
| 25 | + start: "2016-12-28", |
| 26 | + end: "2016-12-31", |
| 27 | + progress: 75, |
| 28 | + color_progress: "#fff", |
| 29 | + custom_class: "custom-task", |
| 30 | + }, |
12 | 31 | ]; |
13 | | -const gantt1 = new Gantt("#gantt", tasks); |
14 | 32 |
|
| 33 | +// Test different constructor signatures |
| 34 | +const gantt1 = new Gantt("#gantt", tasks); |
15 | 35 | const gantt2 = new Gantt(new HTMLElement(), tasks); |
16 | 36 | const gantt3 = new Gantt(new SVGElement(), tasks); |
17 | 37 |
|
18 | | -gantt1.change_view_mode(Gantt.VIEW_MODE.WEEK); |
19 | | -gantt1.refresh(tasks); |
| 38 | +// Test view modes |
| 39 | +gantt1.change_view_mode("Week"); |
| 40 | +gantt1.change_view_mode("Day", true); |
20 | 41 |
|
21 | | -new Gantt("#gantt", tasks, { |
22 | | - on_click: task => {}, |
23 | | - on_date_change: (task, start, end) => {}, |
24 | | - on_progress_change: (task, progress) => {}, |
25 | | - on_view_change: mode => {}, |
| 42 | +// Test view mode object |
| 43 | +gantt1.change_view_mode({ |
| 44 | + name: "Month", |
| 45 | + padding: "1 day", |
| 46 | + date_format: "YYYY-MM-DD", |
| 47 | + upper_text: (date: Date) => date.toLocaleDateString(), |
| 48 | + lower_text: "DD", |
| 49 | + column_width: 50, |
| 50 | + step: "1 day", |
| 51 | + snap_at: "1 day", |
| 52 | + thick_line: (date: Date) => date.getDate() === 1, |
26 | 53 | }); |
27 | 54 |
|
| 55 | +// Test task operations |
| 56 | +gantt1.refresh(tasks); |
| 57 | +gantt1.update_task("Task 1", { progress: 50 }); |
| 58 | +const task = gantt1.get_task("Task 1"); |
| 59 | + |
| 60 | +// Test view checks |
| 61 | +gantt1.view_is("Week"); |
| 62 | +gantt1.view_is(["Week", "Day"]); |
| 63 | +gantt1.view_is({ name: "Week" }); |
| 64 | + |
| 65 | +// Test utility methods |
| 66 | +gantt1.unselect_all(); |
| 67 | +const oldestDate = gantt1.get_oldest_starting_date(); |
| 68 | +gantt1.clear(); |
| 69 | + |
| 70 | +// Test comprehensive options |
28 | 71 | new Gantt("#gantt", tasks, { |
29 | | - custom_popup_html: task => { |
30 | | - const end_date = task._end.toDateString(); |
31 | | - return ` |
32 | | - <div class="details-container"> |
33 | | - <h5>${task.name}</h5> |
34 | | - <p>Expected to finish by ${end_date}</p> |
35 | | - <p>${task.progress}% completed!</p> |
36 | | - </div> |
37 | | - `; |
| 72 | + // Basic display options |
| 73 | + arrow_curve: 5, |
| 74 | + auto_move_label: true, |
| 75 | + bar_corner_radius: 3, |
| 76 | + bar_height: 20, |
| 77 | + column_width: 30, |
| 78 | + container_height: "auto", |
| 79 | + date_format: "YYYY-MM-DD", |
| 80 | + |
| 81 | + // Holiday and ignore settings |
| 82 | + holidays: { |
| 83 | + red: "weekend", |
| 84 | + blue: ["2023-12-25", "2023-12-26"], |
| 85 | + green: (date: Date) => date.getDay() === 5, |
| 86 | + purple: [ |
| 87 | + { date: "2023-12-31", name: "New Year's Eve" }, |
| 88 | + { date: "2024-01-01", name: "New Year's Day" }, |
| 89 | + ], |
38 | 90 | }, |
| 91 | + ignore: ["2023-12-24", "2023-12-25"], |
| 92 | + |
| 93 | + // Layout options |
| 94 | + infinite_padding: true, |
39 | 95 | language: "es", |
| 96 | + lines: "both", |
| 97 | + lower_header_height: 20, |
| 98 | + move_dependencies: true, |
| 99 | + padding: 10, |
| 100 | + |
| 101 | + // Popup options |
| 102 | + popup: true, |
| 103 | + popup_on: "click", |
| 104 | + |
| 105 | + // Readonly options |
| 106 | + readonly: false, |
| 107 | + readonly_dates: false, |
| 108 | + readonly_progress: false, |
| 109 | + |
| 110 | + // Scroll and progress options |
| 111 | + scroll_to: "today", |
| 112 | + show_expected_progress: true, |
| 113 | + snap_at: "1 day", |
| 114 | + today_button: true, |
| 115 | + upper_header_height: 50, |
| 116 | + |
| 117 | + // View mode options |
| 118 | + view_mode: "Week", |
| 119 | + view_mode_select: true, |
| 120 | + view_modes: [ |
| 121 | + { |
| 122 | + name: "Quarter Day", |
| 123 | + padding: "1 hour", |
| 124 | + date_format: "HH:mm", |
| 125 | + upper_text: "DD MMM", |
| 126 | + lower_text: "HH:mm", |
| 127 | + column_width: 25, |
| 128 | + step: "15 mins", |
| 129 | + snap_at: "15 mins", |
| 130 | + }, |
| 131 | + { |
| 132 | + name: "Day", |
| 133 | + padding: "1 day", |
| 134 | + date_format: "DD MMM", |
| 135 | + upper_text: "MMMM YYYY", |
| 136 | + lower_text: "DD", |
| 137 | + column_width: 50, |
| 138 | + step: "1 day", |
| 139 | + snap_at: "1 day", |
| 140 | + thick_line: (date: Date) => date.getDay() === 1, |
| 141 | + }, |
| 142 | + ], |
| 143 | + |
| 144 | + // Event handlers |
| 145 | + on_click: (task: Gantt.Task) => { |
| 146 | + console.log(`Task ${task.name} clicked`); |
| 147 | + }, |
| 148 | + on_date_change: (task: Gantt.Task, start: Date, end: Date) => { |
| 149 | + console.log(`Task ${task.name} dates changed to ${start} - ${end}`); |
| 150 | + }, |
| 151 | + on_progress_change: (task: Gantt.Task, progress: number) => { |
| 152 | + console.log(`Task ${task.name} progress changed to ${progress}%`); |
| 153 | + }, |
| 154 | + on_view_change: (mode: Gantt.ViewModeObject) => { |
| 155 | + console.log(`View changed to ${mode.name}`); |
| 156 | + }, |
40 | 157 | }); |
| 158 | + |
| 159 | +// Test static VIEW_MODE property |
| 160 | +const viewModes = { |
| 161 | + quarterDay: Gantt.VIEW_MODE.QUARTER_DAY, |
| 162 | + halfDay: Gantt.VIEW_MODE.HALF_DAY, |
| 163 | + day: Gantt.VIEW_MODE.DAY, |
| 164 | + week: Gantt.VIEW_MODE.WEEK, |
| 165 | + month: Gantt.VIEW_MODE.MONTH, |
| 166 | + year: Gantt.VIEW_MODE.YEAR, |
| 167 | +}; |
0 commit comments