Skip to content

Commit dccc261

Browse files
committed
test(console): read the picker once its list has loaded
Claude-Session: https://claude.ai/code/session_01FEkQ5ntiCZev2cDL6r5VLw Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5197c40 commit dccc261

1 file changed

Lines changed: 15 additions & 18 deletions

File tree

‎ui/packages/plugin-form/src/__tests__/objectFormShareableObjectRef-31217.test.tsx‎

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ function mount(answer: () => Promise<Response>, initialData?: Record<string, unk
8888
return { ds, apiFetch, ...view };
8989
}
9090

91-
/** Open the picker and read its options, in the order drawn. */
91+
/** Once the picker has its list, open it and read its options, in the order drawn. */
9292
async function openOptions(): Promise<string[]> {
93-
const trigger = await screen.findByRole('combobox');
94-
fireEvent.click(trigger);
93+
await waitFor(() => expect(screen.getByRole('combobox')).not.toHaveTextContent(/Loading/));
94+
fireEvent.click(screen.getByRole('combobox'));
9595
const listbox = await screen.findByRole('listbox');
9696
return within(listbox)
9797
.getAllByRole('option')
@@ -106,11 +106,10 @@ describe('the sharing-rule object picker lists only shareable objects (objectsta
106106

107107
await waitFor(() => expect(apiFetch).toHaveBeenCalled());
108108
expect(String(apiFetch.mock.calls[0][0])).toBe(SHAREABLE_OBJECTS_URL);
109-
await waitFor(async () =>
110-
expect(await openOptions()).toEqual(['Account (crm_account)', 'Opportunity (crm_opportunity)', 'Team (sys_team)']),
111-
);
109+
const options = await openOptions();
110+
expect(options).toEqual(['Account (crm_account)', 'Opportunity (crm_opportunity)', 'Team (sys_team)']);
112111
// No credential or session object, and no object the save would refuse.
113-
const drawn = (await openOptions()).join(' | ');
112+
const drawn = options.join(' | ');
114113
expect(drawn).not.toContain('sys_session');
115114
expect(drawn).not.toContain('sys_api_key');
116115
expect(drawn).not.toContain('crm_audit_note');
@@ -121,7 +120,7 @@ describe('the sharing-rule object picker lists only shareable objects (objectsta
121120
it('CONTROL: a shareable object stays selectable and the form saves its name', async () => {
122121
const { ds, container } = mount(json(200, DOOR_ANSWER));
123122

124-
await waitFor(async () => expect(await openOptions()).toContain('Opportunity (crm_opportunity)'));
123+
expect(await openOptions()).toContain('Opportunity (crm_opportunity)');
125124
fireEvent.click(screen.getByRole('option', { name: 'Opportunity (crm_opportunity)' }));
126125
const trigger = screen.getByRole('combobox');
127126
await waitFor(() => expect(trigger).toHaveTextContent('Opportunity (crm_opportunity)'));
@@ -135,14 +134,12 @@ describe('the sharing-rule object picker lists only shareable objects (objectsta
135134
it('keeps a stored object the door does not list, so editing never drops it', async () => {
136135
mount(json(200, DOOR_ANSWER), { object_name: 'crm_audit_note' });
137136

138-
await waitFor(async () =>
139-
expect(await openOptions()).toEqual([
140-
'crm_audit_note',
141-
'Account (crm_account)',
142-
'Opportunity (crm_opportunity)',
143-
'Team (sys_team)',
144-
]),
145-
);
137+
expect(await openOptions()).toEqual([
138+
'crm_audit_note',
139+
'Account (crm_account)',
140+
'Opportunity (crm_opportunity)',
141+
'Team (sys_team)',
142+
]);
146143
});
147144

148145
it.each([
@@ -152,9 +149,9 @@ describe('the sharing-rule object picker lists only shareable objects (objectsta
152149
const { ds, container } = mount(json(status, body));
153150

154151
await waitFor(() => expect(ds.getObjects).toHaveBeenCalled());
155-
await waitFor(async () => expect(await openOptions()).toHaveLength(ALL_OBJECTS.length));
152+
const options = await openOptions();
156153
// `object-ref`'s own list: every registered object, sorted by label.
157-
expect(await openOptions()).toContain('Account (crm_account)');
154+
expect(options).toEqual([...ALL_OBJECTS].map((o) => `${o.label} (${o.name})`).sort((a, b) => a.localeCompare(b)));
158155

159156
fireEvent.click(screen.getByRole('option', { name: 'Account (crm_account)' }));
160157
fireEvent.submit(container.querySelector('form') as HTMLFormElement);

0 commit comments

Comments
 (0)