Skip to content

Commit 1285fe4

Browse files
committed
test(grid): place the group refresh pins before the state-machine block (#35689 slice B)
Claude-Session: https://claude.ai/code/session_01QsR2jUc3qp6bHKSWijbjds Co-authored-by: Claude <noreply@anthropic.com>
1 parent e96aa67 commit 1285fe4

1 file changed

Lines changed: 121 additions & 121 deletions

File tree

‎ui/packages/plugin-grid/src/__tests__/ObjectGrid.autosave-35685.test.tsx‎

Lines changed: 121 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -570,127 +570,6 @@ describe("ObjectGrid — a grid without cellSelection re-reads on the host list'
570570
});
571571
});
572572

573-
describe('ObjectGrid — a state-machine field is confirmed before a list cell saves it (objectstack#35685)', () => {
574-
/** Deals whose `stage` a state machine governs, and whose `priority` none does. */
575-
function makeMachineDataSource(rule: Record<string, unknown> = {}) {
576-
const ds = makeDataSource();
577-
ds.store.d1.stage = 'new';
578-
ds.store.d1.priority = 'low';
579-
ds.getObjectSchema = async (name: string) => ({
580-
name,
581-
fields: {
582-
id: { type: 'text' },
583-
name: { type: 'text', label: 'Name' },
584-
stage: {
585-
type: 'select',
586-
label: 'Stage',
587-
options: [
588-
{ value: 'new', label: 'New' },
589-
{ value: 'qualified', label: 'Qualified' },
590-
{ value: 'won', label: 'Won' },
591-
],
592-
},
593-
priority: { type: 'select', label: 'Priority', options: [{ value: 'low', label: 'Low' }, { value: 'high', label: 'High' }] },
594-
updated_at: { type: 'datetime' },
595-
},
596-
validations: [{
597-
name: 'stage_flow',
598-
type: 'state_machine',
599-
field: 'stage',
600-
transitions: { new: ['qualified', 'won'], qualified: ['won'] },
601-
...rule,
602-
}],
603-
});
604-
return ds;
605-
}
606-
607-
function renderMachineGrid(ds: any) {
608-
const schema: any = {
609-
type: 'object-grid',
610-
objectName: OBJECT,
611-
editable: true,
612-
columns: [
613-
{ field: 'name', label: 'Name' },
614-
{ field: 'stage', label: 'Stage' },
615-
{ field: 'priority', label: 'Priority' },
616-
],
617-
pagination: { pageSize: 50 },
618-
};
619-
return render(
620-
<ActionProvider>
621-
<ObjectGrid schema={schema} dataSource={ds} cellSelection />
622-
</ActionProvider>,
623-
);
624-
}
625-
626-
/** Select a cell and paste `text` into it (a commit made without an editor). */
627-
function pasteInto(container: HTMLElement, cell: HTMLElement, text: string) {
628-
fireEvent.click(cell);
629-
const catcher = container.querySelector<HTMLInputElement>('[data-slot="cell-type-catcher"]')!;
630-
fireEvent.paste(catcher, { clipboardData: { getData: () => text } });
631-
}
632-
633-
it('names the field and both values, says automation may run, and Cancel saves nothing', async () => {
634-
const ds = makeMachineDataSource();
635-
const { container } = renderMachineGrid(ds);
636-
await screen.findByText('beta');
637-
pasteInto(container, dataCell(container, 0, 'New'), 'Won');
638-
const dialog = await screen.findByRole('alertdialog');
639-
expect(dialog).toHaveTextContent('Change Stage?');
640-
expect(dialog).toHaveTextContent('Stage changes from New to Won. Saving may trigger related automation.');
641-
expect(ds.update).not.toHaveBeenCalled();
642-
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
643-
await waitFor(() => expect(screen.queryByRole('alertdialog')).toBeNull());
644-
await act(async () => {});
645-
expect(ds.update).not.toHaveBeenCalled();
646-
expect(dataCell(container, 0, 'New')).toBeTruthy();
647-
});
648-
649-
it('Change sends the move as one guarded update', async () => {
650-
const ds = makeMachineDataSource();
651-
const { container } = renderMachineGrid(ds);
652-
await screen.findByText('beta');
653-
pasteInto(container, dataCell(container, 0, 'New'), 'Won');
654-
await screen.findByRole('alertdialog');
655-
fireEvent.click(screen.getByRole('button', { name: 'Change' }));
656-
await waitFor(() => expect(ds.update).toHaveBeenCalledTimes(1));
657-
expect(ds.update).toHaveBeenCalledWith(OBJECT, 'd1', { stage: 'won' }, { ifMatch: '2026-11-20T10:00:00.000Z' });
658-
await waitFor(() => expect(dataCell(container, 0, 'Won')).toBeTruthy());
659-
});
660-
661-
it('a field no state machine governs, and an inactive machine, save without asking', async () => {
662-
const ds = makeMachineDataSource({ active: false });
663-
const { container } = renderMachineGrid(ds);
664-
await screen.findByText('beta');
665-
pasteInto(container, dataCell(container, 0, 'Low'), 'High');
666-
await waitFor(() => expect(ds.update).toHaveBeenCalledTimes(1));
667-
expect(ds.update.mock.calls[0][2]).toEqual({ priority: 'high' });
668-
pasteInto(container, dataCell(container, 0, 'New'), 'Won');
669-
await waitFor(() => expect(ds.update).toHaveBeenCalledTimes(2));
670-
expect(screen.queryByRole('alertdialog')).toBeNull();
671-
});
672-
673-
it('a machine bound to insert alone does not govern an update: the move saves without asking', async () => {
674-
const ds = makeMachineDataSource({ events: ['insert'] });
675-
const { container } = renderMachineGrid(ds);
676-
await screen.findByText('beta');
677-
pasteInto(container, dataCell(container, 0, 'New'), 'Won');
678-
await waitFor(() => expect(ds.update).toHaveBeenCalledTimes(1));
679-
expect(ds.update.mock.calls[0][2]).toEqual({ stage: 'won' });
680-
expect(screen.queryByRole('alertdialog')).toBeNull();
681-
});
682-
683-
it('an advisory (warning-severity) machine still asks: the move is what automation listens for', async () => {
684-
const ds = makeMachineDataSource({ severity: 'warning', events: ['update'] });
685-
const { container } = renderMachineGrid(ds);
686-
await screen.findByText('beta');
687-
pasteInto(container, dataCell(container, 0, 'New'), 'Won');
688-
const dialog = await screen.findByRole('alertdialog');
689-
expect(dialog).toHaveTextContent('Stage changes from New to Won.');
690-
expect(ds.update).not.toHaveBeenCalled();
691-
});
692-
});
693-
694573
describe('ObjectGrid — groups, subtotals and the footer total after a cell save (objectstack#35689)', () => {
695574
/**
696575
* Deals by stage (Prospect / Won) with an amount: Prospect holds Acme 100
@@ -919,3 +798,124 @@ describe('ObjectGrid — groups, subtotals and the footer total after a cell sav
919798
await waitFor(() => expect(footerOf('amount')).toMatch(/200/));
920799
});
921800
});
801+
802+
describe('ObjectGrid — a state-machine field is confirmed before a list cell saves it (objectstack#35685)', () => {
803+
/** Deals whose `stage` a state machine governs, and whose `priority` none does. */
804+
function makeMachineDataSource(rule: Record<string, unknown> = {}) {
805+
const ds = makeDataSource();
806+
ds.store.d1.stage = 'new';
807+
ds.store.d1.priority = 'low';
808+
ds.getObjectSchema = async (name: string) => ({
809+
name,
810+
fields: {
811+
id: { type: 'text' },
812+
name: { type: 'text', label: 'Name' },
813+
stage: {
814+
type: 'select',
815+
label: 'Stage',
816+
options: [
817+
{ value: 'new', label: 'New' },
818+
{ value: 'qualified', label: 'Qualified' },
819+
{ value: 'won', label: 'Won' },
820+
],
821+
},
822+
priority: { type: 'select', label: 'Priority', options: [{ value: 'low', label: 'Low' }, { value: 'high', label: 'High' }] },
823+
updated_at: { type: 'datetime' },
824+
},
825+
validations: [{
826+
name: 'stage_flow',
827+
type: 'state_machine',
828+
field: 'stage',
829+
transitions: { new: ['qualified', 'won'], qualified: ['won'] },
830+
...rule,
831+
}],
832+
});
833+
return ds;
834+
}
835+
836+
function renderMachineGrid(ds: any) {
837+
const schema: any = {
838+
type: 'object-grid',
839+
objectName: OBJECT,
840+
editable: true,
841+
columns: [
842+
{ field: 'name', label: 'Name' },
843+
{ field: 'stage', label: 'Stage' },
844+
{ field: 'priority', label: 'Priority' },
845+
],
846+
pagination: { pageSize: 50 },
847+
};
848+
return render(
849+
<ActionProvider>
850+
<ObjectGrid schema={schema} dataSource={ds} cellSelection />
851+
</ActionProvider>,
852+
);
853+
}
854+
855+
/** Select a cell and paste `text` into it (a commit made without an editor). */
856+
function pasteInto(container: HTMLElement, cell: HTMLElement, text: string) {
857+
fireEvent.click(cell);
858+
const catcher = container.querySelector<HTMLInputElement>('[data-slot="cell-type-catcher"]')!;
859+
fireEvent.paste(catcher, { clipboardData: { getData: () => text } });
860+
}
861+
862+
it('names the field and both values, says automation may run, and Cancel saves nothing', async () => {
863+
const ds = makeMachineDataSource();
864+
const { container } = renderMachineGrid(ds);
865+
await screen.findByText('beta');
866+
pasteInto(container, dataCell(container, 0, 'New'), 'Won');
867+
const dialog = await screen.findByRole('alertdialog');
868+
expect(dialog).toHaveTextContent('Change Stage?');
869+
expect(dialog).toHaveTextContent('Stage changes from New to Won. Saving may trigger related automation.');
870+
expect(ds.update).not.toHaveBeenCalled();
871+
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
872+
await waitFor(() => expect(screen.queryByRole('alertdialog')).toBeNull());
873+
await act(async () => {});
874+
expect(ds.update).not.toHaveBeenCalled();
875+
expect(dataCell(container, 0, 'New')).toBeTruthy();
876+
});
877+
878+
it('Change sends the move as one guarded update', async () => {
879+
const ds = makeMachineDataSource();
880+
const { container } = renderMachineGrid(ds);
881+
await screen.findByText('beta');
882+
pasteInto(container, dataCell(container, 0, 'New'), 'Won');
883+
await screen.findByRole('alertdialog');
884+
fireEvent.click(screen.getByRole('button', { name: 'Change' }));
885+
await waitFor(() => expect(ds.update).toHaveBeenCalledTimes(1));
886+
expect(ds.update).toHaveBeenCalledWith(OBJECT, 'd1', { stage: 'won' }, { ifMatch: '2026-11-20T10:00:00.000Z' });
887+
await waitFor(() => expect(dataCell(container, 0, 'Won')).toBeTruthy());
888+
});
889+
890+
it('a field no state machine governs, and an inactive machine, save without asking', async () => {
891+
const ds = makeMachineDataSource({ active: false });
892+
const { container } = renderMachineGrid(ds);
893+
await screen.findByText('beta');
894+
pasteInto(container, dataCell(container, 0, 'Low'), 'High');
895+
await waitFor(() => expect(ds.update).toHaveBeenCalledTimes(1));
896+
expect(ds.update.mock.calls[0][2]).toEqual({ priority: 'high' });
897+
pasteInto(container, dataCell(container, 0, 'New'), 'Won');
898+
await waitFor(() => expect(ds.update).toHaveBeenCalledTimes(2));
899+
expect(screen.queryByRole('alertdialog')).toBeNull();
900+
});
901+
902+
it('a machine bound to insert alone does not govern an update: the move saves without asking', async () => {
903+
const ds = makeMachineDataSource({ events: ['insert'] });
904+
const { container } = renderMachineGrid(ds);
905+
await screen.findByText('beta');
906+
pasteInto(container, dataCell(container, 0, 'New'), 'Won');
907+
await waitFor(() => expect(ds.update).toHaveBeenCalledTimes(1));
908+
expect(ds.update.mock.calls[0][2]).toEqual({ stage: 'won' });
909+
expect(screen.queryByRole('alertdialog')).toBeNull();
910+
});
911+
912+
it('an advisory (warning-severity) machine still asks: the move is what automation listens for', async () => {
913+
const ds = makeMachineDataSource({ severity: 'warning', events: ['update'] });
914+
const { container } = renderMachineGrid(ds);
915+
await screen.findByText('beta');
916+
pasteInto(container, dataCell(container, 0, 'New'), 'Won');
917+
const dialog = await screen.findByRole('alertdialog');
918+
expect(dialog).toHaveTextContent('Stage changes from New to Won.');
919+
expect(ds.update).not.toHaveBeenCalled();
920+
});
921+
});

0 commit comments

Comments
 (0)