Skip to content

Commit aa7b14b

Browse files
Copilothotlong
andcommitted
test: add comprehensive live preview tests for selection, addRecord, and navigation mode
- Enhance ListView mock to render selection.type, addRecord.enabled, and addRecordViaForm - Add test: selection mode change propagates to ListView schema in real-time - Add test: addRecord toggle propagates both addRecord and addRecordViaForm to ListView - Add test: navigation mode change from config panel propagates to ListView schema live - Strengthen navigation priority test to verify ListView receives view-level navigation Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 4a9f5e8 commit aa7b14b

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

apps/console/src/__tests__/ObjectView.test.tsx

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ vi.mock('@object-ui/plugin-list', () => ({
3030
{props.schema?.showRecordCount && <div data-testid="schema-showRecordCount">showRecordCount</div>}
3131
{props.schema?.allowPrinting && <div data-testid="schema-allowPrinting">allowPrinting</div>}
3232
{props.schema?.navigation?.mode && <div data-testid="schema-navigation-mode">{props.schema.navigation.mode}</div>}
33+
{props.schema?.selection?.type && <div data-testid="schema-selection-type">{props.schema.selection.type}</div>}
34+
{props.schema?.addRecord?.enabled && <div data-testid="schema-addRecord-enabled">addRecord</div>}
35+
{props.schema?.addRecordViaForm && <div data-testid="schema-addRecordViaForm">addRecordViaForm</div>}
3336
</div>
3437
);
3538
},
@@ -685,7 +688,76 @@ describe('ObjectView Component', () => {
685688
// Render the component — activeView.navigation should override objectDef.navigation
686689
render(<ObjectView dataSource={mockDataSource} objects={objectsWithNav} onEdit={vi.fn()} />);
687690

688-
// The component should render without errors
691+
// The component should render without errors and ListView should receive
692+
// the view-level navigation config (modal) instead of object-level (drawer)
689693
expect(screen.getByTestId('object-grid')).toBeInTheDocument();
694+
expect(screen.getByTestId('schema-navigation-mode')).toHaveTextContent('modal');
695+
});
696+
697+
it('propagates selection mode change to ListView schema in real-time', async () => {
698+
mockAuthUser = { id: 'u1', name: 'Admin', role: 'admin' };
699+
mockUseParams.mockReturnValue({ objectName: 'opportunity' });
700+
701+
render(<ObjectView dataSource={mockDataSource} objects={mockObjects} onEdit={vi.fn()} />);
702+
703+
// Open config panel
704+
fireEvent.click(screen.getByTitle('console.objectView.designTools'));
705+
fireEvent.click(screen.getByText('console.objectView.editView'));
706+
707+
// Change selection mode to 'single'
708+
const selectionSelect = screen.getByTestId('select-selection-type');
709+
fireEvent.change(selectionSelect, { target: { value: 'single' } });
710+
711+
// Verify the selection type propagated to ListView immediately (live preview)
712+
await vi.waitFor(() => {
713+
expect(screen.getByTestId('schema-selection-type')).toHaveTextContent('single');
714+
});
715+
});
716+
717+
it('propagates addRecord toggle to ListView schema in real-time', async () => {
718+
mockAuthUser = { id: 'u1', name: 'Admin', role: 'admin' };
719+
mockUseParams.mockReturnValue({ objectName: 'opportunity' });
720+
721+
render(<ObjectView dataSource={mockDataSource} objects={mockObjects} onEdit={vi.fn()} />);
722+
723+
// addRecord should not be enabled initially
724+
expect(screen.queryByTestId('schema-addRecord-enabled')).not.toBeInTheDocument();
725+
726+
// Open config panel
727+
fireEvent.click(screen.getByTitle('console.objectView.designTools'));
728+
fireEvent.click(screen.getByText('console.objectView.editView'));
729+
730+
// Toggle addRecord on
731+
const addRecordSwitch = screen.getByTestId('toggle-addRecord-enabled');
732+
fireEvent.click(addRecordSwitch);
733+
734+
// Verify addRecord and addRecordViaForm propagated to ListView immediately
735+
await vi.waitFor(() => {
736+
expect(screen.getByTestId('schema-addRecord-enabled')).toBeInTheDocument();
737+
expect(screen.getByTestId('schema-addRecordViaForm')).toBeInTheDocument();
738+
});
739+
});
740+
741+
it('propagates navigation mode change from config panel to ListView schema in real-time', async () => {
742+
mockAuthUser = { id: 'u1', name: 'Admin', role: 'admin' };
743+
mockUseParams.mockReturnValue({ objectName: 'opportunity' });
744+
745+
render(<ObjectView dataSource={mockDataSource} objects={mockObjects} onEdit={vi.fn()} />);
746+
747+
// navigation mode should not be set initially (no explicit mode on default view)
748+
expect(screen.queryByTestId('schema-navigation-mode')).not.toBeInTheDocument();
749+
750+
// Open config panel
751+
fireEvent.click(screen.getByTitle('console.objectView.designTools'));
752+
fireEvent.click(screen.getByText('console.objectView.editView'));
753+
754+
// Change navigation mode to 'modal'
755+
const navSelect = screen.getByTestId('select-navigation-mode');
756+
fireEvent.change(navSelect, { target: { value: 'modal' } });
757+
758+
// Verify navigation mode propagated to ListView schema immediately (live preview)
759+
await vi.waitFor(() => {
760+
expect(screen.getByTestId('schema-navigation-mode')).toHaveTextContent('modal');
761+
});
690762
});
691763
});

0 commit comments

Comments
 (0)