|
| 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 | +/** |
| 10 | + * objectstack#36193 — while the comment panel holds the record's comments |
| 11 | + * (objectstack#36075), the 概览 tab's 「最近动态」 card lists the system |
| 12 | + * history alone: no comment, no reply, no 「讨论」 heading, a count of the |
| 13 | + * system entries only, and no card at all when there is no system history. |
| 14 | + * |
| 15 | + * The case that broke it: a slotted page whose `discussion` slot holds |
| 16 | + * `record:chatter`. The chatter block draws the timeline's panel face — the |
| 17 | + * 「讨论 (N)」 heading, the 全部动态 filter, every comment and its replies — |
| 18 | + * and the card drew it as it came. The default `record:activity` stream |
| 19 | + * already dropped the comments (objectstack#36075); it is the CONTROL here. |
| 20 | + * |
| 21 | + * Drawn through the real page (`buildDefaultPageSchema` → |
| 22 | + * `buildDefaultPageColumns` → `RecordPageColumns`, real block renderers). |
| 23 | + */ |
| 24 | + |
| 25 | +import * as React from 'react'; |
| 26 | +import { describe, it, expect, afterEach } from 'vitest'; |
| 27 | +import { render, cleanup, waitFor } from '@testing-library/react'; |
| 28 | +import { DiscussionContextProvider } from '@object-ui/react'; |
| 29 | +import type { FeedItem } from '@object-ui/types'; |
| 30 | +import { RecordPageColumns } from '../RecordPageColumns'; |
| 31 | +import { RecordCommentsInPanelContext } from '../recordTimelineStream'; |
| 32 | +import { buildDefaultPageColumns } from '../synth/recordPageColumns'; |
| 33 | +import { buildDefaultPageSchema } from '../synth/buildDefaultPageSchema'; |
| 34 | +import { railStreamNodes } from '../RecordSummaryRail'; |
| 35 | +import '../index'; |
| 36 | + |
| 37 | +afterEach(cleanup); |
| 38 | + |
| 39 | +const comment: FeedItem = { id: 'c1', type: 'comment', actor: 'Ada', body: 'Follow up on the renewal quote', createdAt: '2026-11-21T10:00:00Z' }; |
| 40 | +const reply: FeedItem = { id: 'c2', type: 'comment', actor: 'Ada', body: 'Got it', parentId: 'c1', createdAt: '2026-11-21T10:05:00Z' }; |
| 41 | +const system: FeedItem = { id: 's1', type: 'system', actor: 'System', body: 'Owner changed to Ada', createdAt: '2026-11-20T09:00:00Z' }; |
| 42 | + |
| 43 | +const OBJECT = { name: 'account', label: 'Account', fields: { name: { name: 'name', type: 'text' } } }; |
| 44 | + |
| 45 | +const chatterColumns = () => |
| 46 | + buildDefaultPageColumns( |
| 47 | + buildDefaultPageSchema(OBJECT as any, { |
| 48 | + slots: { discussion: { type: 'record:chatter', id: 'account_chatter', properties: {} } }, |
| 49 | + } as any), |
| 50 | + )!; |
| 51 | +const activityColumns = () => buildDefaultPageColumns(buildDefaultPageSchema(OBJECT as any, {}))!; |
| 52 | + |
| 53 | +function draw(columns: ReturnType<typeof chatterColumns>, items: FeedItem[], inPanel: boolean) { |
| 54 | + return render( |
| 55 | + <RecordCommentsInPanelContext.Provider value={inPanel}> |
| 56 | + <DiscussionContextProvider items={items as any[]} loading={false} onAddComment={(async () => {}) as any}> |
| 57 | + <RecordPageColumns tier="wide" columns={columns} onEnlargeRelated={() => {}} /> |
| 58 | + </DiscussionContextProvider> |
| 59 | + </RecordCommentsInPanelContext.Provider>, |
| 60 | + ); |
| 61 | +} |
| 62 | + |
| 63 | +const CARD = '[data-record-summary-card="timeline"]'; |
| 64 | +const cardOf = (container: HTMLElement) => container.querySelector(CARD) as HTMLElement | null; |
| 65 | +const shown = (card: HTMLElement | null) => !!card && !card.closest('[hidden]') && !card.hasAttribute('hidden'); |
| 66 | + |
| 67 | +describe('the 最近动态 card while the comments are in the panel (objectstack#36193)', () => { |
| 68 | + it('a slotted record:chatter stream: system history only, no 讨论 heading, the system count', async () => { |
| 69 | + const { container } = draw(chatterColumns(), [system, comment, reply], true); |
| 70 | + const card = cardOf(container)!; |
| 71 | + await waitFor(() => expect(card.textContent).toContain('Owner changed to Ada')); |
| 72 | + expect(card.textContent).not.toContain('Follow up on the renewal quote'); |
| 73 | + expect(card.textContent).not.toContain('Got it'); |
| 74 | + expect(card.textContent).not.toMatch(/Discussion|讨论/); |
| 75 | + expect(card.querySelector('[data-record-timeline-peek]')).toBeTruthy(); |
| 76 | + expect(card.querySelector('textarea')).toBeNull(); |
| 77 | + await waitFor(() => expect(card.querySelector('[data-record-summary-card-count]')?.textContent).toBe('1')); |
| 78 | + expect(shown(card)).toBe(true); |
| 79 | + }); |
| 80 | + |
| 81 | + it('no system history: the card is not drawn, a comment does not bring it back', async () => { |
| 82 | + const { container } = draw(chatterColumns(), [comment, reply], true); |
| 83 | + await waitFor(() => expect(shown(cardOf(container))).toBe(false)); |
| 84 | + }); |
| 85 | + |
| 86 | + it('CONTROL — without the panel the chatter card is the page\'s own: comments and all', async () => { |
| 87 | + const { container } = draw(chatterColumns(), [system, comment], false); |
| 88 | + const card = cardOf(container)!; |
| 89 | + await waitFor(() => expect(card.textContent).toContain('Follow up on the renewal quote')); |
| 90 | + }); |
| 91 | + |
| 92 | + it('CONTROL — the default record:activity stream already lists the system history only', async () => { |
| 93 | + const { container } = draw(activityColumns(), [system, comment, reply], true); |
| 94 | + const card = cardOf(container)!; |
| 95 | + await waitFor(() => expect(card.textContent).toContain('Owner changed to Ada')); |
| 96 | + expect(card.textContent).not.toContain('Follow up on the renewal quote'); |
| 97 | + }); |
| 98 | + |
| 99 | + it('railStreamNodes hands the nodes back untouched without the panel, and leaves record:activity alone', () => { |
| 100 | + const nodes = [{ type: 'record:chatter', properties: { feed: { types: ['comment', 'system'] } } }, { type: 'record:activity' }]; |
| 101 | + expect(railStreamNodes(nodes, false)).toBe(nodes); |
| 102 | + const drawn = railStreamNodes(nodes, true); |
| 103 | + expect(drawn[0]).toEqual({ type: 'record:activity', properties: { types: ['comment', 'system'] } }); |
| 104 | + expect(drawn[1]).toBe(nodes[1]); |
| 105 | + }); |
| 106 | +}); |
0 commit comments