@umituz/web-dashboard 11.11.0 → 11.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +17 -1
- package/src/domains/activity/activity.css +229 -0
- package/src/domains/activity/components/ActivityFeed.test.tsx +61 -0
- package/src/domains/activity/components/ActivityFeed.tsx +132 -0
- package/src/domains/activity/components/ActivityTimeline.tsx +127 -0
- package/src/domains/activity/components/index.ts +2 -0
- package/src/domains/activity/index.ts +3 -0
- package/src/domains/activity/types.ts +59 -0
- package/src/domains/activity/utils.ts +73 -0
- package/src/domains/filters/components/DataToolbar.test.tsx +65 -0
- package/src/domains/filters/components/DataToolbar.tsx +119 -0
- package/src/domains/filters/components/index.ts +1 -0
- package/src/domains/filters/filters.css +128 -0
- package/src/domains/filters/index.ts +2 -0
- package/src/domains/filters/types.ts +48 -0
- package/src/domains/kanban/components/KanbanBoard.test.tsx +226 -0
- package/src/domains/kanban/components/KanbanBoard.tsx +135 -0
- package/src/domains/kanban/components/KanbanCard.tsx +160 -0
- package/src/domains/kanban/components/KanbanColumn.tsx +163 -0
- package/src/domains/kanban/components/KanbanPage.test.tsx +115 -0
- package/src/domains/kanban/components/KanbanPage.tsx +91 -0
- package/src/domains/kanban/components/index.ts +4 -0
- package/src/domains/kanban/index.ts +12 -0
- package/src/domains/kanban/kanban.css +406 -0
- package/src/domains/kanban/types.ts +103 -0
- package/src/domains/pages/components/DetailPage.test.tsx +96 -0
- package/src/domains/pages/components/DetailPage.tsx +227 -0
- package/src/domains/pages/components/index.ts +1 -0
- package/src/domains/pages/types.ts +60 -0
- package/src/domains/stepper/components/Stepper.test.tsx +71 -0
- package/src/domains/stepper/components/Stepper.tsx +74 -0
- package/src/domains/stepper/components/Wizard.tsx +84 -0
- package/src/domains/stepper/components/index.ts +2 -0
- package/src/domains/stepper/index.ts +2 -0
- package/src/domains/stepper/stepper.css +145 -0
- package/src/domains/stepper/types.ts +38 -0
- package/src/index.ts +4 -0
- package/src/styles/dashboard.css +1 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { ActivityGroup, ActivityItem } from './types';
|
|
2
|
+
|
|
3
|
+
export function toDate(timestamp: string | number | Date): Date {
|
|
4
|
+
if (timestamp instanceof Date) return timestamp;
|
|
5
|
+
if (typeof timestamp === 'number') return new Date(timestamp);
|
|
6
|
+
return new Date(timestamp);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function toIsoDayKey(date: Date): string {
|
|
10
|
+
const y = date.getFullYear();
|
|
11
|
+
const m = String(date.getMonth() + 1).padStart(2, '0');
|
|
12
|
+
const d = String(date.getDate()).padStart(2, '0');
|
|
13
|
+
return `${y}-${m}-${d}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function formatDayLabel(date: Date, locale = 'en-US'): string {
|
|
17
|
+
const now = new Date();
|
|
18
|
+
const todayKey = toIsoDayKey(now);
|
|
19
|
+
const targetKey = toIsoDayKey(date);
|
|
20
|
+
|
|
21
|
+
if (targetKey === todayKey) return 'Today';
|
|
22
|
+
|
|
23
|
+
const yesterday = new Date(now);
|
|
24
|
+
yesterday.setDate(yesterday.getDate() - 1);
|
|
25
|
+
if (targetKey === toIsoDayKey(yesterday)) return 'Yesterday';
|
|
26
|
+
|
|
27
|
+
return new Intl.DateTimeFormat(locale, {
|
|
28
|
+
month: 'short',
|
|
29
|
+
day: 'numeric',
|
|
30
|
+
year: now.getFullYear() === date.getFullYear() ? undefined : 'numeric',
|
|
31
|
+
}).format(date);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function formatActivityRelativeTime(date: Date): string {
|
|
35
|
+
const diffSec = Math.floor((Date.now() - date.getTime()) / 1000);
|
|
36
|
+
if (diffSec < 60) return 'just now';
|
|
37
|
+
const diffMin = Math.floor(diffSec / 60);
|
|
38
|
+
if (diffMin < 60) return `${diffMin}m ago`;
|
|
39
|
+
const diffHour = Math.floor(diffMin / 60);
|
|
40
|
+
if (diffHour < 24) return `${diffHour}h ago`;
|
|
41
|
+
const diffDay = Math.floor(diffHour / 24);
|
|
42
|
+
if (diffDay < 30) return `${diffDay}d ago`;
|
|
43
|
+
const diffMonth = Math.floor(diffDay / 30);
|
|
44
|
+
if (diffMonth < 12) return `${diffMonth}mo ago`;
|
|
45
|
+
return `${Math.floor(diffMonth / 12)}y ago`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function groupActivitiesByDay<T>(
|
|
49
|
+
items: readonly ActivityItem<T>[],
|
|
50
|
+
locale = 'en-US',
|
|
51
|
+
): readonly ActivityGroup<T>[] {
|
|
52
|
+
const groups: Map<string, { label: string; items: ActivityItem<T>[] }> = new Map();
|
|
53
|
+
|
|
54
|
+
for (const item of items) {
|
|
55
|
+
const d = toDate(item.timestamp);
|
|
56
|
+
const key = toIsoDayKey(d);
|
|
57
|
+
const existing = groups.get(key);
|
|
58
|
+
if (existing) {
|
|
59
|
+
existing.items.push(item);
|
|
60
|
+
} else {
|
|
61
|
+
groups.set(key, {
|
|
62
|
+
label: formatDayLabel(d, locale),
|
|
63
|
+
items: [item],
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return Array.from(groups.entries()).map(([dateKey, val]) => ({
|
|
69
|
+
dateKey,
|
|
70
|
+
label: val.label,
|
|
71
|
+
items: val.items,
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import { DataToolbar } from './DataToolbar';
|
|
4
|
+
|
|
5
|
+
describe('DataToolbar', () => {
|
|
6
|
+
it('renders search input and calls onChange', () => {
|
|
7
|
+
const handleSearch = vi.fn();
|
|
8
|
+
render(
|
|
9
|
+
<DataToolbar
|
|
10
|
+
search={{ value: '', onChange: handleSearch, placeholder: 'Filter records…' }}
|
|
11
|
+
/>,
|
|
12
|
+
);
|
|
13
|
+
const input = screen.getByPlaceholderText('Filter records…');
|
|
14
|
+
expect(input).toBeTruthy();
|
|
15
|
+
fireEvent.change(input, { target: { value: 'test' } });
|
|
16
|
+
expect(handleSearch).toHaveBeenCalledWith('test');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('renders record count label', () => {
|
|
20
|
+
render(<DataToolbar count={{ shown: 10, total: 50 }} />);
|
|
21
|
+
expect(screen.getByTestId('data-toolbar-count').textContent).toBe('10 of 50');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('renders active filter chips and handles remove and clear all', () => {
|
|
25
|
+
const handleRemove = vi.fn();
|
|
26
|
+
const handleClearAll = vi.fn();
|
|
27
|
+
render(
|
|
28
|
+
<DataToolbar
|
|
29
|
+
activeFilters={[
|
|
30
|
+
{ id: 'status', label: 'Status', valueLabel: 'Active', onRemove: handleRemove },
|
|
31
|
+
]}
|
|
32
|
+
onClearAllFilters={handleClearAll}
|
|
33
|
+
/>,
|
|
34
|
+
);
|
|
35
|
+
expect(screen.getByText('Status:')).toBeTruthy();
|
|
36
|
+
expect(screen.getByText('Active')).toBeTruthy();
|
|
37
|
+
|
|
38
|
+
fireEvent.click(screen.getByLabelText('Remove filter Status'));
|
|
39
|
+
expect(handleRemove).toHaveBeenCalled();
|
|
40
|
+
|
|
41
|
+
fireEvent.click(screen.getByText('Clear all'));
|
|
42
|
+
expect(handleClearAll).toHaveBeenCalled();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('renders view switcher buttons and handles change', () => {
|
|
46
|
+
const handleViewChange = vi.fn();
|
|
47
|
+
render(
|
|
48
|
+
<DataToolbar
|
|
49
|
+
viewSwitcher={{
|
|
50
|
+
current: 'table',
|
|
51
|
+
options: [
|
|
52
|
+
{ id: 'table', label: 'Table' },
|
|
53
|
+
{ id: 'kanban', label: 'Kanban' },
|
|
54
|
+
],
|
|
55
|
+
onChange: handleViewChange,
|
|
56
|
+
}}
|
|
57
|
+
/>,
|
|
58
|
+
);
|
|
59
|
+
expect(screen.getByText('Table')).toBeTruthy();
|
|
60
|
+
expect(screen.getByText('Kanban')).toBeTruthy();
|
|
61
|
+
|
|
62
|
+
fireEvent.click(screen.getByText('Kanban'));
|
|
63
|
+
expect(handleViewChange).toHaveBeenCalledWith('kanban');
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { FilterSelect } from '@umituz/web-design-system/molecules';
|
|
2
|
+
import { cn } from '@umituz/web-design-system/utils';
|
|
3
|
+
import type { DataToolbarProps } from '../types';
|
|
4
|
+
|
|
5
|
+
export function DataToolbar({
|
|
6
|
+
search,
|
|
7
|
+
filters,
|
|
8
|
+
activeFilters,
|
|
9
|
+
onClearAllFilters,
|
|
10
|
+
count,
|
|
11
|
+
viewSwitcher,
|
|
12
|
+
actions,
|
|
13
|
+
children,
|
|
14
|
+
className,
|
|
15
|
+
}: DataToolbarProps) {
|
|
16
|
+
const countLabel = (() => {
|
|
17
|
+
if (count === undefined) return null;
|
|
18
|
+
if (typeof count === 'number') return `${count}`;
|
|
19
|
+
if (count.total !== undefined) return `${count.shown} of ${count.total}`;
|
|
20
|
+
return `${count.shown}`;
|
|
21
|
+
})();
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div className={cn('udb-data-toolbar', className)}>
|
|
25
|
+
<div className="udb-data-toolbar__main">
|
|
26
|
+
{search && (
|
|
27
|
+
<div className="udb-data-toolbar__search">
|
|
28
|
+
<input
|
|
29
|
+
type="search"
|
|
30
|
+
value={search.value}
|
|
31
|
+
onChange={(e) => search.onChange(e.target.value)}
|
|
32
|
+
placeholder={search.placeholder ?? 'Search…'}
|
|
33
|
+
className="w-full h-8 px-3 text-xs rounded-md border border-line-border bg-surface text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary"
|
|
34
|
+
/>
|
|
35
|
+
</div>
|
|
36
|
+
)}
|
|
37
|
+
|
|
38
|
+
{filters && filters.length > 0 && (
|
|
39
|
+
<div className="udb-data-toolbar__filters">
|
|
40
|
+
{filters.map((f) => (
|
|
41
|
+
<FilterSelect
|
|
42
|
+
key={f.id}
|
|
43
|
+
value={f.value}
|
|
44
|
+
onChange={f.onChange}
|
|
45
|
+
options={f.options}
|
|
46
|
+
ariaLabel={f.label}
|
|
47
|
+
allLabel={f.allLabel ?? 'All'}
|
|
48
|
+
/>
|
|
49
|
+
))}
|
|
50
|
+
</div>
|
|
51
|
+
)}
|
|
52
|
+
|
|
53
|
+
{children}
|
|
54
|
+
|
|
55
|
+
<div className="udb-data-toolbar__right">
|
|
56
|
+
{actions}
|
|
57
|
+
|
|
58
|
+
{viewSwitcher && (
|
|
59
|
+
<div className="udb-data-toolbar__view-switcher" role="radiogroup" aria-label="View mode">
|
|
60
|
+
{viewSwitcher.options.map((opt) => {
|
|
61
|
+
const isActive = opt.id === viewSwitcher.current;
|
|
62
|
+
return (
|
|
63
|
+
<button
|
|
64
|
+
key={opt.id}
|
|
65
|
+
type="button"
|
|
66
|
+
role="radio"
|
|
67
|
+
aria-checked={isActive}
|
|
68
|
+
onClick={() => viewSwitcher.onChange(opt.id)}
|
|
69
|
+
className={cn(
|
|
70
|
+
'udb-data-toolbar__view-button',
|
|
71
|
+
isActive && 'udb-data-toolbar__view-button--active',
|
|
72
|
+
)}
|
|
73
|
+
>
|
|
74
|
+
{opt.icon}
|
|
75
|
+
<span>{opt.label}</span>
|
|
76
|
+
</button>
|
|
77
|
+
);
|
|
78
|
+
})}
|
|
79
|
+
</div>
|
|
80
|
+
)}
|
|
81
|
+
|
|
82
|
+
{countLabel && (
|
|
83
|
+
<span className="udb-data-toolbar__count" data-testid="data-toolbar-count">
|
|
84
|
+
{countLabel}
|
|
85
|
+
</span>
|
|
86
|
+
)}
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
|
|
90
|
+
{activeFilters && activeFilters.length > 0 && (
|
|
91
|
+
<div className="udb-data-toolbar__chips">
|
|
92
|
+
{activeFilters.map((chip) => (
|
|
93
|
+
<span key={chip.id} className="udb-data-toolbar__chip">
|
|
94
|
+
<span className="text-muted-foreground">{chip.label}:</span>
|
|
95
|
+
<strong className="font-medium text-foreground">{chip.valueLabel}</strong>
|
|
96
|
+
<button
|
|
97
|
+
type="button"
|
|
98
|
+
onClick={chip.onRemove}
|
|
99
|
+
className="udb-data-toolbar__chip-remove"
|
|
100
|
+
aria-label={`Remove filter ${chip.label}`}
|
|
101
|
+
>
|
|
102
|
+
×
|
|
103
|
+
</button>
|
|
104
|
+
</span>
|
|
105
|
+
))}
|
|
106
|
+
{onClearAllFilters && (
|
|
107
|
+
<button
|
|
108
|
+
type="button"
|
|
109
|
+
onClick={onClearAllFilters}
|
|
110
|
+
className="udb-data-toolbar__clear-all"
|
|
111
|
+
>
|
|
112
|
+
Clear all
|
|
113
|
+
</button>
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
)}
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DataToolbar } from './DataToolbar';
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
.udb-data-toolbar {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: 8px;
|
|
5
|
+
width: 100%;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.udb-data-toolbar__main {
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
gap: 12px;
|
|
12
|
+
flex-wrap: wrap;
|
|
13
|
+
width: 100%;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.udb-data-toolbar__search {
|
|
17
|
+
flex: 0 1 240px;
|
|
18
|
+
min-width: 180px;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.udb-data-toolbar__filters {
|
|
22
|
+
display: flex;
|
|
23
|
+
align-items: center;
|
|
24
|
+
gap: 8px;
|
|
25
|
+
flex-wrap: wrap;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.udb-data-toolbar__right {
|
|
29
|
+
display: flex;
|
|
30
|
+
align-items: center;
|
|
31
|
+
gap: 12px;
|
|
32
|
+
margin-left: auto;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.udb-data-toolbar__count {
|
|
36
|
+
font-size: 13px;
|
|
37
|
+
color: var(--text-tertiary, #94a3b8);
|
|
38
|
+
font-variant-numeric: tabular-nums;
|
|
39
|
+
white-space: nowrap;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.udb-data-toolbar__chips {
|
|
43
|
+
display: flex;
|
|
44
|
+
align-items: center;
|
|
45
|
+
gap: 6px;
|
|
46
|
+
flex-wrap: wrap;
|
|
47
|
+
padding-top: 4px;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.udb-data-toolbar__chip {
|
|
51
|
+
display: inline-flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
gap: 6px;
|
|
54
|
+
padding: 2px 8px;
|
|
55
|
+
border-radius: 9999px;
|
|
56
|
+
font-size: 12px;
|
|
57
|
+
background: var(--surface-secondary, rgba(0, 0, 0, 0.05));
|
|
58
|
+
color: var(--text-secondary, #475569);
|
|
59
|
+
border: 1px solid var(--line-border, rgba(0, 0, 0, 0.08));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.udb-data-toolbar__chip-remove {
|
|
63
|
+
display: inline-flex;
|
|
64
|
+
align-items: center;
|
|
65
|
+
justify-content: center;
|
|
66
|
+
width: 14px;
|
|
67
|
+
height: 14px;
|
|
68
|
+
border-radius: 9999px;
|
|
69
|
+
border: none;
|
|
70
|
+
background: transparent;
|
|
71
|
+
color: var(--text-tertiary, #94a3b8);
|
|
72
|
+
cursor: pointer;
|
|
73
|
+
padding: 0;
|
|
74
|
+
font-size: 12px;
|
|
75
|
+
line-height: 1;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.udb-data-toolbar__chip-remove:hover {
|
|
79
|
+
color: var(--text-primary, #0f172a);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.udb-data-toolbar__clear-all {
|
|
83
|
+
font-size: 12px;
|
|
84
|
+
color: var(--signal-600, #3b82f6);
|
|
85
|
+
background: transparent;
|
|
86
|
+
border: none;
|
|
87
|
+
cursor: pointer;
|
|
88
|
+
padding: 2px 6px;
|
|
89
|
+
font-weight: 500;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.udb-data-toolbar__clear-all:hover {
|
|
93
|
+
text-decoration: underline;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.udb-data-toolbar__view-switcher {
|
|
97
|
+
display: inline-flex;
|
|
98
|
+
align-items: center;
|
|
99
|
+
padding: 2px;
|
|
100
|
+
border-radius: 8px;
|
|
101
|
+
background: var(--surface-secondary, rgba(0, 0, 0, 0.05));
|
|
102
|
+
border: 1px solid var(--line-border, rgba(0, 0, 0, 0.08));
|
|
103
|
+
gap: 2px;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.udb-data-toolbar__view-button {
|
|
107
|
+
display: inline-flex;
|
|
108
|
+
align-items: center;
|
|
109
|
+
justify-content: center;
|
|
110
|
+
padding: 4px 8px;
|
|
111
|
+
border-radius: 6px;
|
|
112
|
+
border: none;
|
|
113
|
+
background: transparent;
|
|
114
|
+
color: var(--text-tertiary, #94a3b8);
|
|
115
|
+
font-size: 12px;
|
|
116
|
+
cursor: pointer;
|
|
117
|
+
transition: all 0.15s ease;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.udb-data-toolbar__view-button:hover {
|
|
121
|
+
color: var(--text-primary, #0f172a);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.udb-data-toolbar__view-button--active {
|
|
125
|
+
background: var(--surface, #ffffff);
|
|
126
|
+
color: var(--text-primary, #0f172a);
|
|
127
|
+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
|
128
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface DataToolbarFilterOption {
|
|
4
|
+
readonly value: string;
|
|
5
|
+
readonly label: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface DataToolbarFilter {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly label: string;
|
|
11
|
+
readonly value: string;
|
|
12
|
+
readonly options: readonly DataToolbarFilterOption[];
|
|
13
|
+
readonly onChange: (value: string) => void;
|
|
14
|
+
readonly allLabel?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ActiveFilterChip {
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly label: string;
|
|
20
|
+
readonly valueLabel: string;
|
|
21
|
+
readonly onRemove: () => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ViewSwitcherOption {
|
|
25
|
+
readonly id: string;
|
|
26
|
+
readonly label: string;
|
|
27
|
+
readonly icon?: ReactNode;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface DataToolbarProps {
|
|
31
|
+
readonly search?: {
|
|
32
|
+
readonly value: string;
|
|
33
|
+
readonly onChange: (value: string) => void;
|
|
34
|
+
readonly placeholder?: string;
|
|
35
|
+
};
|
|
36
|
+
readonly filters?: readonly DataToolbarFilter[];
|
|
37
|
+
readonly activeFilters?: readonly ActiveFilterChip[];
|
|
38
|
+
readonly onClearAllFilters?: () => void;
|
|
39
|
+
readonly count?: number | { readonly shown: number; readonly total?: number };
|
|
40
|
+
readonly viewSwitcher?: {
|
|
41
|
+
readonly current: string;
|
|
42
|
+
readonly options: readonly ViewSwitcherOption[];
|
|
43
|
+
readonly onChange: (viewId: string) => void;
|
|
44
|
+
};
|
|
45
|
+
readonly actions?: ReactNode;
|
|
46
|
+
readonly children?: ReactNode;
|
|
47
|
+
readonly className?: string;
|
|
48
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import { KanbanBoard } from './KanbanBoard';
|
|
4
|
+
import type { KanbanColumn, KanbanItem } from '../types';
|
|
5
|
+
|
|
6
|
+
interface TaskPayload {
|
|
7
|
+
priority: 'low' | 'medium' | 'high';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const COLUMNS: readonly KanbanColumn<TaskPayload>[] = [
|
|
11
|
+
{ id: 'todo', title: 'To Do', tone: 'neutral' },
|
|
12
|
+
{ id: 'in_progress', title: 'In Progress', tone: 'primary', limit: 2 },
|
|
13
|
+
{ id: 'done', title: 'Done', tone: 'success' },
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
const ITEMS: readonly KanbanItem<TaskPayload>[] = [
|
|
17
|
+
{
|
|
18
|
+
id: 'task-1',
|
|
19
|
+
columnId: 'todo',
|
|
20
|
+
title: 'Prepare blueprints',
|
|
21
|
+
description: 'Review structural schematics',
|
|
22
|
+
tone: 'info',
|
|
23
|
+
tags: [{ label: 'Arch' }],
|
|
24
|
+
assignee: { name: 'Alice Smith', initials: 'AS' },
|
|
25
|
+
meta: 'Due tomorrow',
|
|
26
|
+
payload: { priority: 'high' },
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: 'task-2',
|
|
30
|
+
columnId: 'in_progress',
|
|
31
|
+
title: 'Site excavation',
|
|
32
|
+
tone: 'warning',
|
|
33
|
+
payload: { priority: 'medium' },
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
describe('KanbanBoard', () => {
|
|
38
|
+
it('renders all columns with titles and counts', () => {
|
|
39
|
+
render(<KanbanBoard<TaskPayload> columns={COLUMNS} items={ITEMS} />);
|
|
40
|
+
|
|
41
|
+
expect(screen.getByText('To Do')).toBeDefined();
|
|
42
|
+
expect(screen.getByText('In Progress')).toBeDefined();
|
|
43
|
+
expect(screen.getByText('Done')).toBeDefined();
|
|
44
|
+
|
|
45
|
+
expect(screen.getByText('Prepare blueprints')).toBeDefined();
|
|
46
|
+
expect(screen.getByText('Site excavation')).toBeDefined();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('renders empty column indicator for columns without items', () => {
|
|
50
|
+
render(
|
|
51
|
+
<KanbanBoard<TaskPayload>
|
|
52
|
+
columns={COLUMNS}
|
|
53
|
+
items={ITEMS}
|
|
54
|
+
emptyText="No tasks here"
|
|
55
|
+
/>,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
expect(screen.getByText('No tasks here')).toBeDefined();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('fires onSelectItem when clicking a card', () => {
|
|
62
|
+
const handleSelect = vi.fn();
|
|
63
|
+
render(
|
|
64
|
+
<KanbanBoard<TaskPayload>
|
|
65
|
+
columns={COLUMNS}
|
|
66
|
+
items={ITEMS}
|
|
67
|
+
onSelectItem={handleSelect}
|
|
68
|
+
/>,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
fireEvent.click(screen.getByText('Prepare blueprints'));
|
|
72
|
+
expect(handleSelect).toHaveBeenCalledWith(ITEMS[0]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('fires onSelectItem on Enter key press', () => {
|
|
76
|
+
const handleSelect = vi.fn();
|
|
77
|
+
render(
|
|
78
|
+
<KanbanBoard<TaskPayload>
|
|
79
|
+
columns={COLUMNS}
|
|
80
|
+
items={ITEMS}
|
|
81
|
+
onSelectItem={handleSelect}
|
|
82
|
+
/>,
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const card = screen.getByText('Prepare blueprints').closest('.udb-kanban-card');
|
|
86
|
+
expect(card).toBeTruthy();
|
|
87
|
+
if (card) {
|
|
88
|
+
fireEvent.keyDown(card, { key: 'Enter' });
|
|
89
|
+
expect(handleSelect).toHaveBeenCalledWith(ITEMS[0]);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('moves item forward via stage button', () => {
|
|
94
|
+
const handleMove = vi.fn();
|
|
95
|
+
render(
|
|
96
|
+
<KanbanBoard<TaskPayload>
|
|
97
|
+
columns={COLUMNS}
|
|
98
|
+
items={ITEMS}
|
|
99
|
+
onMoveItem={handleMove}
|
|
100
|
+
showStageActions={true}
|
|
101
|
+
/>,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const forwardBtns = screen.getAllByRole('button', { name: 'Move forward' });
|
|
105
|
+
const firstForward = forwardBtns[0];
|
|
106
|
+
expect(firstForward).toBeDefined();
|
|
107
|
+
if (firstForward) {
|
|
108
|
+
fireEvent.click(firstForward);
|
|
109
|
+
expect(handleMove).toHaveBeenCalledWith('task-1', 'in_progress', 'todo');
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('moves item backward via stage button', () => {
|
|
114
|
+
const handleMove = vi.fn();
|
|
115
|
+
render(
|
|
116
|
+
<KanbanBoard<TaskPayload>
|
|
117
|
+
columns={COLUMNS}
|
|
118
|
+
items={ITEMS}
|
|
119
|
+
onMoveItem={handleMove}
|
|
120
|
+
showStageActions={true}
|
|
121
|
+
/>,
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const backwardBtns = screen.getAllByRole('button', { name: 'Move backward' });
|
|
125
|
+
const inProgressBtn = backwardBtns.find((btn) => !btn.hasAttribute('disabled'));
|
|
126
|
+
expect(inProgressBtn).toBeTruthy();
|
|
127
|
+
if (inProgressBtn) {
|
|
128
|
+
fireEvent.click(inProgressBtn);
|
|
129
|
+
expect(handleMove).toHaveBeenCalledWith('task-2', 'todo', 'in_progress');
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('handles drag and drop between columns', () => {
|
|
134
|
+
const handleMove = vi.fn();
|
|
135
|
+
const { container } = render(
|
|
136
|
+
<KanbanBoard<TaskPayload>
|
|
137
|
+
columns={COLUMNS}
|
|
138
|
+
items={ITEMS}
|
|
139
|
+
onMoveItem={handleMove}
|
|
140
|
+
/>,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const card = screen.getByText('Prepare blueprints').closest('.udb-kanban-card');
|
|
144
|
+
const doneCol = container.querySelector('[data-column-id="done"]');
|
|
145
|
+
|
|
146
|
+
expect(card).toBeTruthy();
|
|
147
|
+
expect(doneCol).toBeTruthy();
|
|
148
|
+
|
|
149
|
+
if (card && doneCol) {
|
|
150
|
+
const dataTransfer = {
|
|
151
|
+
setData: vi.fn(),
|
|
152
|
+
getData: vi.fn(() => 'task-1'),
|
|
153
|
+
effectAllowed: 'move',
|
|
154
|
+
dropEffect: 'move',
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
fireEvent.dragStart(card, { dataTransfer });
|
|
158
|
+
fireEvent.dragOver(doneCol, { dataTransfer });
|
|
159
|
+
fireEvent.drop(doneCol, { dataTransfer });
|
|
160
|
+
|
|
161
|
+
expect(handleMove).toHaveBeenCalledWith('task-1', 'done', 'todo');
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('prevents dropping into column where canDrop is false', () => {
|
|
166
|
+
const handleMove = vi.fn();
|
|
167
|
+
const blockedCols: readonly KanbanColumn<TaskPayload>[] = [
|
|
168
|
+
{ id: 'todo', title: 'To Do', tone: 'neutral' },
|
|
169
|
+
{ id: 'in_progress', title: 'In Progress', tone: 'primary' },
|
|
170
|
+
{ id: 'done', title: 'Done', tone: 'success', canDrop: false },
|
|
171
|
+
];
|
|
172
|
+
|
|
173
|
+
const { container } = render(
|
|
174
|
+
<KanbanBoard<TaskPayload>
|
|
175
|
+
columns={blockedCols}
|
|
176
|
+
items={ITEMS}
|
|
177
|
+
onMoveItem={handleMove}
|
|
178
|
+
/>,
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
const card = screen.getByText('Prepare blueprints').closest('.udb-kanban-card');
|
|
182
|
+
const doneCol = container.querySelector('[data-column-id="done"]');
|
|
183
|
+
|
|
184
|
+
if (card && doneCol) {
|
|
185
|
+
const dataTransfer = {
|
|
186
|
+
setData: vi.fn(),
|
|
187
|
+
getData: vi.fn(() => 'task-1'),
|
|
188
|
+
effectAllowed: 'move',
|
|
189
|
+
dropEffect: 'move',
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
fireEvent.drop(doneCol, { dataTransfer });
|
|
193
|
+
expect(handleMove).not.toHaveBeenCalled();
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('renders custom card when renderCard is provided', () => {
|
|
198
|
+
render(
|
|
199
|
+
<KanbanBoard<TaskPayload>
|
|
200
|
+
columns={COLUMNS}
|
|
201
|
+
items={ITEMS}
|
|
202
|
+
renderCard={(item) => <div data-testid={`custom-${item.id}`}>Custom: {item.title}</div>}
|
|
203
|
+
/>,
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
expect(screen.getByTestId('custom-task-1').textContent).toContain('Custom: Prepare blueprints');
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('indicates when column limit is exceeded', () => {
|
|
210
|
+
const overflowItems: readonly KanbanItem<TaskPayload>[] = [
|
|
211
|
+
...ITEMS,
|
|
212
|
+
{ id: 'task-3', columnId: 'in_progress', title: 'Task 3' },
|
|
213
|
+
{ id: 'task-4', columnId: 'in_progress', title: 'Task 4' },
|
|
214
|
+
];
|
|
215
|
+
|
|
216
|
+
render(
|
|
217
|
+
<KanbanBoard<TaskPayload>
|
|
218
|
+
columns={COLUMNS}
|
|
219
|
+
items={overflowItems}
|
|
220
|
+
/>,
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
const limitPill = screen.getByText('/ 2');
|
|
224
|
+
expect(limitPill.className).toContain('is-exceeded');
|
|
225
|
+
});
|
|
226
|
+
});
|