@object-ui/plugin-detail 3.0.2 → 3.1.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.
Files changed (132) hide show
  1. package/.turbo/turbo-build.log +45 -8
  2. package/CHANGELOG.md +9 -0
  3. package/dist/AddressField-C07oUOY6.js +96 -0
  4. package/dist/AutoNumberField-BxnFqllo.js +8 -0
  5. package/dist/AvatarField-VThNABzo.js +82 -0
  6. package/dist/BooleanField-CGHKBzAi.js +37 -0
  7. package/dist/CodeField-Co_muhRR.js +21 -0
  8. package/dist/ColorField-DLid_tFz.js +42 -0
  9. package/dist/CurrencyField-Bw-LqANM.js +43 -0
  10. package/dist/DateField-BNHAzMB2.js +21 -0
  11. package/dist/DateTimeField-DjAyn_DQ.js +28 -0
  12. package/dist/EmailField-xoNcSppb.js +31 -0
  13. package/dist/FileField-DbNJwjU2.js +133 -0
  14. package/dist/FormulaField-CJkkwIK8.js +9 -0
  15. package/dist/GeolocationField-C1AnS6VV.js +123 -0
  16. package/dist/GridField-DATAHIKf.js +30 -0
  17. package/dist/ImageField-CEKJpyJp.js +90 -0
  18. package/dist/LocationField-jDWXjlpx.js +31 -0
  19. package/dist/LookupField-DQ08L9UQ.js +96 -0
  20. package/dist/MasterDetailField-Dbk529Ea.js +108 -0
  21. package/dist/NumberField-BVroN9aV.js +26 -0
  22. package/dist/ObjectField-CT3l_IHW.js +48 -0
  23. package/dist/PasswordField-DweVLEE0.js +38 -0
  24. package/dist/PercentField-ZpWUK97K.js +63 -0
  25. package/dist/PhoneField-mw-9fqZ_.js +31 -0
  26. package/dist/QRCodeField-Cbb9ck59.js +77 -0
  27. package/dist/RatingField-CSqgLS6t.js +47 -0
  28. package/dist/RichTextField-BpfBOd99.js +38 -0
  29. package/dist/SelectField-B9Ei-5jl.js +26 -0
  30. package/dist/SignatureField-DgGpHnQ8.js +85 -0
  31. package/dist/SliderField-C6HvOHd8.js +30 -0
  32. package/dist/SummaryField-ugYPYxjP.js +9 -0
  33. package/dist/TextAreaField-BK3RgzY3.js +39 -0
  34. package/dist/TextField-Bvzx3atT.js +32 -0
  35. package/dist/TimeField-Cuz9-Uai.js +21 -0
  36. package/dist/UrlField-B6XHTV73.js +33 -0
  37. package/dist/UserField-ooTul2d6.js +49 -0
  38. package/dist/VectorField-CKg9jdGa.js +25 -0
  39. package/dist/index-CnlyRfY_.js +59461 -0
  40. package/dist/index.js +30 -55026
  41. package/dist/index.umd.cjs +41 -30
  42. package/dist/plugin-detail.css +1 -1
  43. package/dist/src/ActivityTimeline.d.ts +20 -0
  44. package/dist/src/ActivityTimeline.d.ts.map +1 -0
  45. package/dist/src/CommentAttachment.d.ts +25 -0
  46. package/dist/src/CommentAttachment.d.ts.map +1 -0
  47. package/dist/src/CommentInput.d.ts +24 -0
  48. package/dist/src/CommentInput.d.ts.map +1 -0
  49. package/dist/src/DetailSection.d.ts +6 -0
  50. package/dist/src/DetailSection.d.ts.map +1 -1
  51. package/dist/src/DetailView.d.ts +4 -0
  52. package/dist/src/DetailView.d.ts.map +1 -1
  53. package/dist/src/DetailView.stories.d.ts +8 -0
  54. package/dist/src/DetailView.stories.d.ts.map +1 -1
  55. package/dist/src/DiffView.d.ts +24 -0
  56. package/dist/src/DiffView.d.ts.map +1 -0
  57. package/dist/src/FieldChangeItem.d.ts +21 -0
  58. package/dist/src/FieldChangeItem.d.ts.map +1 -0
  59. package/dist/src/InlineCreateRelated.d.ts +32 -0
  60. package/dist/src/InlineCreateRelated.d.ts.map +1 -0
  61. package/dist/src/MentionAutocomplete.d.ts +43 -0
  62. package/dist/src/MentionAutocomplete.d.ts.map +1 -0
  63. package/dist/src/PointInTimeRestore.d.ts +28 -0
  64. package/dist/src/PointInTimeRestore.d.ts.map +1 -0
  65. package/dist/src/ReactionPicker.d.ts +25 -0
  66. package/dist/src/ReactionPicker.d.ts.map +1 -0
  67. package/dist/src/RecordActivityTimeline.d.ts +49 -0
  68. package/dist/src/RecordActivityTimeline.d.ts.map +1 -0
  69. package/dist/src/RecordChatterPanel.d.ts +48 -0
  70. package/dist/src/RecordChatterPanel.d.ts.map +1 -0
  71. package/dist/src/RecordComments.d.ts +20 -0
  72. package/dist/src/RecordComments.d.ts.map +1 -0
  73. package/dist/src/RecordNavigationEnhanced.d.ts +18 -0
  74. package/dist/src/RecordNavigationEnhanced.d.ts.map +1 -0
  75. package/dist/src/RelatedList.d.ts +4 -0
  76. package/dist/src/RelatedList.d.ts.map +1 -1
  77. package/dist/src/RelationshipGraph.d.ts +23 -0
  78. package/dist/src/RelationshipGraph.d.ts.map +1 -0
  79. package/dist/src/RichTextCommentInput.d.ts +24 -0
  80. package/dist/src/RichTextCommentInput.d.ts.map +1 -0
  81. package/dist/src/SubscriptionToggle.d.ts +22 -0
  82. package/dist/src/SubscriptionToggle.d.ts.map +1 -0
  83. package/dist/src/ThreadedReplies.d.ts +26 -0
  84. package/dist/src/ThreadedReplies.d.ts.map +1 -0
  85. package/dist/src/autoLayout.d.ts +34 -0
  86. package/dist/src/autoLayout.d.ts.map +1 -0
  87. package/dist/src/index.d.ts +36 -0
  88. package/dist/src/index.d.ts.map +1 -1
  89. package/dist/src/useDetailTranslation.d.ts +34 -0
  90. package/dist/src/useDetailTranslation.d.ts.map +1 -0
  91. package/package.json +8 -7
  92. package/src/ActivityTimeline.tsx +184 -0
  93. package/src/CommentAttachment.tsx +192 -0
  94. package/src/CommentInput.tsx +81 -0
  95. package/src/DetailSection.tsx +74 -9
  96. package/src/DetailView.stories.tsx +76 -0
  97. package/src/DetailView.tsx +270 -27
  98. package/src/DiffView.tsx +231 -0
  99. package/src/FieldChangeItem.tsx +46 -0
  100. package/src/InlineCreateRelated.tsx +291 -0
  101. package/src/MentionAutocomplete.tsx +123 -0
  102. package/src/PointInTimeRestore.tsx +261 -0
  103. package/src/ReactionPicker.tsx +106 -0
  104. package/src/RecordActivityTimeline.tsx +429 -0
  105. package/src/RecordChatterPanel.tsx +202 -0
  106. package/src/RecordComments.tsx +215 -0
  107. package/src/RecordNavigationEnhanced.tsx +211 -0
  108. package/src/RelatedList.tsx +37 -8
  109. package/src/RelationshipGraph.tsx +286 -0
  110. package/src/RichTextCommentInput.tsx +348 -0
  111. package/src/SubscriptionToggle.tsx +60 -0
  112. package/src/ThreadedReplies.tsx +161 -0
  113. package/src/__tests__/ActivityTimeline.test.tsx +119 -0
  114. package/src/__tests__/ActivityTimelineFiltering.test.tsx +143 -0
  115. package/src/__tests__/CommentInput.test.tsx +57 -0
  116. package/src/__tests__/DetailSection.test.tsx +320 -0
  117. package/src/__tests__/DetailView.test.tsx +415 -1
  118. package/src/__tests__/FieldChangeItem.test.tsx +119 -0
  119. package/src/__tests__/MentionAutocomplete.test.tsx +97 -0
  120. package/src/__tests__/ReactionPicker.test.tsx +113 -0
  121. package/src/__tests__/RecordActivityTimeline.test.tsx +395 -0
  122. package/src/__tests__/RecordChatterPanel.test.tsx +227 -0
  123. package/src/__tests__/RecordComments.test.tsx +96 -0
  124. package/src/__tests__/RecordCommentsPinSearch.test.tsx +133 -0
  125. package/src/__tests__/RelatedList.test.tsx +66 -0
  126. package/src/__tests__/SubscriptionToggle.test.tsx +84 -0
  127. package/src/__tests__/ThreadedReplies.test.tsx +212 -0
  128. package/src/__tests__/autoLayout.test.ts +184 -0
  129. package/src/__tests__/phase12-features.test.tsx +583 -0
  130. package/src/autoLayout.ts +111 -0
  131. package/src/index.tsx +46 -0
  132. package/src/useDetailTranslation.ts +103 -0
