|
33 | 33 | */ |
34 | 34 |
|
35 | 35 | import * as React from 'react'; |
36 | | -import { describe, it, expect, vi, beforeEach } from 'vitest'; |
| 36 | +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; |
37 | 37 | import { render, screen, waitFor, cleanup, fireEvent } from '@testing-library/react'; |
38 | 38 | import { RecordContextProvider, DiscussionContextProvider } from '@object-ui/react'; |
39 | 39 | import type { FeedItem } from '@object-ui/types'; |
40 | 40 | import { RecordActivityRenderer } from '../record-activity'; |
| 41 | +import { resetWithheldCommentComposerWarnings } from '../recordActivityFeed'; |
41 | 42 |
|
42 | 43 | const COMPOSER_PLACEHOLDER = 'Leave a comment… (Ctrl+Enter to submit)'; |
43 | 44 | const EMPTY_FEED = 'No activity recorded'; |
@@ -329,3 +330,100 @@ describe('record:activity — showSubscriptionToggle is the one documented gap', |
329 | 330 | expect(screen.queryByLabelText('Unsubscribe from notifications')).toBeNull(); |
330 | 331 | }); |
331 | 332 | }); |
| 333 | + |
| 334 | +/** |
| 335 | + * objectstack#34371 — a `types` allow-list that leaves out `comment` filters |
| 336 | + * every comment out of the block, the ones posted on it included, so the block |
| 337 | + * offers no composer and no Comments-only filter, and says why once in |
| 338 | + * development. HotCRM's `lead_detail` page authors exactly that shape |
| 339 | + * (`types: ['task']`, `showCompleted: true`); the controls are the same block |
| 340 | + * with `comment` admitted, and with no `types` at all. |
| 341 | + */ |
| 342 | +describe('record:activity — a types list without comment offers no comment composer (objectstack#34371)', () => { |
| 343 | + const FILTER_TRIGGER = 'Filter activity'; |
| 344 | + const COMMENTS_ONLY = 'Comments Only'; |
| 345 | + const FEED: FeedItem[] = [ |
| 346 | + { id: 'c1', type: 'comment', actor: 'Ada', body: 'a posted comment', createdAt: '2026-11-16T09:47:37.000Z' }, |
| 347 | + { id: 't1', type: 'task', actor: 'Ada', body: 'Meeting held', createdAt: '2026-11-16T09:30:00.000Z' }, |
| 348 | + ]; |
| 349 | + const HOTCRM_LEAD_ACTIVITY = { types: ['task'], limit: 20, showCompleted: true }; |
| 350 | + const withHost = (node: React.ReactNode) => ( |
| 351 | + <DiscussionContextProvider items={FEED as any} onAddComment={vi.fn()}> |
| 352 | + {node} |
| 353 | + </DiscussionContextProvider> |
| 354 | + ); |
| 355 | + const mountBlock = (properties: Record<string, unknown>) => |
| 356 | + mountBound({ type: 'record:activity', id: 'lead_activity', properties }, makeDataSource(), withHost); |
| 357 | + |
| 358 | + /** The dropdown's option labels, read by opening the Radix Select. */ |
| 359 | + async function filterOptionLabels(): Promise<string[]> { |
| 360 | + fireEvent.keyDown(screen.getByRole('combobox', { name: FILTER_TRIGGER }), { key: 'ArrowDown' }); |
| 361 | + await waitFor(() => expect(screen.queryAllByRole('option').length).toBeGreaterThan(0)); |
| 362 | + return screen.getAllByRole('option').map((o) => o.textContent ?? ''); |
| 363 | + } |
| 364 | + |
| 365 | + let warn: ReturnType<typeof vi.spyOn>; |
| 366 | + beforeEach(() => { |
| 367 | + resetWithheldCommentComposerWarnings(); |
| 368 | + warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); |
| 369 | + }); |
| 370 | + afterEach(() => { |
| 371 | + warn.mockRestore(); |
| 372 | + }); |
| 373 | + |
| 374 | + const withheldWarnings = () => |
| 375 | + (warn.mock.calls as unknown[][]) |
| 376 | + .map((c: unknown[]) => String(c[0])) |
| 377 | + .filter((m: string) => m.includes('offers no comment composer')); |
| 378 | + |
| 379 | + it('the HotCRM shape (types: [task]) draws no composer and no Comments-only option', async () => { |
| 380 | + mountBlock(HOTCRM_LEAD_ACTIVITY); |
| 381 | + expect(await screen.findByText('Meeting held')).toBeTruthy(); |
| 382 | + expect(screen.queryByText('a posted comment')).toBeNull(); |
| 383 | + expect(screen.queryByPlaceholderText(COMPOSER_PLACEHOLDER)).toBeNull(); |
| 384 | + const options = await filterOptionLabels(); |
| 385 | + expect(options).toContain('All Activity'); |
| 386 | + expect(options).not.toContain(COMMENTS_ONLY); |
| 387 | + }); |
| 388 | + |
| 389 | + it('CONTROL: types that admits comment keeps the composer and the option, and the comment shows', async () => { |
| 390 | + mountBlock({ ...HOTCRM_LEAD_ACTIVITY, types: ['task', 'comment'] }); |
| 391 | + expect(await screen.findByText('a posted comment')).toBeTruthy(); |
| 392 | + expect(screen.getByPlaceholderText(COMPOSER_PLACEHOLDER)).toBeTruthy(); |
| 393 | + expect(await filterOptionLabels()).toContain(COMMENTS_ONLY); |
| 394 | + expect(withheldWarnings()).toHaveLength(0); |
| 395 | + }); |
| 396 | + |
| 397 | + it('CONTROL: no types keeps the composer and the option, and the comment shows', async () => { |
| 398 | + mountBlock({ limit: 20, showCompleted: true }); |
| 399 | + expect(await screen.findByText('a posted comment')).toBeTruthy(); |
| 400 | + expect(screen.getByPlaceholderText(COMPOSER_PLACEHOLDER)).toBeTruthy(); |
| 401 | + expect(await filterOptionLabels()).toContain(COMMENTS_ONLY); |
| 402 | + expect(withheldWarnings()).toHaveLength(0); |
| 403 | + }); |
| 404 | + |
| 405 | + it('warns once, naming the block, its types and both fixes, however often it renders', async () => { |
| 406 | + const first = mountBlock(HOTCRM_LEAD_ACTIVITY); |
| 407 | + expect(await screen.findByText('Meeting held')).toBeTruthy(); |
| 408 | + first.rerender( |
| 409 | + <RecordContextProvider objectName="crm_account" recordId="rec-alpha" data={{ id: 'rec-alpha', name: 'Alpha' }} dataSource={makeDataSource()}> |
| 410 | + {withHost(<RecordActivityRenderer schema={{ type: 'record:activity', id: 'lead_activity', properties: { ...HOTCRM_LEAD_ACTIVITY } } as any} />)} |
| 411 | + </RecordContextProvider>, |
| 412 | + ); |
| 413 | + first.unmount(); |
| 414 | + mountBlock(HOTCRM_LEAD_ACTIVITY); |
| 415 | + expect(await screen.findByText('Meeting held')).toBeTruthy(); |
| 416 | + const said = withheldWarnings(); |
| 417 | + expect(said).toHaveLength(1); |
| 418 | + expect(said[0]).toContain('record:activity "lead_activity"'); |
| 419 | + expect(said[0]).toContain('["task"]'); |
| 420 | + expect(said[0]).toContain('add "comment" to `types`'); |
| 421 | + expect(said[0]).toContain('`showCommentInput: false`'); |
| 422 | + }); |
| 423 | + |
| 424 | + it('an author who switched the composer off is not told anything', async () => { |
| 425 | + mountBlock({ ...HOTCRM_LEAD_ACTIVITY, showCommentInput: false }); |
| 426 | + expect(await screen.findByText('Meeting held')).toBeTruthy(); |
| 427 | + expect(withheldWarnings()).toHaveLength(0); |
| 428 | + }); |
| 429 | +}); |
0 commit comments