Skip to content

Commit 8bb293f

Browse files
committed
test(app-shell): pin the conditional-formatting hold on an object page opened from 不在导航中; controls stay controls
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CXDf4Yt5PtKZFbtLVD
1 parent 4c38380 commit 8bb293f

1 file changed

Lines changed: 57 additions & 6 deletions

File tree

‎ui/packages/app-shell/src/views/studio-design/InterfacesPillar.offNavListViews-30046.test.tsx‎

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function seed() {
7777
formView('crm_lead', 'contact_us', 'Contact us'),
7878
listView('crm_case', 'open', 'Open cases', { isDefault: true }),
7979
listView('crm_case', 'mine', 'My cases', {}, {
80-
conditionalFormatting: [{ condition: "status == 'urgent'", style: { color: 'red' } }],
80+
conditionalFormatting: [{ condition: "record.status == 'urgent'", style: { color: 'red' } }],
8181
}),
8282
].map((row) => [row.name, row]),
8383
);
@@ -166,6 +166,23 @@ import { InterfacesPillar } from './StudioDesignSurface';
166166
import { registerMetadataPreview, type MetadataPreviewProps } from '../metadata-admin/preview-registry';
167167
import { t, tFormat } from '../metadata-admin/i18n';
168168
import { STUDIO_RAIL_ROW_ACTIVE } from './studio-tokens';
169+
import { __setCelFormulaLoader } from '../metadata-admin/celAuthoring';
170+
171+
/** A formula engine whose one verdict is: an expression that ends after an operator does not parse. */
172+
function stubCelEngine() {
173+
__setCelFormulaLoader(() =>
174+
Promise.resolve({
175+
validateExpression: (_role: string, input: unknown) => {
176+
const src = typeof input === 'string' ? input : String((input as { source?: string })?.source ?? '');
177+
return /[*+\-/&|=<>]\s*$/.test(src)
178+
? { ok: false, errors: [{ message: 'Parse error: expression ends after an operator' }], warnings: [] }
179+
: { ok: true, errors: [], warnings: [] };
180+
},
181+
introspectScope: () => ({ fields: ['name', 'status'], roots: ['record'], functions: ['has'] }),
182+
inferExpressionType: () => 'boolean' as const,
183+
}) as never,
184+
);
185+
}
169186

170187
/** A view page's canvas that says what it was opened on. */
171188
function StubPreview({ type, name }: MetadataPreviewProps) {
@@ -208,7 +225,10 @@ beforeEach(() => {
208225
for (const fn of [mockClient.save, mockClient.list, mockClient.listDrafts, previewClient.list]) fn.mockClear();
209226
window.confirm = vi.fn(() => false) as unknown as typeof window.confirm;
210227
});
211-
afterEach(cleanup);
228+
afterEach(() => {
229+
cleanup();
230+
__setCelFormulaLoader(undefined);
231+
});
212232

213233
/** The address the pillar writes, as a reload or a shared link reads it. */
214234
let address = new URLSearchParams();
@@ -273,14 +293,21 @@ describe('不在导航中 → 视图 lists what the dropdown does not reach (obj
273293
expect(names).not.toContain('view · crm_lead.drafted');
274294
});
275295

276-
it('CONTROL: the list views of an object with no entry stay listed, beside the form views', async () => {
296+
it('what is listed: the form views, and the list views of an object no entry opens', async () => {
277297
mountPillar();
278298
const group = await viewGroup();
279299
await viewsRead();
280300
expect(rowNames(group).sort()).toEqual(
281301
['view · crm_case.mine', 'view · crm_case.open', 'view · crm_lead.contact_us', 'view · crm_lead.form'].sort(),
282302
);
283303
});
304+
305+
it('CONTROL: the list views of an object with no entry stay listed', async () => {
306+
mountPillar();
307+
const group = await viewGroup();
308+
await viewsRead();
309+
expect(rowNames(group)).toEqual(expect.arrayContaining(['view · crm_case.mine', 'view · crm_case.open']));
310+
});
284311
});
285312

