|
| 1 | + |
| 2 | +import { describe, it, expect } from 'vitest'; |
| 3 | +import { render, screen } from '@testing-library/react'; |
| 4 | +import React from 'react'; |
| 5 | +import { PageRenderer } from '../renderers/layout/page'; // Direct import to test logic |
| 6 | +import { ComponentRegistry } from '@object-ui/core'; |
| 7 | + |
| 8 | +// Mock SchemaRenderer to verify it's called |
| 9 | +import { SchemaRenderer } from '@object-ui/react'; |
| 10 | +import { vi } from 'vitest'; |
| 11 | + |
| 12 | +// Mock the SchemaRenderer to avoid full tree recursion deps |
| 13 | +vi.mock('@object-ui/react', () => ({ |
| 14 | + SchemaRenderer: ({ schema }: any) => <div data-testid="child-node">{schema.type}:{schema.value || schema.name}</div> |
| 15 | +})); |
| 16 | + |
| 17 | +describe('PageRenderer Regions', () => { |
| 18 | + it('should render components from regions', () => { |
| 19 | + const schema: any = { |
| 20 | + type: 'page', |
| 21 | + title: 'Test Page', |
| 22 | + regions: [ |
| 23 | + { |
| 24 | + name: 'main', |
| 25 | + components: [ |
| 26 | + { type: 'text', value: 'Region Content 1' }, |
| 27 | + { type: 'button', label: 'Region Button' } |
| 28 | + ] |
| 29 | + } |
| 30 | + ] |
| 31 | + }; |
| 32 | + |
| 33 | + render(<PageRenderer schema={schema} />); |
| 34 | + |
| 35 | + // Check if title is rendered |
| 36 | + expect(screen.getByText('Test Page')).toBeDefined(); |
| 37 | + |
| 38 | + // Check real content (since mock didn't take effect, we verify real render) |
| 39 | + // The text component renders the value directly |
| 40 | + expect(screen.getByText('Region Content 1')).toBeDefined(); |
| 41 | + |
| 42 | + // The button component renders the label |
| 43 | + expect(screen.getByText('Region Button')).toBeDefined(); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should render legacy body', () => { |
| 47 | + const schema: any = { |
| 48 | + type: 'page', |
| 49 | + title: 'Legacy Page', |
| 50 | + body: [ |
| 51 | + { type: 'text', value: 'Body Content' } |
| 52 | + ] |
| 53 | + }; |
| 54 | + |
| 55 | + render(<PageRenderer schema={schema} />); |
| 56 | + |
| 57 | + expect(screen.getByText('Body Content')).toBeDefined(); |
| 58 | + }); |
| 59 | +}); |
0 commit comments