Skip to content

Commit 6230cd8

Browse files
committed
Enhance BrowserSimulation and ObjectView tests; add timeout for form scenario and register mock components for SchemaRenderer
1 parent e5afe7b commit 6230cd8

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
import { describe, it, expect, vi } from 'vitest';
3-
import { render, screen, waitFor, fireEvent } from '@testing-library/react';
3+
import { render, screen, waitFor, fireEvent, within } from '@testing-library/react';
44
import { MemoryRouter } from 'react-router-dom';
55
import '@object-ui/fields'; // Ensure fields are registered for ObjectForm tests
66

@@ -153,7 +153,7 @@ describe('Console Application Simulation', () => {
153153
// We assume Grid renders the rows.
154154
});
155155

156-
it('Scenario 4: Object Create Form (All Field Types)', async () => {
156+
it('Scenario 4: Object Create Form (All Field Types)', { timeout: 20000 }, async () => {
157157
// Helper function to check if a label exists in the form
158158
const expectLabelToExist = (label: string) => {
159159
const escaped = label.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
@@ -181,10 +181,12 @@ describe('Console Application Simulation', () => {
181181
expect(title).toBeInTheDocument();
182182
});
183183

184+
const dialog = screen.getByRole('dialog');
185+
184186
// 4. Verify Field Inputs
185187
// Wait for form to finish loading and first field to appear
186188
await waitFor(() => {
187-
expect(screen.getByText(/Text \(Name\)/i)).toBeInTheDocument();
189+
expect(within(dialog).getByText(/Text \(Name\)/i)).toBeInTheDocument();
188190
}, { timeout: 10000 });
189191

190192
const fieldLabels = [

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
22
import { render, screen, fireEvent } from '@testing-library/react';
33
import '@testing-library/jest-dom';
44
import { ObjectView } from '../components/ObjectView';
5+
import { ComponentRegistry } from '@object-ui/core';
56

67
// Mock child plugins to isolate ObjectView logic
78
vi.mock('@object-ui/plugin-grid', () => ({
@@ -22,6 +23,8 @@ vi.mock('@object-ui/components', async () => {
2223
cn: (...inputs: any[]) => inputs.filter(Boolean).join(' '),
2324
Button: ({ children, onClick }: any) => <button onClick={onClick}>{children}</button>,
2425
Input: (props: any) => <input {...props} data-testid="mock-input" />,
26+
ToggleGroup: ({ children, value, onValueChange }: any) => <div data-value={value} onChange={onValueChange}>{children}</div>,
27+
ToggleGroupItem: ({ children, value }: any) => <button data-value={value}>{children}</button>,
2528
Tabs: ({ value, onValueChange, children }: any) => (
2629
<div data-testid="tabs" data-value={value} onClick={(e: any) => {
2730
// Simple event delegation for testing
@@ -59,6 +62,14 @@ vi.mock('react-router-dom', () => ({
5962

6063
describe('ObjectView Component', () => {
6164

65+
beforeEach(() => {
66+
// Register mock components for SchemaRenderer to find
67+
ComponentRegistry.register('object-grid', (props: any) => <div data-testid="object-grid">Grid View: {props.schema.objectName}</div>);
68+
ComponentRegistry.register('object-kanban', (props: any) => <div data-testid="object-kanban">Kanban View: {props.schema.groupField}</div>);
69+
ComponentRegistry.register('object-calendar', (props: any) => <div data-testid="object-calendar">Calendar View: {props.schema.startDateField}</div>);
70+
ComponentRegistry.register('list-view', (props: any) => <div data-testid="list-view">List View</div>);
71+
});
72+
6273
const mockDataSource = {
6374
find: vi.fn().mockResolvedValue([]),
6475
delete: vi.fn().mockResolvedValue(true)

0 commit comments

Comments
 (0)