286313
describe('the group names what it holds, and a form view by a readable name (objectstack#30046 Scope 8)', () => {
@@ -310,12 +337,12 @@ describe('the group names what it holds, and a form view by a readable name (obj
310337
expect(forms).not.toHaveTextContent(t('engine.studio.if.offNav.viewMixed', 'en'));
311338
});
312339

313-
it('CONTROL: with only list views left, the heading stays 视图', async () => {
340+
it('CONTROL: with no form view, the heading stays 视图', async () => {
314341
for (const name of Object.keys(published)) if (published[name]!.viewKind === 'form') delete published[name];
315342
mountPillar();
316343
const group = await viewGroup();
317344
await viewsRead();
318-
expect(rowNames(group).sort()).toEqual(['view · crm_case.mine', 'view · crm_case.open']);
345+
expect(rowNames(group)).toEqual(expect.arrayContaining(['view · crm_case.mine', 'view · crm_case.open']));
319346
expect(group).toHaveTextContent(t('engine.studio.if.offNav.view', 'en'));
320347
expect(group).not.toHaveTextContent(t('engine.studio.if.offNav.viewForms', 'en'));
321348
});
@@ -350,7 +377,7 @@ describe('a list view opened from 不在导航中 lands on its object’s page (
350377

351378
const more = await screen.findByTestId('list-view-more', undefined, { timeout: 8000 });
352379
expect(within(more).getByTestId('list-view-conditional-formatting')).toBeInTheDocument();
353-
expect(within(more).getByDisplayValue("status == 'urgent'")).toBeInTheDocument();
380+
expect(within(more).getByDisplayValue("record.status == 'urgent'")).toBeInTheDocument();
354381
expect(within(more).getByTestId('list-view-spec-form')).toBeInTheDocument();
355382
});
356383

@@ -398,4 +425,28 @@ describe('a list view opened from 不在导航中 lands on its object’s page (
398425
expect(await screen.findByText('view:crm_lead.contact_us', undefined, { timeout: 8000 })).toBeInTheDocument();
399426
expect(screen.queryByTestId('studio-list-view-inspector')).toBeNull();
400427
});
428+
429+
it('a formatting rule whose CEL does not parse holds the view’s autosave, as the view page held Save', async () => {
430+
stubCelEngine();
431+
mountPillar();
432+
const group = await viewGroup();
433+
await viewsRead();
434+
fireEvent.click(within(group).getByRole('button', { name: 'My cases' }));
435+
await waitFor(() => expect(shownView()).toBe('crm_case.mine'), { timeout: 8000 });
436+
const rule = () => screen.getByTestId('cf-rule-0').querySelector('[role="combobox"]') as HTMLTextAreaElement;
437+
await waitFor(() => expect(rule()).toBeInTheDocument(), { timeout: 8000 });
438+
439+
fireEvent.change(rule(), { target: { value: 'record.status ==' } });
440+
await screen.findByTestId('studio-held', undefined, { timeout: 4000 });
441+
// Past the autosave's 1.5 s debounce: nothing was sent.
442+
await new Promise((r) => setTimeout(r, 2000));
443+
expect(mockClient.save.mock.calls.filter((c: unknown[]) => c[0] === 'view')).toEqual([]);
444+
445+
// Fixed, it is sent to the view it was made on.
446+
fireEvent.change(rule(), { target: { value: "record.status == 'open'" } });
447+
await waitFor(() => expect(mockClient.save.mock.calls.some((c: unknown[]) => c[0] === 'view')).toBe(true), { timeout: 8000 });
448+
const [, name, body] = mockClient.save.mock.calls.find((c: unknown[]) => c[0] === 'view') as [string, string, Record<string, any>];
449+
expect(name).toBe('crm_case.mine');
450+
expect(body.config.conditionalFormatting[0].condition).toBe("record.status == 'open'");
451+
}, 20000);
401452
});

0 commit comments

Comments
 (0)