Skip to content

Commit a9062bb

Browse files
test(app-shell): await the flow label in the canvas-chip header test (#38171)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoAoNwrZVJoUEFfvMURpRPKJ)_ Fixes #37822 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户无感:只改一条自动化测试,产品界面不变。 - 让流程画布标题测试不再偶发失败(测试在标题加载完成前就去读文字)。 - 出错只会让这条测试误报,可直接撤回。 - 要你做什么:无。 ## What changes `StudioDesignSurface.flowCanvasChip-11665.test.tsx` only. The canvas chip prints the API name until the flow loads (`flowTitle = current ? ... : flowName`), so the synchronous label and header-text reads after `caption()` raced the load. They now sit in `waitFor`. The fixture gains a `server.gate` that holds `list`/`layered`; a new case proves the chip is the API-name placeholder while held and the label after release; the API-name fallback case releases the gate and waits for `auto-flow-meta` so it no longer passes on the placeholder. ## Tests - File: 5/5 pass; 20 consecutive runs: 20 ok. - Ablation (header prints API name, `flowTitle = flowName`, reverted): zh, en and the new late-load case go red; the API-name case stays green by design (it is the fallback). - Old synchronous read vs late load: the new case asserts the placeholder while held, which is what the old sync assertion would have read. ## Acceptance notes No changeset: test file ships in no package. Header text reads (zh hint, en 'Visual orchestration') also sat synchronously; now awaited. Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent 9db1dc8 commit a9062bb

1 file changed

Lines changed: 37 additions & 9 deletions

File tree

‎ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.flowCanvasChip-11665.test.tsx‎

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,25 @@ const EDGES = [{ id: 'e1', source: 'start', target: 'end' }];
4242

4343
const server = vi.hoisted(() => ({
4444
active: new Map<string, Record<string, unknown>>(),
45+
// When set, `layered` waits on it: the label load answers late on demand.
46+
gate: null as Promise<void> | null,
4547
}));
4648

4749
const mockClient = vi.hoisted(() => {
4850
const k = (type: string, name: string) => `${type}/${name}`;
4951
return {
50-
list: vi.fn(async (type: string) =>
51-
[...server.active.entries()]
52+
list: vi.fn(async (type: string) => {
53+
if (server.gate) await server.gate;
54+
return [...server.active.entries()]
5255
.filter(([key]) => key.startsWith(`${type}/`))
53-
.map(([, row]) => ({ name: row.name, label: row.label ?? row.name })),
54-
),
56+
.map(([, row]) => ({ name: row.name, label: row.label ?? row.name }));
57+
}),
5558
listDrafts: vi.fn(async () => []),
5659
listTypes: vi.fn(async () => ({ entries: [] })),
5760
get: vi.fn(async () => null),
5861
references: vi.fn(async () => []),
5962
layered: vi.fn(async (type: string, name: string) => {
63+
if (server.gate) await server.gate;
6064
const eff = server.active.get(k(type, name)) ?? null;
6165
return { code: null, overlay: eff, overlayScope: eff ? 'env' : null, effective: eff, editable: true, deletable: true, resettable: false, lock: 'none' };
6266
}),
@@ -114,6 +118,7 @@ registerMetadataInspector('flow', FlowInspector);
114118

115119
beforeEach(() => {
116120
server.active.clear();
121+
server.gate = null;
117122
for (const fn of Object.values(mockClient)) (fn as unknown as { mockClear: () => void }).mockClear();
118123
});
119124

@@ -161,13 +166,15 @@ describe('the automation canvas header names the open flow by its label (objectu
161166
renderPillar('zh');
162167
const { chip, header } = await caption();
163168

164-
expect(chip).toHaveTextContent(/^每日摘要$/);
169+
// The chip first prints the API name (the flow is not loaded yet), so the
170+
// label is awaited, not read at once.
171+
await waitFor(() => expect(chip).toHaveTextContent(/^每日摘要$/));
165172
// `designer.field.apiName` lives in the lazily fetched `studio` namespace,
166173
// which answers from `en` until its zh catalogue lands and then re-renders
167174
// the pillar (`useStudioCatalogue`): the zh title is the answer after that.
168175
await waitFor(() => expect(chip).toHaveAttribute('title', `API 名称: ${API_NAME}`));
169176
// The neighbouring chip is the real zh `canvasHint`, so the header read is the whole strip.
170-
expect(header).toHaveTextContent('点选画布上的节点即可配置');
177+
await waitFor(() => expect(header).toHaveTextContent('点选画布上的节点即可配置'));
171178
expect(chip.textContent ?? '').not.toMatch(TYPE_WORD);
172179
expect(chip.getAttribute('title') ?? '').not.toMatch(TYPE_WORD);
173180
});
@@ -177,23 +184,44 @@ describe('the automation canvas header names the open flow by its label (objectu
177184
renderPillar('en');
178185
const { chip, header } = await caption();
179186

180-
expect(chip).toHaveTextContent(/^Nightly digest$/);
181-
expect(chip).toHaveAttribute('title', `API name: ${API_NAME}`);
182-
expect(header).toHaveTextContent('Visual orchestration');
187+
await waitFor(() => expect(chip).toHaveTextContent(/^Nightly digest$/));
188+
await waitFor(() => expect(chip).toHaveAttribute('title', `API name: ${API_NAME}`));
189+
await waitFor(() => expect(header).toHaveTextContent('Visual orchestration'));
183190
expect(chip.textContent ?? '').not.toMatch(TYPE_WORD);
184191
expect(chip.getAttribute('title') ?? '').not.toMatch(TYPE_WORD);
185192
});
186193

187194
it('a label that resolves to nothing falls back to the API name rather than an empty chip', async () => {
188195
serve('');
196+
// Hold the flow load, release it, and let it settle first: before the load
197+
// the chip already prints the API name, so reading it earlier would pass
198+
// on the placeholder rather than on the fallback.
199+
let release!: () => void;
200+
server.gate = new Promise<void>((r) => { release = r; });
189201
renderPillar('zh');
190202
const { chip, header } = await caption();
203+
release();
204+
await waitFor(() => expect(screen.getByTestId('auto-flow-meta')).toBeInTheDocument());
191205

192206
expect(chip).toHaveTextContent(new RegExp(`^${API_NAME}$`));
193207
expect(chip.textContent ?? '').not.toMatch(TYPE_WORD);
194208
expect(header).toBeInTheDocument();
195209
});
196210

211+
it('the label replaces the API name placeholder once a late load lands', async () => {
212+
serve('每日摘要');
213+
let release!: () => void;
214+
server.gate = new Promise<void>((r) => { release = r; });
215+
renderPillar('zh');
216+
const { chip } = await caption();
217+
218+
// Load held: the chip is the placeholder, so a synchronous label read here fails.
219+
expect(chip).toHaveTextContent(new RegExp(`^${API_NAME}$`));
220+
expect(chip).not.toHaveTextContent('每日摘要');
221+
release();
222+
await waitFor(() => expect(chip).toHaveTextContent(/^每日摘要$/));
223+
});
224+
197225
it('the type-word pattern sees what it is meant to catch (positive control)', () => {
198226
expect(TYPE_WORD.test('flow · nightly_digest')).toBe(true);
199227
expect(TYPE_WORD.test('Flow')).toBe(true);

0 commit comments

Comments
 (0)