@@ -0,0 +1,161 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ import * as React from 'react';
10
+ import { cn, Button } from '@object-ui/components';
11
+ import { MessageSquare, ChevronDown, ChevronRight, Send } from 'lucide-react';
12
+ import type { FeedItem } from '@object-ui/types';
13
+
14
+ export interface ThreadedRepliesProps {
15
+ /** Parent feed item (root comment) */
16
+ parentItem: FeedItem;
17
+ /** Reply feed items (children) */
18
+ replies: FeedItem[];
19
+ /** Called when a reply is submitted */
20
+ onAddReply?: (parentId: string | number, text: string) => void | Promise<void>;
21
+ /** Whether to show the reply input */
22
+ showReplyInput?: boolean;
23
+ className?: string;
24
+ }
25
+
26
+ function formatTimestamp(timestamp: string): string {
27
+ try {
28
+ const date = new Date(timestamp);
29
+ const now = new Date();
30
+ const diffMs = now.getTime() - date.getTime();
31
+ const diffMins = Math.floor(diffMs / 60000);
32
+
33
+ if (diffMins < 1) return 'just now';
34
+ if (diffMins < 60) return `${diffMins}m ago`;
35
+ const diffHours = Math.floor(diffMins / 60);
36
+ if (diffHours < 24) return `${diffHours}h ago`;
37
+ const diffDays = Math.floor(diffHours / 24);
38
+ if (diffDays < 7) return `${diffDays}d ago`;
39
+ return date.toLocaleDateString();
40
+ } catch {
41
+ return timestamp;
42
+ }
43
+ }
44
+
45
+ /**
46
+ * ThreadedReplies — Displays a collapsible thread of replies under a parent comment.
47
+ * Supports adding new replies and showing reply count.
48
+ */
49
+ export const ThreadedReplies: React.FC<ThreadedRepliesProps> = ({
50
+ parentItem,
51
+ replies,
52
+ onAddReply,
53
+ showReplyInput = true,
54
+ className,
55
+ }) => {
56
+ const [expanded, setExpanded] = React.useState(false);
57
+ const [replyText, setReplyText] = React.useState('');
58
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
59
+
60
+ const handleSubmitReply = React.useCallback(async () => {
61
+ const text = replyText.trim();
62
+ if (!text || !onAddReply) return;
63
+ setIsSubmitting(true);
64
+ try {
65
+ await onAddReply(parentItem.id, text);
66
+ setReplyText('');
67
+ } finally {
68
+ setIsSubmitting(false);
69
+ }
70
+ }, [replyText, onAddReply, parentItem.id]);
71
+
72
+ const handleKeyDown = React.useCallback(
73
+ (e: React.KeyboardEvent) => {
74
+ if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
75
+ e.preventDefault();
76
+ handleSubmitReply();
77
+ }
78
+ },
79
+ [handleSubmitReply],
80
+ );
81
+
82
+ if (replies.length === 0 && !showReplyInput) return null;
83
+
84
+ return (
85
+ <div className={cn('ml-10 mt-1', className)}>
86
+ {/* Toggle */}
87
+ {replies.length > 0 && (
88
+ <button
89
+ type="button"
90
+ className="flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors mb-1"
91
+ onClick={() => setExpanded(!expanded)}
92
+ aria-expanded={expanded}
93
+ >
94
+ {expanded ? (
95
+ <ChevronDown className="h-3 w-3" />
96
+ ) : (
97
+ <ChevronRight className="h-3 w-3" />
98
+ )}
99
+ <MessageSquare className="h-3 w-3" />
100
+ <span>{replies.length} {replies.length === 1 ? 'reply' : 'replies'}</span>
101
+ </button>
102
+ )}
103
+
104
+ {/* Replies list */}
105
+ {expanded && (
106
+ <div className="space-y-2 border-l-2 border-border pl-3">
107
+ {replies.map((reply) => (
108
+ <div key={reply.id} className="flex gap-2">
109
+ <div className="shrink-0">
110
+ {reply.actorAvatarUrl ? (
111
+ <img
112
+ src={reply.actorAvatarUrl}
113
+ alt={reply.actor}
114
+ className="h-6 w-6 rounded-full object-cover"
115
+ />
116
+ ) : (
117
+ <div className="h-6 w-6 rounded-full bg-muted flex items-center justify-center text-[10px] font-medium text-muted-foreground">
118
+ {reply.actor.charAt(0).toUpperCase()}
119
+ </div>
120
+ )}
121
+ </div>
122
+ <div className="flex-1 min-w-0">
123
+ <div className="flex items-center gap-1.5">
124
+ <span className="text-xs font-medium">{reply.actor}</span>
125
+ <span className="text-[10px] text-muted-foreground">
126
+ {formatTimestamp(reply.createdAt)}
127
+ </span>
128
+ </div>
129
+ <p className="text-xs whitespace-pre-wrap break-words">{reply.body}</p>
130
+ </div>
131
+ </div>
132
+ ))}
133
+ </div>
134
+ )}
135
+
136
+ {/* Reply input */}
137
+ {showReplyInput && onAddReply && (
138
+ <div className="flex gap-1.5 mt-1.5">
139
+ <input
140
+ className="flex-1 rounded-md border border-input bg-background px-2 py-1 text-xs placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
141
+ placeholder="Reply…"
142
+ value={replyText}
143
+ onChange={(e) => setReplyText(e.target.value)}
144
+ onKeyDown={handleKeyDown}
145
+ disabled={isSubmitting}
146
+ />
147
+ <Button
148
+ variant="ghost"
149
+ size="icon"
150
+ className="h-6 w-6 shrink-0"
151
+ onClick={handleSubmitReply}
152
+ disabled={!replyText.trim() || isSubmitting}
153
+ aria-label="Send reply"
154
+ >
155
+ <Send className="h-3 w-3" />
156
+ </Button>
157
+ </div>
158
+ )}
159
+ </div>
160
+ );
161
+ };
@@ -0,0 +1,119 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ import { describe, it, expect } from 'vitest';
10
+ import { render, screen } from '@testing-library/react';
11
+ import '@testing-library/jest-dom';
12
+ import { ActivityTimeline } from '../ActivityTimeline';
13
+ import type { ActivityEntry } from '@object-ui/types';
14
+
15
+ const mockActivities: ActivityEntry[] = [
16
+ {
17
+ id: '1',
18
+ type: 'create',
19
+ user: 'Alice',
20
+ timestamp: '2026-02-15T10:00:00Z',
21
+ },
22
+ {
23
+ id: '2',
24
+ type: 'field_change',
25
+ field: 'status',
26
+ oldValue: 'open',
27
+ newValue: 'in_progress',
28
+ user: 'Bob',
29
+ timestamp: '2026-02-16T08:30:00Z',
30
+ },
31
+ {
32
+ id: '3',
33
+ type: 'status_change',
34
+ field: 'stage',
35
+ newValue: 'Completed',
36
+ user: 'Charlie',
37
+ timestamp: '2026-02-16T09:00:00Z',
38
+ description: 'Moved to Completed stage',
39
+ },
40
+ {
41
+ id: '4',
42
+ type: 'comment',
43
+ user: 'Alice',
44
+ timestamp: '2026-02-16T09:30:00Z',
45
+ description: 'Added a comment',
46
+ },
47
+ ];
48
+
49
+ describe('ActivityTimeline', () => {
50
+ it('should render activity heading with count', () => {
51
+ render(<ActivityTimeline activities={mockActivities} />);
52
+ expect(screen.getByText('Activity')).toBeInTheDocument();
53
+ expect(screen.getByText('(4)')).toBeInTheDocument();
54
+ });
55
+
56
+ it('should render user names', () => {
57
+ render(<ActivityTimeline activities={mockActivities} />);
58
+ expect(screen.getAllByText('Alice')).toHaveLength(2);
59
+ expect(screen.getByText('Bob')).toBeInTheDocument();
60
+ expect(screen.getByText('Charlie')).toBeInTheDocument();
61
+ });
62
+
63
+ it('should show "No activity recorded" when empty', () => {
64
+ render(<ActivityTimeline activities={[]} />);
65
+ expect(screen.getByText('No activity recorded')).toBeInTheDocument();
66
+ });
67
+
68
+ it('should render field change description for field_change type', () => {
69
+ render(
70
+ <ActivityTimeline
71
+ activities={[
72
+ {
73
+ id: '1',
74
+ type: 'field_change',
75
+ field: 'priority',
76
+ oldValue: 'low',
77
+ newValue: 'high',
78
+ user: 'Eve',
79
+ timestamp: '2026-02-16T10:00:00Z',
80
+ },
81
+ ]}
82
+ />,
83
+ );
84
+ expect(screen.getByText(/Changed Priority from "low" to "high"/)).toBeInTheDocument();
85
+ });
86
+
87
+ it('should use description if provided', () => {
88
+ render(
89
+ <ActivityTimeline
90
+ activities={[
91
+ {
92
+ id: '1',
93
+ type: 'comment',
94
+ user: 'Alice',
95
+ timestamp: '2026-02-16T09:30:00Z',
96
+ description: 'Added a comment',
97
+ },
98
+ ]}
99
+ />,
100
+ );
101
+ expect(screen.getByText('Added a comment')).toBeInTheDocument();
102
+ });
103
+
104
+ it('should render create type with default description', () => {
105
+ render(
106
+ <ActivityTimeline
107
+ activities={[
108
+ {
109
+ id: '1',
110
+ type: 'create',
111
+ user: 'Eve',
112
+ timestamp: '2026-02-16T10:00:00Z',
113
+ },
114
+ ]}
115
+ />,
116
+ );
117
+ expect(screen.getByText('Created this record')).toBeInTheDocument();
118
+ });
119
+ });
@@ -0,0 +1,143 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ import { describe, it, expect } from 'vitest';
10
+ import { render, screen, fireEvent } from '@testing-library/react';
11
+ import '@testing-library/jest-dom';
12
+ import { ActivityTimeline } from '../ActivityTimeline';
13
+ import type { ActivityEntry } from '@object-ui/types';
14
+
15
+ const mockActivities: ActivityEntry[] = [
16
+ {
17
+ id: '1',
18
+ type: 'create',
19
+ user: 'Alice',
20
+ timestamp: '2026-02-15T10:00:00Z',
21
+ },
22
+ {
23
+ id: '2',
24
+ type: 'field_change',
25
+ field: 'status',
26
+ oldValue: 'open',
27
+ newValue: 'in_progress',
28
+ user: 'Bob',
29
+ timestamp: '2026-02-16T08:30:00Z',
30
+ },
31
+ {
32
+ id: '3',
33
+ type: 'comment',
34
+ user: 'Charlie',
35
+ timestamp: '2026-02-16T09:00:00Z',
36
+ description: 'Added a comment on the record',
37
+ },
38
+ {
39
+ id: '4',
40
+ type: 'delete',
41
+ user: 'Diana',
42
+ timestamp: '2026-02-16T09:30:00Z',
43
+ },
44
+ {
45
+ id: '5',
46
+ type: 'comment',
47
+ user: 'Eve',
48
+ timestamp: '2026-02-16T10:00:00Z',
49
+ description: 'Another comment here',
50
+ },
51
+ ];
52
+
53
+ describe('ActivityTimeline - Filtering', () => {
54
+ it('does not render filter controls when filterable is false/not provided', () => {
55
+ render(<ActivityTimeline activities={mockActivities} />);
56
+ expect(screen.queryByRole('group', { name: 'Activity type filter' })).not.toBeInTheDocument();
57
+ });
58
+
59
+ it('renders filter controls when filterable is true', () => {
60
+ render(<ActivityTimeline activities={mockActivities} filterable />);
61
+ const filterGroup = screen.getByRole('group', { name: 'Activity type filter' });
62
+ expect(filterGroup).toBeInTheDocument();
63
+
64
+ // Should have "All", "Field Changes", "Creates", "Deletes", "Comments", "Status Changes"
65
+ expect(screen.getByText('All')).toBeInTheDocument();
66
+ expect(screen.getByText('Comments')).toBeInTheDocument();
67
+ expect(screen.getByText('Field Changes')).toBeInTheDocument();
68
+ expect(screen.getByText('Creates')).toBeInTheDocument();
69
+ expect(screen.getByText('Deletes')).toBeInTheDocument();
70
+ });
71
+
72
+ it('shows all activities by default', () => {
73
+ render(<ActivityTimeline activities={mockActivities} filterable />);
74
+ // Count should be (5)
75
+ expect(screen.getByText('(5)')).toBeInTheDocument();
76
+ });
77
+
78
+ it('filters to only comments when Comments filter is selected', () => {
79
+ render(<ActivityTimeline activities={mockActivities} filterable />);
80
+
81
+ const commentsFilter = screen.getByText('Comments');
82
+ fireEvent.click(commentsFilter);
83
+
84
+ // Only 2 comment activities
85
+ expect(screen.getByText('(2)')).toBeInTheDocument();
86
+ expect(screen.getByText('Added a comment on the record')).toBeInTheDocument();
87
+ expect(screen.getByText('Another comment here')).toBeInTheDocument();
88
+ });
89
+
90
+ it('filters to only field changes when Field Changes filter is selected', () => {
91
+ render(<ActivityTimeline activities={mockActivities} filterable />);
92
+
93
+ const fieldChangesFilter = screen.getByText('Field Changes');
94
+ fireEvent.click(fieldChangesFilter);
95
+
96
+ // Only 1 field_change activity
97
+ expect(screen.getByText('(1)')).toBeInTheDocument();
98
+ });
99
+
100
+ it('shows all activities when All filter is re-selected', () => {
101
+ render(<ActivityTimeline activities={mockActivities} filterable />);
102
+
103
+ // First filter to comments only
104
+ fireEvent.click(screen.getByText('Comments'));
105
+ expect(screen.getByText('(2)')).toBeInTheDocument();
106
+
107
+ // Then go back to All
108
+ fireEvent.click(screen.getByText('All'));
109
+ expect(screen.getByText('(5)')).toBeInTheDocument();
110
+ });
111
+
112
+ it('respects defaultFilter prop', () => {
113
+ render(
114
+ <ActivityTimeline
115
+ activities={mockActivities}
116
+ filterable
117
+ defaultFilter="comment"
118
+ />,
119
+ );
120
+
121
+ // Should start filtered to comments
122
+ expect(screen.getByText('(2)')).toBeInTheDocument();
123
+ });
124
+
125
+ it('shows "No activity recorded" when filter has no results', () => {
126
+ render(
127
+ <ActivityTimeline
128
+ activities={mockActivities}
129
+ filterable
130
+ defaultFilter="status_change"
131
+ />,
132
+ );
133
+
134
+ expect(screen.getByText('No activity recorded')).toBeInTheDocument();
135
+ });
136
+
137
+ it('renders all activities without filter when filterable is not set', () => {
138
+ render(<ActivityTimeline activities={mockActivities} />);
139
+ expect(screen.getByText('(5)')).toBeInTheDocument();
140
+ expect(screen.getByText('Alice')).toBeInTheDocument();
141
+ expect(screen.getByText('Bob')).toBeInTheDocument();
142
+ });
143
+ });
@@ -0,0 +1,57 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ import { describe, it, expect, vi } from 'vitest';
10
+ import { render, screen, fireEvent } from '@testing-library/react';
11
+ import '@testing-library/jest-dom';
12
+ import { CommentInput } from '../CommentInput';
13
+
14
+ describe('CommentInput', () => {
15
+ it('should render placeholder text', () => {
16
+ const onSubmit = vi.fn();
17
+ render(<CommentInput onSubmit={onSubmit} />);
18
+ expect(screen.getByPlaceholderText('Leave a comment…')).toBeInTheDocument();
19
+ });
20
+
21
+ it('should render custom placeholder', () => {
22
+ const onSubmit = vi.fn();
23
+ render(<CommentInput onSubmit={onSubmit} placeholder="Type here…" />);
24
+ expect(screen.getByPlaceholderText('Type here…')).toBeInTheDocument();
25
+ });
26
+
27
+ it('should disable submit when textarea is empty', () => {
28
+ const onSubmit = vi.fn();
29
+ render(<CommentInput onSubmit={onSubmit} />);
30
+ expect(screen.getByLabelText('Submit comment')).toBeDisabled();
31
+ });
32
+
33
+ it('should enable submit when text is entered', () => {
34
+ const onSubmit = vi.fn();
35
+ render(<CommentInput onSubmit={onSubmit} />);
36
+ fireEvent.change(screen.getByPlaceholderText('Leave a comment…'), {
37
+ target: { value: 'Hello' },
38
+ });
39
+ expect(screen.getByLabelText('Submit comment')).not.toBeDisabled();
40
+ });
41
+
42
+ it('should call onSubmit with text when clicked', () => {
43
+ const onSubmit = vi.fn().mockResolvedValue(undefined);
44
+ render(<CommentInput onSubmit={onSubmit} />);
45
+ fireEvent.change(screen.getByPlaceholderText('Leave a comment…'), {
46
+ target: { value: 'Hello world' },
47
+ });
48
+ fireEvent.click(screen.getByLabelText('Submit comment'));
49
+ expect(onSubmit).toHaveBeenCalledWith('Hello world');
50
+ });
51
+
52
+ it('should disable input when disabled prop is true', () => {
53
+ const onSubmit = vi.fn();
54
+ render(<CommentInput onSubmit={onSubmit} disabled />);
55
+ expect(screen.getByPlaceholderText('Leave a comment…')).toBeDisabled();
56
+ });
57
+ });