Skip to content

Commit b192892

Browse files
committed
test(plugin-chatbot): the pending-count pulse pin waits for the count render, not for the button
The draft card draws its 发布 button before the first fetchPendingDraftCount read answers; the count lands on a later render. Both tests read the count with a one-shot toHaveTextContent right after findByTestId, which resolves on the button alone, so under load the check could run before that render and read 发布 instead of 发布 (2) — the merge-queue ejections' signature. The pin now waits for the render that carries the count. Product code unchanged. Claude-Session: https://claude.ai/code/session_01J8VVAkq9LgnKiBeyJBZqSp Co-authored-by: Claude <noreply@anthropic.com>
1 parent f6ffd72 commit b192892

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

‎ui/packages/plugin-chatbot/src/__tests__/ChatbotEnhanced.pendingCountPulse-26471.test.tsx‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
import '@testing-library/jest-dom/vitest';
2323
import { afterEach, describe, expect, it, vi } from 'vitest';
24-
import { act, cleanup, render, screen } from '@testing-library/react';
24+
import { act, cleanup, render, screen, waitFor } from '@testing-library/react';
2525
import { ChatbotEnhanced, type ChatbotEnhancedMessage } from '../ChatbotEnhanced';
2626
import { detectDraftResult } from '../mapMessages';
2727

@@ -81,14 +81,24 @@ function chat(pulse: ReturnType<typeof makePulse>, fetchPendingDraftCount: (pkg:
8181
);
8282
}
8383

84+
/**
85+
* The button draws with the card, before the first count read answers; the
86+
* count lands on a later render. `findByTestId` resolves on the button alone,
87+
* so a one-shot text check after it races that render (objectstack#26647):
88+
* wait for the render that carries the count.
89+
*/
90+
async function expectPublishButtonText(text: string) {
91+
await waitFor(() => expect(screen.getByTestId('draft-publish')).toHaveTextContent(text));
92+
}
93+
8494
describe('objectstack#26471 — the draft card re-reads its pending count on the metadata pulse', () => {
8595
it('发布 (2), then a publish elsewhere fires the pulse and the card stops offering 发布', async () => {
8696
const pulse = makePulse();
8797
let pending = 2;
8898
const fetchPendingDraftCount = vi.fn(async (_pkg: string) => pending);
8999
const { rerender } = render(chat(pulse, fetchPendingDraftCount));
90100

91-
expect(await screen.findByTestId('draft-publish')).toHaveTextContent('发布 (2)');
101+
await expectPublishButtonText('发布 (2)');
92102
expect(fetchPendingDraftCount).toHaveBeenCalledTimes(1);
93103
expect(fetchPendingDraftCount).toHaveBeenCalledWith(PACKAGE_ID);
94104

@@ -113,7 +123,7 @@ describe('objectstack#26471 — the draft card re-reads its pending count on the
113123
const fetchPendingDraftCount = vi.fn(async (_pkg: string) => 2);
114124
const { unmount } = render(chat(pulse, fetchPendingDraftCount));
115125

116-
expect(await screen.findByTestId('draft-publish')).toHaveTextContent('发布 (2)');
126+
await expectPublishButtonText('发布 (2)');
117127
expect(pulse.listeners.size).toBe(1);
118128

119129
unmount();

0 commit comments

Comments
 (0)