Skip to content

Commit d7b8e9a

Browse files
committed
test(plugin-grid): flip the undeclared-name pins, add the withheld-package trigger, repair fixtures
1 parent 382682a commit d7b8e9a

10 files changed

Lines changed: 214 additions & 72 deletions

‎ui/packages/plugin-grid/src/__tests__/actionsColumnAndChips-12708.test.tsx‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ function renderGrid(opts: {
4545
schema?: Record<string, unknown>;
4646
objectFields?: Record<string, unknown>;
4747
wired?: boolean;
48+
/** Serves the object's schema (the rows stay inline), e.g. to declare actions. */
49+
dataSource?: Record<string, unknown>;
4850
} = {}) {
4951
const schema: any = {
5052
type: 'object-grid',
@@ -59,6 +61,7 @@ function renderGrid(opts: {
5961
<ObjectGrid
6062
schema={schema}
6163
objectFields={opts.objectFields}
64+
{...(opts.dataSource ? { dataSource: opts.dataSource as any } : {})}
6265
{...(wired ? { onEdit: vi.fn(), onDelete: vi.fn() } : {})}
6366
{...(opts.rowOperations ? { rowOperations: opts.rowOperations } : {})}
6467
/>
@@ -122,9 +125,21 @@ describe('objectui#12708 · CONTROL — a list whose rows offer actions keeps it
122125
});
123126

124127
it('draws it for a legacy row action that is not Edit or Delete, with nothing else wired', async () => {
125-
renderGrid({ wired: false, schema: { rowActions: ['archive'] } });
128+
// `archive` is declared on the object: a bare `rowActions` name draws only
129+
// when it names an action the object declares (objectstack#30169).
130+
renderGrid({
131+
wired: false,
132+
schema: { rowActions: ['archive'] },
133+
dataSource: {
134+
getObjectSchema: async (name: string) => ({
135+
name,
136+
fields: { name: { type: 'text' }, status: { type: 'text' } },
137+
actions: [{ name: 'archive', label: 'Archive' }],
138+
}),
139+
},
140+
});
126141
await settle();
127-
expect(actionsHeader()).not.toBeNull();
142+
await waitFor(() => expect(actionsHeader()).not.toBeNull());
128143
});
129144
});
130145

‎ui/packages/plugin-grid/src/__tests__/bulkActionMembers-8071.test.tsx‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,30 @@ describe('object-grid `bulkActions` members are BARE ACTION NAMES (objectui#8071
199199
}
200200
});
201201

202-
it('3. a name matching no declared action still reaches the bar, by name', async () => {
203-
// Not a hole: `resolveBulkActions` keeps unresolved names so a consumer's
204-
// `runner.registerHandler('<name>', …)` stays reachable. Pinned because it
205-
// is the one case where the member is read as a name AND stays one — which
206-
// is what makes row 1's promotion an observable event rather than the only
207-
// path a string could take.
208-
await renderAndSelectAll({ bulkActions: ['no_such_action'] });
209-
expect(await screen.findByTestId('bulk-action-no_such_action')).toHaveTextContent(
210-
'No Such Action',
211-
);
202+
it('3. a name matching no declared action draws NOTHING, and says so once (objectstack#30169)', async () => {
203+
// Trigger objectstack#30169: an action a disabled package withholds leaves
204+
// the served object, so its bare name matched nothing — and this row used
205+
// to pin that the bar still drew it by humanized name ("No Such Action"),
206+
// a button whose click toasted "not executable". The spec says the member
207+
// "names an action the object declares"; one that does not draws nothing.
208+
// The declared sibling keeps the bar up, so the absence is observed on a
209+
// rendered bar, not on a missing one.
210+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
211+
try {
212+
await renderAndSelectAll({ bulkActions: ['approve', 'no_such_action'] });
213+
await screen.findByTestId('bulk-action-approve');
214+
expect(renderedBulkActionIds()).toEqual(['bulk-action-approve']);
215+
expect(screen.queryByText('No Such Action')).not.toBeInTheDocument();
216+
// The drop is not silent: one development warning, naming the member.
217+
const named = () =>
218+
warn.mock.calls
219+
.map((args: unknown[]) => String(args[0]))
220+
.filter((line: string) => line.includes('ObjectGrid bulkActions'));
221+
await waitFor(() => expect(named()).toHaveLength(1));
222+
expect(named()[0]).toContain("'no_such_action'");
223+
} finally {
224+
warn.mockRestore();
225+
}
212226
});
213227
});
214228

‎ui/packages/plugin-grid/src/__tests__/bulkActionRefresh.test.tsx‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,24 @@ function makeDataSource() {
7171
} as any;
7272
}
7373

74-
function renderGrid(dataSource: any, handlers: Record<string, any>) {
74+
function renderGrid(dataSource: any, handlers: { approve: (...args: any[]) => unknown }) {
7575
const schema: any = {
7676
type: 'object-grid',
7777
objectName: OBJECT,
78-
// String bulk action — the path 下推 / 派工 travels.
79-
batchActions: ['approve'],
78+
// String bulk action. Since objectstack#30169 a bare name the object does
79+
// not declare draws nothing, and a declared one is promoted to a def and
80+
// runs through the dialog — so the one name still dispatched by string is
81+
// the canonical `'delete'` with no `onBulkDelete` wired, which reaches the
82+
// runner by name (the `delete` handler each test registers).
83+
batchActions: ['delete'],
8084
columns: [
8185
{ field: 'name', label: 'Name' },
8286
{ field: 'status', label: 'Status' },
8387
],
8488
pagination: { pageSize: 50 },
8589
};
8690
return render(
87-
<ActionProvider handlers={handlers}>
91+
<ActionProvider handlers={{ delete: handlers.approve }}>
8892
<ObjectGrid schema={schema} dataSource={dataSource} />
8993
</ActionProvider>,
9094
);
@@ -110,7 +114,7 @@ describe('ObjectGrid — string bulk action refreshes the list on success', () =
110114
expect(headerCheckbox).toBeTruthy();
111115
fireEvent.click(headerCheckbox);
112116

113-
const approveBtn = await screen.findByTestId('bulk-action-approve');
117+
const approveBtn = await screen.findByTestId('bulk-action-delete');
114118
fireEvent.click(approveBtn);
115119

116120
// The handler ran against the selected records.
@@ -140,7 +144,7 @@ describe('ObjectGrid — string bulk action refreshes the list on success', () =
140144

141145
const headerCheckbox = document.querySelector('thead [role="checkbox"]') as HTMLElement;
142146
fireEvent.click(headerCheckbox);
143-
const approveBtn = await screen.findByTestId('bulk-action-approve');
147+
const approveBtn = await screen.findByTestId('bulk-action-delete');
144148
fireEvent.click(approveBtn);
145149

146150
await waitFor(() => expect(approve).toHaveBeenCalledTimes(1));
@@ -301,8 +305,10 @@ describe('ObjectGrid — bulk dialog Done keeps selection in sync', () => {
301305
*
302306
* Both survive objectui#3002: a name that resolves to a declared object action
303307
* is now promoted to a def and routes through the dialog instead, so what still
304-
* reaches `dispatchBulkAction` is a consumer-registered runner handler
305-
* (`approve` here) and the canonical `'delete'`.
308+
* reaches `dispatchBulkAction` is the canonical `'delete'`: through
309+
* `onBulkDelete` when it is wired, and to the runner by name when it is not
310+
* (the `delete` handler `renderGrid` registers). A bare name the object does
311+
* not declare no longer reaches it at all (objectstack#30169).
306312
*/
307313
describe('ObjectGrid — dispatchBulkAction keeps selection in sync (#3056)', () => {
308314
const headerChecked = () =>
@@ -317,7 +323,7 @@ describe('ObjectGrid — dispatchBulkAction keeps selection in sync (#3056)', ()
317323
fireEvent.click(document.querySelector('thead [role="checkbox"]') as HTMLElement);
318324
await waitFor(() => expect(headerChecked()).toBe('checked'));
319325

320-
fireEvent.click(await screen.findByTestId('bulk-action-approve'));
326+
fireEvent.click(await screen.findByTestId('bulk-action-delete'));
321327
await waitFor(() => expect(approve).toHaveBeenCalledTimes(1));
322328

323329
await waitFor(() =>
@@ -335,7 +341,7 @@ describe('ObjectGrid — dispatchBulkAction keeps selection in sync (#3056)', ()
335341
fireEvent.click(document.querySelector('thead [role="checkbox"]') as HTMLElement);
336342
await waitFor(() => expect(headerChecked()).toBe('checked'));
337343

338-
fireEvent.click(await screen.findByTestId('bulk-action-approve'));
344+
fireEvent.click(await screen.findByTestId('bulk-action-delete'));
339345
await waitFor(() => expect(approve).toHaveBeenCalledTimes(1));
340346

341347
// Failure keeps BOTH sources, so the user can retry the same rows.

‎ui/packages/plugin-grid/src/__tests__/bulkActionsSpecKey.test.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ function makeDataSource() {
6969
name: { type: 'text' },
7070
status: { type: 'text' },
7171
},
72+
// Declared, because a bare bulk-action name draws only when the object
73+
// declares the action it names (objectstack#30169).
74+
actions: [
75+
{ name: 'approve', label: 'Approve' },
76+
{ name: 'reject', label: 'Reject' },
77+
],
7278
}),
7379
} as any;
7480
}

‎ui/packages/plugin-grid/src/__tests__/gridPagerSelectionMembers-8071.test.tsx‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,20 @@ const ROWS = Array.from({ length: 12 }, (_, i) => ({
8888
status: 'open',
8989
}));
9090

91-
function renderGrid(opts: Record<string, unknown>) {
91+
/**
92+
* A data source that serves only the object's schema, with `approve` declared:
93+
* a bare `bulkActions` name auto-enables selection only once it resolves to an
94+
* action the object declares (objectstack#30169). The rows stay inline.
95+
*/
96+
const DECLARES_APPROVE: any = {
97+
getObjectSchema: async (name: string) => ({
98+
name,
99+
fields: { id: { type: 'text' }, name: { type: 'text' }, status: { type: 'text' } },
100+
actions: [{ name: 'approve', label: 'Approve' }],
101+
}),
102+
};
103+
104+
function renderGrid(opts: Record<string, unknown>, dataSource?: any) {
92105
const schema: any = {
93106
type: 'object-grid',
94107
objectName: 'task',
@@ -101,7 +114,7 @@ function renderGrid(opts: Record<string, unknown>) {
101114
};
102115
return render(
103116
<ActionProvider>
104-
<ObjectGrid schema={schema} />
117+
<ObjectGrid schema={schema} {...(dataSource ? { dataSource } : {})} />
105118
</ActionProvider>,
106119
);
107120
}
@@ -236,15 +249,15 @@ describe('object-grid `selection`: presence enables, an explicit off wins (objec
236249
// `bulkActions` alone auto-enables multi-select (the row below proves it),
237250
// so this is the member deciding against a declaration that asks for the
238251
// opposite — and the author is told nothing.
239-
renderGrid({ ...paged, selection: { type: 'none' }, bulkActions: ['approve'] });
252+
renderGrid({ ...paged, selection: { type: 'none' }, bulkActions: ['approve'] }, DECLARES_APPROVE);
240253
await waitFor(() => expect(screen.getByText('Row 01')).toBeInTheDocument());
241254
expect(screen.queryAllByRole('checkbox')).toHaveLength(0);
242255
});
243256

244257
it('CONTROL — the same schema WITHOUT the member auto-enables multi-select', async () => {
245-
renderGrid({ ...paged, bulkActions: ['approve'] });
258+
renderGrid({ ...paged, bulkActions: ['approve'] }, DECLARES_APPROVE);
246259
await waitFor(() => expect(screen.getByText('Row 01')).toBeInTheDocument());
247-
expect(screen.getAllByRole('checkbox')).toHaveLength(6);
260+
await waitFor(() => expect(screen.getAllByRole('checkbox')).toHaveLength(6));
248261
});
249262

250263
it('`none` also beats the deprecated `selectable: true`', async () => {

‎ui/packages/plugin-grid/src/__tests__/legacyRowActionDispatch.test.tsx‎

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,31 @@ describe('legacy string rowActions dispatch (objectui#2960)', () => {
160160
expect(screen.getAllByTestId('row-action-convert_lead')).toHaveLength(1);
161161
});
162162

163-
it('leaves a name with no declared action to the by-name handler path', async () => {
164-
// Consumers may register a runner handler under exactly this name, so the
165-
// entry must still render and still dispatch.
166-
await openRowMenu({
167-
objectActions: [CONVERT_LEAD],
168-
schema: { rowActions: ['crm_only_handler'] },
169-
});
163+
it('draws no entry for a name the object does not declare, and warns once naming it (objectstack#30169)', async () => {
164+
// Trigger objectstack#30169: an action a disabled package withholds is
165+
// absent from the served object, so its bare name matched nothing and the
166+
// menu drew a humanized entry that toasted "not executable". The spec says
167+
// a bare name "names an action the object declares"; one that does not
168+
// draws nothing, and development says which name it dropped.
169+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
170+
try {
171+
await openRowMenu({
172+
objectActions: [CONVERT_LEAD],
173+
schema: { rowActions: ['convert_lead', 'crm_only_handler'] },
174+
});
170175

171-
expect(screen.getByTestId('row-action-crm_only_handler')).toBeInTheDocument();
172-
// Nothing resolvable to call — and with the runner's fallback now failing
173-
// loudly, no request and no success are reported.
174-
await userEvent.click(screen.getByTestId('row-action-crm_only_handler'));
175-
await waitFor(() => expect(fetchMock).not.toHaveBeenCalled());
176+
// The declared sibling still draws, so the menu is open and populated.
177+
expect(screen.getByTestId('row-action-convert_lead')).toBeInTheDocument();
178+
expect(screen.queryByTestId('row-action-crm_only_handler')).not.toBeInTheDocument();
179+
const lines = warn.mock.calls
180+
.map((args) => String(args[0]))
181+
.filter((line) => line.includes('ObjectGrid rowActions'));
182+
expect(lines).toHaveLength(1);
183+
expect(lines[0]).toContain("'crm_only_handler'");
184+
expect(lines[0]).not.toContain("'convert_lead'");
185+
} finally {
186+
warn.mockRestore();
187+
}
176188
});
177189
});
178190

‎ui/packages/plugin-grid/src/__tests__/objectBulkActionDispatch.test.tsx‎

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,11 @@ describe('view-declared bulk actions (objectui#3002)', () => {
210210
await waitFor(() => expect(screen.getAllByTestId('bulk-action-push_down')).toHaveLength(1));
211211
});
212212

213-
it('keeps an unresolvable name alongside the promoted defs', async () => {
214-
// A name the object never declared may still have a runner handler
215-
// registered under it; hiding it because some OTHER def exists dropped
216-
// half the bar's buttons.
213+
it('draws no button for a name the object does not declare, even with a runner handler under it (objectstack#30169)', async () => {
214+
// Trigger objectstack#30169. The spec says a bare `bulkActions` name "names
215+
// an action the object declares", and lint `action-name-undefined` refuses
216+
// any other. A runner handler registered under the name is client code,
217+
// not a declaration, so it does not bring the button back.
217218
const handler = vi.fn(async () => ({ success: true }));
218219
await renderAndSelectAll({
219220
objectActions: [PUSH_DOWN],
@@ -222,9 +223,63 @@ describe('view-declared bulk actions (objectui#3002)', () => {
222223
});
223224

224225
expect(await screen.findByTestId('bulk-action-push_down')).toBeInTheDocument();
225-
const legacy = await screen.findByTestId('bulk-action-crm_only_handler');
226-
fireEvent.click(legacy);
227-
await waitFor(() => expect(handler).toHaveBeenCalledTimes(1));
226+
expect(screen.queryByTestId('bulk-action-crm_only_handler')).not.toBeInTheDocument();
227+
expect(handler).not.toHaveBeenCalled();
228+
});
229+
});
230+
231+
/**
232+
* objectstack#30169 — the selection bar and a disabled package. With the
233+
* package disabled the server withholds its actions: they leave the served
234+
* object's `actions`, exactly as if never declared. The view still names one
235+
* in `bulkActions` as a bare string (the spec accepts it). Before the fix the
236+
* bar drew it anyway, under its humanized name ("Create Campaign"), and the
237+
* click toasted "not executable". Now the bar draws only what the object
238+
* declares: withheld, no button and one development warning naming it;
239+
* served, the button under the action's own label.
240+
*/
241+
describe('a bulk action a disabled package withholds (objectstack#30169)', () => {
242+
/** The package's action. Its label is NOT the humanized name, on purpose. */
243+
const CREATE_CAMPAIGN = {
244+
name: 'create_campaign',
245+
label: 'Add to Campaign',
246+
type: 'api',
247+
target: '/api/v1/campaigns/add',
248+
};
249+
const VIEW = { bulkActions: ['push_down', 'create_campaign'] };
250+
251+
const bulkActionWarnings = (warn: { mock: { calls: unknown[][] } }) =>
252+
warn.mock.calls
253+
.map((args) => String(args[0]))
254+
.filter((line) => line.includes('ObjectGrid bulkActions'));
255+
256+
it('withheld: the served object lacks it, so the bar draws no button and warns once naming it', async () => {
257+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
258+
try {
259+
await renderAndSelectAll({ objectActions: [PUSH_DOWN], schema: VIEW });
260+
261+
// The declared sibling is drawn, so the bar is up and populated.
262+
expect(await screen.findByTestId('bulk-action-push_down')).toBeInTheDocument();
263+
expect(screen.queryByTestId('bulk-action-create_campaign')).not.toBeInTheDocument();
264+
expect(screen.queryByText('Create Campaign')).not.toBeInTheDocument();
265+
await waitFor(() => expect(bulkActionWarnings(warn)).toHaveLength(1));
266+
expect(bulkActionWarnings(warn)[0]).toContain("'create_campaign'");
267+
expect(bulkActionWarnings(warn)[0]).not.toContain("'push_down'");
268+
} finally {
269+
warn.mockRestore();
270+
}
271+
});
272+
273+
it('served: the same view draws it under the action label, and stays quiet', async () => {
274+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
275+
try {
276+
await renderAndSelectAll({ objectActions: [PUSH_DOWN, CREATE_CAMPAIGN], schema: VIEW });
277+
278+
expect(await screen.findByTestId('bulk-action-create_campaign')).toHaveTextContent('Add to Campaign');
279+
expect(bulkActionWarnings(warn)).toEqual([]);
280+
} finally {
281+
warn.mockRestore();
282+
}
228283
});
229284
});
230285

0 commit comments

Comments
 (0)